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



50
51
52
53
54
55
56
# File 'lib/omise/attributes.rb', line 50

def method_missing(method_name, *args, &block)
  if key?(method_name)
    self[method_name]
  else
    super
  end
end

Instance Method Details

#[](key) ⇒ Object



33
34
35
36
37
38
39
40
# File 'lib/omise/attributes.rb', line 33

def [](key)
  value = @attributes[key.to_s]
  if value.is_a?(Hash)
    Omise::Util.typecast(value)
  else
    value
  end
end

#as_jsonObject



29
30
31
# File 'lib/omise/attributes.rb', line 29

def as_json(*)
  @attributes
end

#assign_attributes(attributes = {}) ⇒ Object



14
15
16
17
18
19
# File 'lib/omise/attributes.rb', line 14

def assign_attributes(attributes = {})
  cleanup!
  @attributes = attributes
  yield if block_given?
  self
end

#attributesObject



10
11
12
# File 'lib/omise/attributes.rb', line 10

def attributes
  @attributes
end

#destroyed?Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/omise/attributes.rb', line 25

def destroyed?
  @attributes["deleted"]
end

#initialize(attributes = {}) ⇒ Object



5
6
7
8
# File 'lib/omise/attributes.rb', line 5

def initialize(attributes = {})
  @expanded_attributes = {}
  @attributes = attributes
end

#key?(key) ⇒ Boolean

Returns:

  • (Boolean)


42
43
44
# File 'lib/omise/attributes.rb', line 42

def key?(key)
  @attributes.key?(key.to_s)
end

#location(id = nil) ⇒ Object



21
22
23
# File 'lib/omise/attributes.rb', line 21

def location(id = nil)
  [@attributes["location"], id].compact.join("/")
end

#respond_to?(method_name) ⇒ Boolean

Returns:

  • (Boolean)


46
47
48
# File 'lib/omise/attributes.rb', line 46

def respond_to?(method_name)
  key?(method_name) || super
end