Module: CrowdPay::InstanceMethods
- Defined in:
- lib/crowd_pay.rb
Instance Method Summary collapse
Instance Method Details
#assign_attributes(hash) ⇒ Object
36 37 38 |
# File 'lib/crowd_pay.rb', line 36 def assign_attributes(hash) send :initialize, hash end |
#initialize(opts = {}) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# 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 |
#populate_errors(error) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 |
# 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 |