Module: Conekta::Operations::Delete

Included in:
Card, Customer, Payee, PayoutMethod, Plan, Webhook
Defined in:
lib/conekta/operations/delete.rb

Instance Method Summary collapse

Instance Method Details

#deleteObject



4
5
6
7
# File 'lib/conekta/operations/delete.rb', line 4

def delete
  self.custom_action(:delete, nil, nil)
  self
end

#delete_member(parent, member) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/conekta/operations/delete.rb', line 8

def delete_member(parent, member)
  self.custom_action(:delete, nil, nil)
  parent = parent.to_sym
  member = member.to_sym
  obj = self.method(parent).call.method(member).call
  if obj.class.class_name == "ConektaObject"
    self.method(parent).call.method(member).call.each do |(k, v)|
      if v.id == self.id
        self.method(parent).call.method(member).call[k] = nil
        # Shift hash array
        shift = false
        self.method(parent).call.method(member).call.each_with_index do |v,i|
          if shift
            self.method(parent).call.method(member).call.set_val(i-1,v[1])
            self.method(parent).call.method(member).call[i-1] = v[1]
          end
          if v[1] == nil
            shift = true
          end
        end
        n_members = self.method(parent).call.method(member).call.count
        last_index = n_members - 1
        # Remove last member because the hash array was shifted
        self.method(parent).call.method(member).call.unset_key(last_index)
        self.method(parent).call.method(member).call.delete(last_index)
        break
      end
    end
  else
    self.create_attr(member.to_s, nil)
  end
  self
end