Class: Securetrading::BaseModel

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

Instance Method Summary collapse

Constructor Details

#initialize(attrs_hash = {}) ⇒ BaseModel

Returns a new instance of BaseModel.



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

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)



29
30
31
32
# File 'lib/securetrading/base_model.rb', line 29

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

Instance Method Details

#ox_xmlObject



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

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