Class: Resourcerer::Inflector
- Inherits:
-
Object
- Object
- Resourcerer::Inflector
- Defined in:
- lib/resourcerer/inflector.rb
Instance Attribute Summary collapse
-
#finder_attribute ⇒ Object
readonly
Returns the value of attribute finder_attribute.
-
#model ⇒ Object
readonly
Returns the value of attribute model.
-
#original ⇒ Object
(also: #name)
readonly
Returns the value of attribute original.
Class Method Summary collapse
Instance Method Summary collapse
- #finder_param ⇒ Object
-
#initialize(name, model, finder_attribute = :id) ⇒ Inflector
constructor
A new instance of Inflector.
- #model_name ⇒ Object
- #param_key ⇒ Object
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_attribute ⇒ Object (readonly)
Returns the value of attribute finder_attribute.
7 8 9 |
# File 'lib/resourcerer/inflector.rb', line 7 def finder_attribute @finder_attribute end |
#model ⇒ Object (readonly)
Returns the value of attribute model.
7 8 9 |
# File 'lib/resourcerer/inflector.rb', line 7 def model @model end |
#original ⇒ Object (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_param ⇒ Object
25 26 27 |
# File 'lib/resourcerer/inflector.rb', line 25 def finder_param "#{model_name.singular}_#{finder_attribute}" end |
#model_name ⇒ Object
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_key ⇒ Object
21 22 23 |
# File 'lib/resourcerer/inflector.rb', line 21 def param_key model_name.param_key end |