Class: Trestle::ModelName
- Inherits:
-
Object
- Object
- Trestle::ModelName
- Defined in:
- lib/trestle/model_name.rb
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.
9 10 11 12 |
# File 'lib/trestle/model_name.rb', line 9 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.
5 6 7 |
# File 'lib/trestle/model_name.rb', line 5 def klass @klass end |
Instance Method Details
#==(other) ⇒ Object
14 15 16 |
# File 'lib/trestle/model_name.rb', line 14 def ==(other) other.is_a?(self.class) && klass == other.klass end |
#plural(options = {}) ⇒ Object Also known as: pluralize
27 28 29 30 31 32 33 |
# File 'lib/trestle/model_name.rb', line 27 def plural(={}) if i18n_supported? && i18n_pluralizations_available? human(default_plural, { count: :many }.merge()) else default_plural end end |
#singular(options = {}) ⇒ Object Also known as: singularize
22 23 24 |
# File 'lib/trestle/model_name.rb', line 22 def singular(={}) human(default_singular, ) end |
#to_s ⇒ Object
18 19 20 |
# File 'lib/trestle/model_name.rb', line 18 def to_s singular end |