Class: Resourcerer::Inflector

Inherits:
Object
  • Object
show all
Defined in:
lib/resourcerer/inflector.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, model, finder_attribute = :id) ⇒ Inflector

Returns a new instance of Inflector.



9
10
11
# File 'lib/resourcerer/inflector.rb', line 9

def initialize(name, model, finder_attribute=:id)
  @original, @model, @finder_attribute = name.to_s, model, finder_attribute
end

Instance Attribute Details

#finder_attributeObject (readonly)

Returns the value of attribute finder_attribute.



7
8
9
# File 'lib/resourcerer/inflector.rb', line 7

def finder_attribute
  @finder_attribute
end

#modelObject (readonly)

Returns the value of attribute model.



7
8
9
# File 'lib/resourcerer/inflector.rb', line 7

def model
  @model
end

#originalObject (readonly) Also known as: name

Returns the value of attribute original.



7
8
9
# File 'lib/resourcerer/inflector.rb', line 7

def original
  @original
end

Class Method Details

.class_for(name) ⇒ Object



29
30
31
# File 'lib/resourcerer/inflector.rb', line 29

def self.class_for(name)
  name.to_s.split('::').map(&:classify).join('::').constantize
end

Instance Method Details

#finder_paramObject



25
26
27
# File 'lib/resourcerer/inflector.rb', line 25

def finder_param
  "#{model_name.singular}_#{finder_attribute}"
end

#model_nameObject



15
16
17
18
19
# File 'lib/resourcerer/inflector.rb', line 15

def model_name
  @model_name ||= model.model_name
rescue
  @model_name = ActiveModel::Name.new(model)
end

#param_keyObject



21
22
23
# File 'lib/resourcerer/inflector.rb', line 21

def param_key
  model_name.param_key
end