Class: Wakari::Support::Naming::Name

Inherits:
ActiveModel::Name
  • Object
show all
Defined in:
lib/wakari/models/support/naming.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(parent_class, klass, namespace = nil, name = nil) ⇒ Name

Returns a new instance of Name.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/wakari/models/support/naming.rb', line 9

def initialize(parent_class, klass, namespace = nil, name = nil)
  super(klass, namespace, name)
  @parent_class = parent_class
  @clear_name   = (Rails.version <= "3.2.8" ? (name||klass.name) : @name).sub(/^#{parent_class.name}\W*/,'')
  @singular     = _singularize(@clear_name)
  @plural       = ActiveSupport::Inflector.pluralize(@singular)
  @element       = ActiveSupport::Inflector.underscore(ActiveSupport::Inflector.demodulize(@clear_name))
  @collection   = @parent_class.model_name.collection + "/" + ActiveSupport::Inflector.tableize(@clear_name)
  @param_key    = (namespace ? _singularize(@unnamespaced) : @singular)
  @i18n_key     = (@parent_class.model_name.i18n_key.to_s + "/" + @clear_name.underscore).to_sym
  @route_key          = (namespace ? ActiveSupport::Inflector.pluralize(@param_key) : @plural.dup)
  @singular_route_key = ActiveSupport::Inflector.singularize(@route_key)
  @route_key << "_index" if @plural == @singular
end

Instance Attribute Details

#parent_classObject (readonly)

Returns the value of attribute parent_class.



7
8
9
# File 'lib/wakari/models/support/naming.rb', line 7

def parent_class
  @parent_class
end

Instance Method Details

#human(options = {}) ⇒ Object



24
25
26
# File 'lib/wakari/models/support/naming.rb', line 24

def human(options = {})
  try_human(options)
end