diff options
author | Jeremy Kemper <jeremy@bitsweat.net> | 2009-06-08 17:58:14 -0700 |
---|---|---|
committer | Jeremy Kemper <jeremy@bitsweat.net> | 2009-06-08 19:37:50 -0700 |
commit | 99cf77be270e71408a14f0c00472517adb5981b2 (patch) | |
tree | 9a99a178948a19eaba9a85b444d36a3f5724711a /activesupport/lib | |
parent | d9f16fafecad13cfe4ca1d4ff825de768b39b9ee (diff) | |
download | rails-99cf77be270e71408a14f0c00472517adb5981b2.tar.gz rails-99cf77be270e71408a14f0c00472517adb5981b2.tar.bz2 rails-99cf77be270e71408a14f0c00472517adb5981b2.zip |
Add #element and #collection to ModelName
Diffstat (limited to 'activesupport/lib')
-rw-r--r-- | activesupport/lib/active_support/core_ext/module/model_naming.rb | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/activesupport/lib/active_support/core_ext/module/model_naming.rb b/activesupport/lib/active_support/core_ext/module/model_naming.rb index 36fde87b23..13420bab07 100644 --- a/activesupport/lib/active_support/core_ext/module/model_naming.rb +++ b/activesupport/lib/active_support/core_ext/module/model_naming.rb @@ -2,14 +2,16 @@ require 'active_support/inflector' module ActiveSupport class ModelName < String - attr_reader :singular, :plural, :cache_key, :partial_path + attr_reader :singular, :plural, :element, :collection, :partial_path + alias_method :cache_key, :collection def initialize(name) super @singular = ActiveSupport::Inflector.underscore(self).tr('/', '_').freeze @plural = ActiveSupport::Inflector.pluralize(@singular).freeze - @cache_key = tableize.freeze - @partial_path = "#{@cache_key}/#{ActiveSupport::Inflector.underscore(ActiveSupport::Inflector.demodulize(self))}".freeze + @element = ActiveSupport::Inflector.underscore(ActiveSupport::Inflector.demodulize(self)).freeze + @collection = ActiveSupport::Inflector.tableize(self).freeze + @partial_path = "#{@collection}/#{@element}".freeze end end end |