Module: Omise::Attributes
- Included in:
- OmiseObject
- Defined in:
- lib/omise/attributes.rb
Instance Method Summary
collapse
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args, &block) ⇒ Object
49
50
51
52
53
54
55
|
# File 'lib/omise/attributes.rb', line 49
def method_missing(method_name, *args, &block)
if key?(method_name)
self[method_name]
else
super
end
end
|
Instance Method Details
#[](key) ⇒ Object
32
33
34
35
36
37
38
39
|
# File 'lib/omise/attributes.rb', line 32
def [](key)
value = @attributes[key.to_s]
if value.is_a?(Hash)
@attributes[key.to_s] = Omise::Util.typecast(value)
else
value
end
end
|
#as_json ⇒ Object
28
29
30
|
# File 'lib/omise/attributes.rb', line 28
def as_json(*)
@attributes
end
|
#assign_attributes(attributes = {}) ⇒ Object
13
14
15
16
17
18
|
# File 'lib/omise/attributes.rb', line 13
def assign_attributes(attributes = {})
@attributes = attributes
cleanup!
yield if block_given?
self
end
|
#attributes ⇒ Object
9
10
11
|
# File 'lib/omise/attributes.rb', line 9
def attributes
@attributes
end
|
#destroyed? ⇒ Boolean
24
25
26
|
# File 'lib/omise/attributes.rb', line 24
def destroyed?
@attributes["deleted"]
end
|
#initialize(attributes = {}) ⇒ Object
5
6
7
|
# File 'lib/omise/attributes.rb', line 5
def initialize(attributes = {})
@attributes = attributes
end
|
#key?(key) ⇒ Boolean
41
42
43
|
# File 'lib/omise/attributes.rb', line 41
def key?(key)
@attributes.key?(key.to_s)
end
|
#location(id = nil) ⇒ Object
20
21
22
|
# File 'lib/omise/attributes.rb', line 20
def location(id = nil)
[@attributes["location"], id].compact.join("/")
end
|
#respond_to?(method_name) ⇒ Boolean
45
46
47
|
# File 'lib/omise/attributes.rb', line 45
def respond_to?(method_name)
key?(method_name) || super
end
|