Class: ApiTwister::ApiAssociation
- Inherits:
-
Object
- Object
- ApiTwister::ApiAssociation
- Defined in:
- lib/api-twister/api_association.rb
Instance Attribute Summary collapse
-
#association ⇒ Object
readonly
Returns the value of attribute association.
Instance Method Summary collapse
- #api_hash(name, options = {}) ⇒ Object
-
#initialize(model, association) ⇒ ApiAssociation
constructor
A new instance of ApiAssociation.
Constructor Details
#initialize(model, association) ⇒ ApiAssociation
Returns a new instance of ApiAssociation.
5 6 7 8 |
# File 'lib/api-twister/api_association.rb', line 5 def initialize(model, association) @model = model @association = association end |
Instance Attribute Details
#association ⇒ Object (readonly)
Returns the value of attribute association.
3 4 5 |
# File 'lib/api-twister/api_association.rb', line 3 def association @association end |
Instance Method Details
#api_hash(name, options = {}) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/api-twister/api_association.rb', line 10 def api_hash(name, ={}) hash = {} assoc = @model.reflect_on_association(@association) raise "There is no association named #{@association}" if assoc.nil? klass = eval(assoc.class_name) if klass.respond_to? :api_hash hash[@association] = klass.api_hash(name, ) else hash[@association] = {} end end |