Class: Klaviyo::Resource::KlaviyoObject

Inherits:
Struct
  • Object
show all
Defined in:
lib/klaviyo/resource.rb

Direct Known Subclasses

Folder, List, Membership, Person

Instance Attribute Summary collapse

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *arguments, &block) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/klaviyo/resource.rb', line 4

def method_missing(method_name, *arguments, &block)
  if attrs.key?(method_name.to_s) || attrs.key?("$#{method_name}")
    attr_value = attrs[method_name.to_s] || attrs["$#{method_name}"]
    if attr_value.is_a?(Hash) &&
       attr_value.key?('object') && attr_value.key?('id')
      attrs[method_name.to_s] = Klaviyo::Resource.build(attr_value)
    else
      attr_value
    end
  else
    super
  end
end

Instance Attribute Details

#attrsObject

Returns the value of attribute attrs



3
4
5
# File 'lib/klaviyo/resource.rb', line 3

def attrs
  @attrs
end