module Instamojo::CommonObject

Public Class Methods

included(klass) click to toggle source
# File lib/common_object.rb, line 42
def self.included(klass)
  klass.extend(KlassMethods)
end

Public Instance Methods

assign_values(object) click to toggle source

Common intializer

# File lib/common_object.rb, line 5
def assign_values(object)
  @original = object
  object.each do |k, v|
    instance_variable_set("@#{k}", v)
  end
  self
end
construct_hash() click to toggle source

Construct hash from mutated parameters

# File lib/common_object.rb, line 35
def construct_hash
  vars = instance_variables.reject { |x| [:@client, :@original].include? x }
  Hash[vars.map { |key| [key.to_s[1..key.length], instance_variable_get(key)] }]
end
refresh()
Alias for: reload
refresh!()
Alias for: reload!
reload() click to toggle source

Reload the link/payment/payment_request/refund from the server

# File lib/common_object.rb, line 24
def reload
  @client.send(*self.detail_helper)
end
Also aliased as: refresh
reload!() click to toggle source

Same as relaod but mutable

# File lib/common_object.rb, line 29
def reload!
  obj = reload
  obj.instance_of?(self.class) ? assign_values(obj.to_h) : obj
end
Also aliased as: refresh!
to_h() click to toggle source

Return link/payment/payment_request/refund as hash

# File lib/common_object.rb, line 19
def to_h
  construct_hash
end
to_json() click to toggle source

Return link/payment/payment_request/refund as json

# File lib/common_object.rb, line 14
def to_json
  construct_hash.to_json
end