Class: Erede::Models::Base
- Inherits:
-
Object
- Object
- Erede::Models::Base
- Defined in:
- lib/erede/models/base.rb
Direct Known Subclasses
Address, Authorization, Brand, Capture, Cart, Consumer, Device, Document, Flight, Iata, Item, Passenger, Phone, Refund, Store, SubMerchant, ThreeDSecure, Transaction, Url
Instance Method Summary collapse
-
#initialize ⇒ Base
constructor
A new instance of Base.
- #set_accessors_for_api_attributes ⇒ Object
- #to_json ⇒ Object
Constructor Details
#initialize ⇒ Base
Returns a new instance of Base.
4 5 6 |
# File 'lib/erede/models/base.rb', line 4 def initialize set_accessors_for_api_attributes end |
Instance Method Details
#set_accessors_for_api_attributes ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/erede/models/base.rb', line 8 def set_accessors_for_api_attributes self.class.const_get(:API_ATTRIBUTES).each do |attr_name| define_singleton_method attr_name do instance_variable_get("@#{attr_name}") end define_singleton_method "#{attr_name}=" do |value| instance_variable_set("@#{attr_name}", value) end end end |
#to_json ⇒ Object
20 21 22 23 24 25 26 |
# File 'lib/erede/models/base.rb', line 20 def to_json(*) Hash[ self.class.const_get(:API_ATTRIBUTES).map { |attr_name| [attr_name, send(attr_name)] } ] .delete_if { |k, v| v.nil? } .to_json end |