Class: Retell::SDK::Unofficial::Base
- Inherits:
-
Object
- Object
- Retell::SDK::Unofficial::Base
show all
- Defined in:
- lib/retell/sdk/unofficial/base.rb
Class Attribute Summary collapse
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(client, raw_response) ⇒ Base
Returns a new instance of Base.
25
26
27
28
29
30
31
|
# File 'lib/retell/sdk/unofficial/base.rb', line 25
def initialize(client, raw_response)
@client = client
@changed_attributes = {}
self.class.attributes.each do |attr|
instance_variable_set("@#{attr}", raw_response[attr])
end
end
|
Class Attribute Details
.attributes ⇒ Object
Returns the value of attribute attributes.
6
7
8
|
# File 'lib/retell/sdk/unofficial/base.rb', line 6
def attributes
@attributes
end
|
Instance Attribute Details
#changed_attributes ⇒ Object
Returns the value of attribute changed_attributes.
19
20
21
|
# File 'lib/retell/sdk/unofficial/base.rb', line 19
def changed_attributes
@changed_attributes
end
|
#client ⇒ Object
Returns the value of attribute client.
9
10
11
|
# File 'lib/retell/sdk/unofficial/base.rb', line 9
def client
@client
end
|
Class Method Details
.each_attribute ⇒ Object
15
16
17
|
# File 'lib/retell/sdk/unofficial/base.rb', line 15
def self.each_attribute
@attributes.each { |attr| yield attr }
end
|
.inherited(subclass) ⇒ Object
11
12
13
|
# File 'lib/retell/sdk/unofficial/base.rb', line 11
def self.inherited(subclass)
subclass.instance_variable_set(:@attributes, [])
end
|
.writeable_attributes ⇒ Object
21
22
23
|
# File 'lib/retell/sdk/unofficial/base.rb', line 21
def self.writeable_attributes
@writeable_attributes ||= []
end
|
Instance Method Details
#[](key) ⇒ Object
33
34
35
|
# File 'lib/retell/sdk/unofficial/base.rb', line 33
def [](key)
send(key) if self.class.attributes.include?(key.to_sym)
end
|
#[]=(key, value) ⇒ Object
37
38
39
40
41
42
43
44
|
# File 'lib/retell/sdk/unofficial/base.rb', line 37
def []=(key, value)
if self.class.writeable_attributes.include?(key.to_sym)
instance_variable_set("@#{key}", value)
@changed_attributes[key.to_sym] = value
else
raise KeyError, "key not found or not writable: #{key}"
end
end
|
#each ⇒ Object
60
61
62
63
64
65
66
67
68
69
|
# File 'lib/retell/sdk/unofficial/base.rb', line 60
def each
if block_given?
to_h.each do |key, value|
yield(key, value)
end
to_h
else
to_enum(:each)
end
end
|
#fetch(key, default = nil) ⇒ Object
71
72
73
74
75
76
77
|
# File 'lib/retell/sdk/unofficial/base.rb', line 71
def fetch(key, default = nil)
if self.class.attributes.include?(key.to_sym)
send(key)
else
block_given? ? yield(key) : (default || raise(KeyError, "key not found: #{key}"))
end
end
|
#keys ⇒ Object
52
53
54
|
# File 'lib/retell/sdk/unofficial/base.rb', line 52
def keys
self.class.attributes
end
|
#to_h ⇒ Object
46
47
48
49
50
|
# File 'lib/retell/sdk/unofficial/base.rb', line 46
def to_h
self.class.attributes.each_with_object({}) do |attr, hash|
hash[attr] = send(attr)
end
end
|
#values ⇒ Object
56
57
58
|
# File 'lib/retell/sdk/unofficial/base.rb', line 56
def values
self.class.attributes.map { |attr| send(attr) }
end
|