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