Class: Her::Model::Associations::Association
- Inherits:
-
Object
- Object
- Her::Model::Associations::Association
- Defined in:
- lib/her_extension/model/associations/association.rb
Direct Known Subclasses
Instance Attribute Summary collapse
Instance Method Summary collapse
-
#blank_relation ⇒ Object
Reset params when directly called on association class def where(*args) blank_relation.params = {} blank_relation.where(*args) end.
-
#build_request_path(params = {}) ⇒ Object
Required by Relation methods.
-
#method_for(meth) ⇒ Object
Required by Relation methods.
- #method_missing(name, *args, &block) ⇒ Object
-
#new_collection(parsed_data) ⇒ Object
Required by Relation methods.
-
#reload ⇒ Object
Reload the association from remote service.
-
#request(*args, &block) ⇒ Object
Required by Relation methods.
-
#to_params(attributes) ⇒ Object
Properly format the attributes to post/put.
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object
54 55 56 |
# File 'lib/her_extension/model/associations/association.rb', line 54 def method_missing(name, *args, &block) blank_relation.send(name, *args, &block) end |
Instance Attribute Details
#params ⇒ Object
7 8 9 |
# File 'lib/her_extension/model/associations/association.rb', line 7 def params @params end |
Instance Method Details
#blank_relation ⇒ Object
Reset params when directly called on association class def where(*args)
blank_relation.params = {}
blank_relation.where(*args)
end
48 49 50 51 52 |
# File 'lib/her_extension/model/associations/association.rb', line 48 def blank_relation @blank_relation ||= Relation.new(self) @blank_relation.params = {} @blank_relation end |
#build_request_path(params = {}) ⇒ Object
Required by Relation methods
11 12 13 |
# File 'lib/her_extension/model/associations/association.rb', line 11 def build_request_path(params = {}) build_association_path lambda { "#{@parent.request_path(@params.merge(params))}#{@opts[:path]}" } end |
#method_for(meth) ⇒ Object
Required by Relation methods
16 17 18 |
# File 'lib/her_extension/model/associations/association.rb', line 16 def method_for(meth) @parent.class.method_for(meth) end |
#new_collection(parsed_data) ⇒ Object
Required by Relation methods
26 27 28 |
# File 'lib/her_extension/model/associations/association.rb', line 26 def new_collection(parsed_data) Her::Model::Attributes.initialize_collection(@klass, parsed_data) end |
#reload ⇒ Object
Reload the association from remote service
36 37 38 39 40 |
# File 'lib/her_extension/model/associations/association.rb', line 36 def reload @klass.get(build_request_path, @params).tap do |result| @parent.attributes[@name] = result end end |
#request(*args, &block) ⇒ Object
Required by Relation methods
21 22 23 |
# File 'lib/her_extension/model/associations/association.rb', line 21 def request(*args,&block) @parent.class.request(*args,&block) end |
#to_params(attributes) ⇒ Object
Properly format the attributes to post/put
31 32 33 |
# File 'lib/her_extension/model/associations/association.rb', line 31 def to_params(attributes) @parent.class.to_params(attributes,attributes) end |