aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/core_ext/module/model_naming.rb
blob: 26e76ab556755a92ee82a47352e9b5604045bfb6 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
module ActiveSupport
  class ModelName < String
    attr_reader :singular, :plural, :partial_path

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

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