Class: Appilf::AppilfObject

Inherits:
Object
  • Object
show all
Defined in:
lib/appilf/appilf_object.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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_dataObject

Returns the value of attribute item_data.



7
8
9
# File 'lib/appilf/appilf_object.rb', line 7

def item_data
  @item_data
end

Returns the value of attribute links.



6
7
8
# File 'lib/appilf/appilf_object.rb', line 6

def links
  @links
end

#metaObject

Returns the value of attribute meta.



5
6
7
# File 'lib/appilf/appilf_object.rb', line 5

def meta
  @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.meta = api_element_hash.fetch('data', {}).delete('meta')
  self.links = api_element_hash.fetch('data', {}).delete('links')
  self.meta.methodize!
  self.links.methodize!
end

#respond_to_missing?(method_name, include_private = false) ⇒ Boolean

Returns:

  • (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