Module: BraintreeRails::Persistence::InstanceMethods

Defined in:
lib/braintree_rails/persistence.rb

Instance Method Summary collapse

Instance Method Details

#deleteObject



77
# File 'lib/braintree_rails/persistence.rb', line 77

def delete; destroy; end

#delete!Object



78
# File 'lib/braintree_rails/persistence.rb', line 78

def delete!; destroy; end

#destroyObject



67
68
69
70
71
72
73
74
75
# File 'lib/braintree_rails/persistence.rb', line 67

def destroy
  if persisted?
    run_callbacks :destroy do
      self.class.delete(id)
    end
  end
  self.persisted = false unless frozen?
  freeze
end

#destroy!Object



79
# File 'lib/braintree_rails/persistence.rb', line 79

def destroy!; destroy; end

#new_record?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/braintree_rails/persistence.rb', line 34

def new_record?
  !persisted?
end

#persisted?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/braintree_rails/persistence.rb', line 30

def persisted?
  !!persisted
end

#reloadObject



38
39
40
41
# File 'lib/braintree_rails/persistence.rb', line 38

def reload
  init(self.class.braintree_model_class.find(id))
  self
end

#saveObject



43
44
45
46
47
48
49
# File 'lib/braintree_rails/persistence.rb', line 43

def save(*)
  run_callbacks :save do
    create_or_update
  end
rescue RecordInvalid
  false
end

#save!Object



51
52
53
54
55
# File 'lib/braintree_rails/persistence.rb', line 51

def save!(*)
  run_callbacks :save do
    create_or_update!
  end
end

#update_attributes(attributes) ⇒ Object



57
58
59
60
# File 'lib/braintree_rails/persistence.rb', line 57

def update_attributes(attributes)
  assign_attributes(attributes)
  save
end

#update_attributes!(attributes) ⇒ Object



62
63
64
65
# File 'lib/braintree_rails/persistence.rb', line 62

def update_attributes!(attributes)
  assign_attributes(attributes)
  save!
end