Module: MongoMapper::Plugins::Rails::ClassMethods
- Defined in:
- lib/mongo_mapper/i18n.rb
Instance Method Summary collapse
-
#human_attribute_name(attribute_key_name, options = {}) ⇒ Object
Transforms attribute key names into a more humane format, such as “First name” instead of “first_name”.
-
#human_name(options = {}) ⇒ Object
Transform the modelname into a more humane format, using I18n.
-
#self_and_descendants ⇒ Object
nodoc:.
Instance Method Details
#human_attribute_name(attribute_key_name, options = {}) ⇒ Object
Transforms attribute key names into a more humane format, such as “First name” instead of “first_name”. Example:
Person.human_attribute_name("first_name") # => "First name"
This used to be depricated in favor of humanize, but is now preferred, because it automatically uses the I18n module now. Specify options
with additional translating options.
26 27 28 29 30 31 32 33 34 35 |
# File 'lib/mongo_mapper/i18n.rb', line 26 def human_attribute_name(attribute_key_name, = {}) defaults = self_and_descendants.map do |klass| :"#{klass.name.underscore}.#{attribute_key_name}" end defaults << [:default] if [:default] defaults.flatten! defaults << attribute_key_name.to_s.humanize [:count] ||= 1 I18n.translate(defaults.shift, .merge(:default => defaults, :scope => [:mongo_mapper, :attributes])) end |
#human_name(options = {}) ⇒ Object
Transform the modelname into a more humane format, using I18n. Defaults to the basic humanize method. Default scope of the translation is mongo_mapper.models Specify options
with additional translating options.
41 42 43 44 45 46 47 |
# File 'lib/mongo_mapper/i18n.rb', line 41 def human_name( = {}) defaults = self_and_descendants.map do |klass| :"#{klass.name.underscore}" end defaults << self.name.humanize I18n.translate(defaults.shift, {:scope => [:mongo_mapper, :models], :count => 1, :default => defaults}.merge()) end |
#self_and_descendants ⇒ Object
nodoc:
10 11 12 13 14 15 16 17 18 19 |
# File 'lib/mongo_mapper/i18n.rb', line 10 def self_and_descendants#nodoc: klass = self classes = [klass] while klass != klass.base_class classes << klass = klass.superclass end classes rescue [self] end |