2008-09-07 07:54:05 +02:00
|
|
|
module ActiveSupport
|
|
|
|
class ModelName < String
|
2009-08-04 17:16:03 +02:00
|
|
|
attr_reader :singular, :plural, :element, :collection, :partial_path
|
|
|
|
alias_method :cache_key, :collection
|
2008-09-07 07:54:05 +02:00
|
|
|
|
|
|
|
def initialize(name)
|
|
|
|
super
|
2009-08-04 17:16:03 +02:00
|
|
|
@singular = ActiveSupport::Inflector.underscore(self).tr('/', '_').freeze
|
|
|
|
@plural = ActiveSupport::Inflector.pluralize(@singular).freeze
|
|
|
|
@element = ActiveSupport::Inflector.underscore(ActiveSupport::Inflector.demodulize(self)).freeze
|
|
|
|
@collection = ActiveSupport::Inflector.tableize(self).freeze
|
|
|
|
@partial_path = "#{@collection}/#{@element}".freeze
|
2008-09-07 07:54:05 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2008-10-27 07:47:01 +01:00
|
|
|
module CoreExtensions
|
2008-09-07 07:54:05 +02:00
|
|
|
module Module
|
2008-10-27 07:47:01 +01:00
|
|
|
# Returns an ActiveSupport::ModelName object for module. It can be
|
|
|
|
# used to retrieve all kinds of naming-related information.
|
|
|
|
def model_name
|
2009-08-04 17:16:03 +02:00
|
|
|
@model_name ||= ::ActiveSupport::ModelName.new(name)
|
2008-09-07 07:54:05 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|