Class: Trestle::ModelName

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

#klassObject (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(options={})
  if i18n_supported? && i18n_pluralizations_available?
    human(default_plural, { count: I18N_PLURAL_COUNT }.merge(options))
  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(options={})
  human(default_singular, options)
end

#to_sObject



21
22
23
# File 'lib/trestle/model_name.rb', line 21

def to_s
  singular
end