2008-09-07 07:54:05 +02:00
|
|
|
module ActiveSupport
|
|
|
|
class ModelName < String
|
2008-10-27 07:47:01 +01:00
|
|
|
attr_reader :singular, :plural, :cache_key, :partial_path
|
2008-09-07 07:54:05 +02:00
|
|
|
|
|
|
|
def initialize(name)
|
|
|
|
super
|
|
|
|
@singular = underscore.tr('/', '_').freeze
|
|
|
|
@plural = @singular.pluralize.freeze
|
2008-10-27 07:47:01 +01:00
|
|
|
@cache_key = tableize.freeze
|
|
|
|
@partial_path = "#{@cache_key}/#{demodulize.underscore}".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
|
|
|
|
@model_name ||= ModelName.new(name)
|
2008-09-07 07:54:05 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|