Class: Appilf::AppilfObject
- Inherits:
-
Object
- Object
- Appilf::AppilfObject
- Defined in:
- lib/appilf/appilf_object.rb
Direct Known Subclasses
DomainTrait, Listing, ResourcePage, SavedSearch, User, WatchedItem
Instance Attribute Summary collapse
-
#item_data ⇒ Object
Returns the value of attribute item_data.
-
#links ⇒ Object
Returns the value of attribute links.
-
#meta ⇒ Object
Returns the value of attribute meta.
Instance Method Summary collapse
- #add_relationships(relationships_hash) ⇒ Object
- #init_meta_data(api_element_hash) ⇒ Object
-
#initialize(api_element_hash) ⇒ AppilfObject
constructor
A new instance of AppilfObject.
- #method_missing(method_name, *args) ⇒ Object
- #respond_to_missing?(method_name, include_private = false) ⇒ Boolean
Constructor Details
#initialize(api_element_hash) ⇒ AppilfObject
Returns a new instance of AppilfObject.
21 22 23 24 |
# File 'lib/appilf/appilf_object.rb', line 21 def initialize(api_element_hash) (api_element_hash) self.item_data = api_element_hash.fetch('data', {}).methodize! end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args) ⇒ Object
37 38 39 |
# File 'lib/appilf/appilf_object.rb', line 37 def method_missing(method_name, *args) item_data.send(method_name) end |
Instance Attribute Details
#item_data ⇒ Object
Returns the value of attribute item_data.
7 8 9 |
# File 'lib/appilf/appilf_object.rb', line 7 def item_data @item_data end |
#links ⇒ Object
Returns the value of attribute links.
6 7 8 |
# File 'lib/appilf/appilf_object.rb', line 6 def links @links end |
#meta ⇒ Object
Returns the value of attribute meta.
5 6 7 |
# File 'lib/appilf/appilf_object.rb', line 5 def @meta end |
Instance Method Details
#add_relationships(relationships_hash) ⇒ Object
41 42 43 44 45 46 47 48 |
# File 'lib/appilf/appilf_object.rb', line 41 def add_relationships(relationships_hash) return unless relationships_hash self.class.instance_eval do relationships_hash.each_pair do |k, v| define_method(k) { Util.translate_from_response(v) } end end end |
#init_meta_data(api_element_hash) ⇒ Object
26 27 28 29 30 31 |
# File 'lib/appilf/appilf_object.rb', line 26 def (api_element_hash) self. = api_element_hash.fetch('data', {}).delete('meta') self.links = api_element_hash.fetch('data', {}).delete('links') self..methodize! self.links.methodize! end |
#respond_to_missing?(method_name, include_private = false) ⇒ Boolean
33 34 35 |
# File 'lib/appilf/appilf_object.rb', line 33 def respond_to_missing?(method_name, include_private = false) item_data.keys.include? method_name end |