aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport
diff options
context:
space:
mode:
authorJeremy Kemper <jeremy@bitsweat.net>2009-06-08 17:58:14 -0700
committerJeremy Kemper <jeremy@bitsweat.net>2009-06-08 19:37:50 -0700
commit99cf77be270e71408a14f0c00472517adb5981b2 (patch)
tree9a99a178948a19eaba9a85b444d36a3f5724711a /activesupport
parentd9f16fafecad13cfe4ca1d4ff825de768b39b9ee (diff)
downloadrails-99cf77be270e71408a14f0c00472517adb5981b2.tar.gz
rails-99cf77be270e71408a14f0c00472517adb5981b2.tar.bz2
rails-99cf77be270e71408a14f0c00472517adb5981b2.zip
Add #element and #collection to ModelName
Diffstat (limited to 'activesupport')
-rw-r--r--activesupport/lib/active_support/core_ext/module/model_naming.rb8
-rw-r--r--activesupport/test/core_ext/module/model_naming_test.rb8
2 files changed, 13 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
diff --git a/activesupport/test/core_ext/module/model_naming_test.rb b/activesupport/test/core_ext/module/model_naming_test.rb
index da3b6c4932..37119f378a 100644
--- a/activesupport/test/core_ext/module/model_naming_test.rb
+++ b/activesupport/test/core_ext/module/model_naming_test.rb
@@ -14,6 +14,14 @@ class ModelNamingTest < Test::Unit::TestCase
assert_equal 'post_track_backs', @model_name.plural
end
+ def test_element
+ assert_equal 'track_back', @model_name.element
+ end
+
+ def test_collection
+ assert_equal 'post/track_backs', @model_name.collection
+ end
+
def test_partial_path
assert_equal 'post/track_backs/track_back', @model_name.partial_path
end