Class: PYR::ResponseObject
- Inherits:
-
LazyRecord::Base
- Object
- LazyRecord::Base
- PYR::ResponseObject
- Defined in:
- lib/pyr/response_object.rb
Overview
The ResponseObject is the parent class of all objects instantiated from the response body.
Direct Known Subclasses
Instance Method Summary collapse
-
#call ⇒ PYR::Response
Send a request to the API for the object.
-
#controller ⇒ Object
The controller name, based on the object’s class name.
-
#initialize(opts = {}, &block) ⇒ ResponseObject
constructor
Pass in an options hash to instantiate the object and set the data attributes.
Constructor Details
#initialize(opts = {}, &block) ⇒ ResponseObject
Pass in an options hash to instantiate the object and set the data attributes. First iterates through the hash converting nested hashes and arrays of hashes into other PYR::ResponseObjects if possible. Hash keys that are not defined as attributes with ‘attr_accessor` or `lr_has_many` will not be accessible in the parent object.
19 20 21 22 23 24 |
# File 'lib/pyr/response_object.rb', line 19 def initialize(opts = {}, &block) new_opts = opts.each_with_object({}) do |(key, val), memo| memo[key] = convert_json_object_to_pyr_resource(key, val) || val end super(new_opts, &block) end |
Instance Method Details
#call ⇒ PYR::Response
Send a request to the API for the object
41 42 43 |
# File 'lib/pyr/response_object.rb', line 41 def call PYR.object self end |
#controller ⇒ Object
The controller name, based on the object’s class name
27 28 29 |
# File 'lib/pyr/response_object.rb', line 27 def controller @controller ||= self.class.to_s.split('::').last.tableize end |