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
69
70
71
72
73
74
75
76
77
|
# File 'lib/omise/attributes.rb', line 69
def method_missing(method_name, *args, &block)
if predicate?(method_name)
!!self[method_name.to_s.chomp("?")]
elsif key?(method_name)
self[method_name]
else
super
end
end
|
Instance Method Details
#[](key) ⇒ Object
34
35
36
37
38
39
40
41
|
# File 'lib/omise/attributes.rb', line 34
def [](key)
value = @attributes[key.to_s]
if value.is_a?(Hash)
Omise::Util.typecast(value)
else
value
end
end
|
#as_json ⇒ Object
30
31
32
|
# File 'lib/omise/attributes.rb', line 30
def as_json(*)
@attributes
end
|
#assign_attributes(attributes = {}) ⇒ Object
15
16
17
18
19
20
|
# File 'lib/omise/attributes.rb', line 15
def assign_attributes(attributes = {})
cleanup!
@attributes = attributes
yield if block_given?
self
end
|
#attributes ⇒ Object
11
12
13
|
# File 'lib/omise/attributes.rb', line 11
def attributes
@attributes
end
|
#destroyed? ⇒ Boolean
26
27
28
|
# File 'lib/omise/attributes.rb', line 26
def destroyed?
@attributes["deleted"]
end
|
#initialize(attributes = {}, options = {}) ⇒ Object
5
6
7
8
9
|
# File 'lib/omise/attributes.rb', line 5
def initialize(attributes = {}, options = {})
@attributes = attributes
@options = options
@expanded_attributes = {}
end
|
#key?(key) ⇒ Boolean
43
44
45
|
# File 'lib/omise/attributes.rb', line 43
def key?(key)
@attributes.key?(key.to_s)
end
|
#location(id = nil) ⇒ Object
22
23
24
|
# File 'lib/omise/attributes.rb', line 22
def location(id = nil)
[@attributes["location"], id].compact.join("/")
end
|
#predicate?(method_name) ⇒ Boolean
47
48
49
50
51
52
53
54
55
56
57
|
# File 'lib/omise/attributes.rb', line 47
def predicate?(method_name)
method_name = method_name.to_s
question_mark = method_name.chars.last == "?"
key = method_name.chomp("?")
if question_mark && key?(key)
true
else
false
end
end
|
#respond_to_missing?(method_name, *args, &block) ⇒ Boolean
59
60
61
62
63
64
65
66
67
|
# File 'lib/omise/attributes.rb', line 59
def respond_to_missing?(method_name, *args, &block)
if predicate?(method_name)
true
elsif key?(method_name)
true
else
super
end
end
|