module CrowdPay::InstanceMethods
Public Class Methods
new(opts = {})
click to toggle source
# File lib/crowd_pay.rb, line 15 def initialize(opts = {}) opts.each do |k, v| associations = self.class.class_variable_get(:@@associations) assoc_name = k.downcase.to_sym if associations.key?(assoc_name) klass = associations[assoc_name][:class_name].constantize association = v.each_with_object([]) do |data, array| obj = klass.new obj.assign_attributes(data) array << obj end instance_variable_set("@#{k.downcase}", association) else instance_variable_set("@#{k}", v) end end end
Public Instance Methods
assign_attributes(hash)
click to toggle source
# File lib/crowd_pay.rb, line 36 def assign_attributes(hash) send :initialize, hash end
populate_errors(error)
click to toggle source
# File lib/crowd_pay.rb, line 40 def populate_errors(error) errors.add(:api, (error.key?('Message') ? error['Message'] : error)) if error.key?('ModelState') model_state = error['ModelState'].symbolize_keys! model_state.each do |k, v| next if k == self.class.name.downcase.to_sym v.each do |e| errors.add(k.to_s.split('.').last, e) end end end end