Class: DataShift::LoadObject

Inherits:
SimpleDelegator
  • Object
show all
Defined in:
lib/datashift/load_object.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(current_object) ⇒ LoadObject

Returns a new instance of LoadObject.



15
16
17
18
# File 'lib/datashift/load_object.rb', line 15

def initialize(current_object)
  super
  @instance = current_object
end

Instance Attribute Details

#instanceObject

Returns the value of attribute instance.



13
14
15
# File 'lib/datashift/load_object.rb', line 13

def instance
  @instance
end

Instance Method Details

#save_if_newObject

This method usually called during processing to avoid errors with associations like

<ActiveRecord::RecordNotSaved: You cannot call create unless the parent is saved>

If the object is still invalid at this point probably indicates compulsory columns on model have not been processed before associations on that model

Raises:

  • (SaveError)


27
28
29
30
31
32
33
# File 'lib/datashift/load_object.rb', line 27

def save_if_new
  return false unless instance && instance.new_record?

  return instance.save if instance.valid?

  raise SaveError, "Cannot Save #{instance.class} : #{instance.errors.full_messages.inspect}"
end