diff options
author | Piotr Sarnacki <drogus@gmail.com> | 2010-07-21 10:37:09 +0200 |
---|---|---|
committer | José Valim <jose.valim@gmail.com> | 2010-07-21 11:29:58 +0200 |
commit | 6807b080996ee4bd6b80abb4f5e9964632c421c8 (patch) | |
tree | 9ab10340178251987b5379b74948ba1ac6389a1b /activemodel/lib | |
parent | fa8b290496789eb037d4fad89acea1cb0a534f35 (diff) | |
download | rails-6807b080996ee4bd6b80abb4f5e9964632c421c8.tar.gz rails-6807b080996ee4bd6b80abb4f5e9964632c421c8.tar.bz2 rails-6807b080996ee4bd6b80abb4f5e9964632c421c8.zip |
Moved a few methods from RecordIdentifier to ActiveModel::Naming
Signed-off-by: José Valim <jose.valim@gmail.com>
Diffstat (limited to 'activemodel/lib')
-rw-r--r-- | activemodel/lib/active_model/naming.rb | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/activemodel/lib/active_model/naming.rb b/activemodel/lib/active_model/naming.rb index ca1e9f0ee8..dc83932dde 100644 --- a/activemodel/lib/active_model/naming.rb +++ b/activemodel/lib/active_model/naming.rb @@ -57,6 +57,35 @@ module ActiveModel def model_name @_model_name ||= ActiveModel::Name.new(self) end + + # Returns the plural class name of a record or class. Examples: + # + # ActiveModel::Naming.plural(post) # => "posts" + # ActiveModel::Naming.plural(Highrise::Person) # => "highrise_people" + def self.plural(record_or_class) + model_name_from_record_or_class(record_or_class).plural + end + + # Returns the singular class name of a record or class. Examples: + # + # ActiveModel::Naming.singular(post) # => "post" + # ActiveModel::Naming.singular(Highrise::Person) # => "highrise_person" + def self.singular(record_or_class) + model_name_from_record_or_class(record_or_class).singular + end + + # Identifies whether the class name of a record or class is uncountable. Examples: + # + # ActiveModel::Naming.uncountable?(Sheep) # => true + # ActiveModel::Naming.uncountable?(Post) => false + def self.uncountable?(record_or_class) + plural(record_or_class) == singular(record_or_class) + end + + private + def self.model_name_from_record_or_class(record_or_class) + (record_or_class.is_a?(Class) ? record_or_class : record_or_class.class).model_name + end end end |