Module: ActiveZuora::Persistence

Extended by:
ActiveSupport::Concern
Defined in:
lib/active_zuora/persistence.rb

Defined Under Namespace

Modules: ClassMethods

Constant Summary collapse

MAX_BATCH_SIZE =
50

Instance Method Summary collapse

Instance Method Details

#deleteObject


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

def delete
  self.class.delete(id) > 0
end

#new_record?Boolean

Returns:

  • (Boolean)

8
9
10
# File 'lib/active_zuora/persistence.rb', line 8

def new_record?
  id.blank?
end

#reloadObject

Raises:

  • (ArgumentError)

34
35
36
37
38
# File 'lib/active_zuora/persistence.rb', line 34

def reload
  raise ArgumentError.new("You can't reload a new record") if new_record?
  self.untracked_attributes = self.class.find(id).attributes
  self
end

#saveObject


12
13
14
# File 'lib/active_zuora/persistence.rb', line 12

def save
  new_record? ? create : update
end

#save!Object


16
17
18
# File 'lib/active_zuora/persistence.rb', line 16

def save!
  raise "Could Not Save Zuora Object: #{errors.full_messages.join ', '}" unless save
end

#update_attributes(attributes) ⇒ Object


20
21
22
23
# File 'lib/active_zuora/persistence.rb', line 20

def update_attributes(attributes)
  self.attributes = attributes
  save
end

#update_attributes!(attributes) ⇒ Object


25
26
27
28
# File 'lib/active_zuora/persistence.rb', line 25

def update_attributes!(attributes)
  self.attributes = attributes
  save!
end

#xml_field_namesObject


40
41
42
43
# File 'lib/active_zuora/persistence.rb', line 40

def xml_field_names
  # If we're rendering an existing record, always include the id.
  new_record? ? super : ([:id] + super).uniq
end