~michaelforrest/use-case-mapper/trunk

« back to all changes in this revision

Viewing changes to vendor/rails/activesupport/lib/active_support/core_ext/module/model_naming.rb

  • Committer: Michael Forrest
  • Date: 2010-10-15 16:28:50 UTC
  • Revision ID: michael.forrest@canonical.com-20101015162850-tj2vchanv0kr0dun
refrozeĀ gems

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
module ActiveSupport
 
2
  class ModelName < String
 
3
    attr_reader :singular, :plural, :element, :collection, :partial_path
 
4
    alias_method :cache_key, :collection
 
5
 
 
6
    def initialize(name)
 
7
      super
 
8
      @singular = ActiveSupport::Inflector.underscore(self).tr('/', '_').freeze
 
9
      @plural = ActiveSupport::Inflector.pluralize(@singular).freeze
 
10
      @element = ActiveSupport::Inflector.underscore(ActiveSupport::Inflector.demodulize(self)).freeze
 
11
      @collection = ActiveSupport::Inflector.tableize(self).freeze
 
12
      @partial_path = "#{@collection}/#{@element}".freeze
 
13
    end
 
14
  end
 
15
 
 
16
  module CoreExtensions
 
17
    module Module
 
18
      # Returns an ActiveSupport::ModelName object for module. It can be
 
19
      # used to retrieve all kinds of naming-related information.
 
20
      def model_name
 
21
        @model_name ||= ::ActiveSupport::ModelName.new(name)
 
22
      end
 
23
    end
 
24
  end
 
25
end