Class: Trestle::ModelName

Inherits:
Object
  • Object
show all
Defined in:
lib/trestle/model_name.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

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

#to_sObject



18
19
20
# File 'lib/trestle/model_name.rb', line 18

def to_s
  singular
end