Module: ElvantoAPI::Resource
- Defined in:
- lib/elvanto/resources/resource.rb
Defined Under Namespace
Modules: ClassMethods
Instance Attribute Summary collapse
-
#attributes ⇒ Object
Returns the value of attribute attributes.
Class Method Summary collapse
Instance Method Summary collapse
- #initialize(attributes = {}) ⇒ Object
- #method_missing(method, *args, &block) ⇒ Object
-
#query_member(method, options = {}) ⇒ Object
The response from the API method.
-
#reload ⇒ Object
New copy of the object with updated attributes.
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
29 30 31 32 33 34 35 |
# File 'lib/elvanto/resources/resource.rb', line 29 def method_missing(method, *args, &block) if @attributes.has_key?(method.to_s) return @attributes[method.to_s] end super method, *args, &block end |
Instance Attribute Details
#attributes ⇒ Object
Returns the value of attribute attributes.
10 11 12 |
# File 'lib/elvanto/resources/resource.rb', line 10 def attributes @attributes end |
Class Method Details
.included(base) ⇒ Object
37 38 39 |
# File 'lib/elvanto/resources/resource.rb', line 37 def self.included(base) base.extend ClassMethods end |
Instance Method Details
#initialize(attributes = {}) ⇒ Object
13 14 15 |
# File 'lib/elvanto/resources/resource.rb', line 13 def initialize(attributes = {}) @attributes = Utils.indifferent_read_access attributes end |
#query_member(method, options = {}) ⇒ Object
Returns The response from the API method.
25 26 27 |
# File 'lib/elvanto/resources/resource.rb', line 25 def query_member(method, ={}) self.class.query_member(method, .merge({id: id})) end |
#reload ⇒ Object
Returns New copy of the object with updated attributes.
18 19 20 |
# File 'lib/elvanto/resources/resource.rb', line 18 def reload self.class.find({id: id}) end |