Module: Instamojo::CommonObject

Included in:
Link, Payment, PaymentRequest, Refund
Defined in:
lib/common_object.rb

Defined Under Namespace

Modules: KlassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(klass) ⇒ Object



42
43
44
# File 'lib/common_object.rb', line 42

def self.included(klass)
  klass.extend(KlassMethods)
end

Instance Method Details

#assign_values(object) ⇒ Object

Common intializer



5
6
7
8
9
10
11
# 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_hashObject

Construct hash from mutated parameters



35
36
37
38
# 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

#reloadObject Also known as: refresh

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



24
25
26
# File 'lib/common_object.rb', line 24

def reload
  @client.send(*self.detail_helper)
end

#reload!Object Also known as: refresh!

Same as relaod but mutable



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

def reload!
  obj = reload
  obj.instance_of?(self.class) ? assign_values(obj.to_h) : obj
end

#to_hObject

Return link/payment/payment_request/refund as hash



19
20
21
# File 'lib/common_object.rb', line 19

def to_h
  construct_hash
end

#to_jsonObject

Return link/payment/payment_request/refund as json



14
15
16
# File 'lib/common_object.rb', line 14

def to_json
  construct_hash.to_json
end