Class: Securetrading::BaseModel

Inherits:
Object
  • Object
show all
Defined in:
lib/securetrading/base_model.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attrs_hash = {}) ⇒ BaseModel

Returns a new instance of BaseModel.



5
6
7
8
# File 'lib/securetrading/base_model.rb', line 5

def initialize(attrs_hash = {})
  @attributes_hash = attrs_hash.presence &&
                     attrs_hash.transform_keys! { |k| k.to_s.tr('__', '') }
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(m, *args, &block) ⇒ Object (private)



31
32
33
34
# File 'lib/securetrading/base_model.rb', line 31

def method_missing(m, *args, &block)
  return super unless attributes_hash.key?(m.to_s)
  determine_value(m.to_s)
end

Instance Attribute Details

#attributes_hashObject (readonly)

Returns the value of attribute attributes_hash.



3
4
5
# File 'lib/securetrading/base_model.rb', line 3

def attributes_hash
  @attributes_hash
end

Instance Method Details

#ox_xmlObject



10
11
12
13
14
15
16
17
# File 'lib/securetrading/base_model.rb', line 10

def ox_xml
  ox = ox_from_values
  sub_classes.each do |sub_class_name|
    next unless attributes_hash.key?(sub_class_name)
    ox << send(sub_class_name).ox_xml
  end
  ox
end