Class: Trestle::ModelName
- Inherits:
-
Object
- Object
- Trestle::ModelName
- Defined in:
- lib/trestle/model_name.rb
Constant Summary collapse
- I18N_PLURAL_COUNT =
Matches :other i18n pluralization option for most languages
20
Instance Attribute Summary collapse
-
#klass ⇒ Object
readonly
Returns the value of attribute klass.
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#initialize(klass) ⇒ ModelName
constructor
A new instance of ModelName.
- #plural(options = {}) ⇒ Object (also: #pluralize)
- #singular(options = {}) ⇒ Object (also: #singularize)
- #to_s ⇒ Object
Constructor Details
#initialize(klass) ⇒ ModelName
Returns a new instance of ModelName.
12 13 14 15 |
# File 'lib/trestle/model_name.rb', line 12 def initialize(klass) @klass = klass @name = klass.respond_to?(:model_name) ? klass.model_name : ActiveModel::Name.new(klass) end |
Instance Attribute Details
#klass ⇒ Object (readonly)
Returns the value of attribute klass.
8 9 10 |
# File 'lib/trestle/model_name.rb', line 8 def klass @klass end |
Instance Method Details
#==(other) ⇒ Object
17 18 19 |
# File 'lib/trestle/model_name.rb', line 17 def ==(other) other.is_a?(self.class) && klass == other.klass end |
#plural(options = {}) ⇒ Object Also known as: pluralize
30 31 32 33 34 35 36 |
# File 'lib/trestle/model_name.rb', line 30 def plural(={}) if i18n_supported? && i18n_pluralizations_available? human(default_plural, { count: I18N_PLURAL_COUNT }.merge()) else default_plural end end |
#singular(options = {}) ⇒ Object Also known as: singularize
25 26 27 |
# File 'lib/trestle/model_name.rb', line 25 def singular(={}) human(default_singular, ) end |
#to_s ⇒ Object
21 22 23 |
# File 'lib/trestle/model_name.rb', line 21 def to_s singular end |