aboutsummaryrefslogblamecommitdiffstats
path: root/activesupport/lib/active_support/core_ext/module/model_naming.rb
blob: 5518f5417bd2f25c1ff4534be9e7482dd831f469 (plain) (tree)
1
2
3
4
5
6
7
8
9

                          
                                                             




                                                
                                  
                                                                     












                                             
module ActiveSupport
  class ModelName < String
    attr_reader :singular, :plural, :cache_key, :partial_path

    def initialize(name)
      super
      @singular = underscore.tr('/', '_').freeze
      @plural = @singular.pluralize.freeze
      @cache_key = tableize.freeze
      @partial_path = "#{@cache_key}/#{demodulize.underscore}".freeze
    end
  end

  module CoreExt
    module Module
      module ModelNaming
        def model_name
          @model_name ||= ModelName.new(name)
        end
      end
    end
  end
end