Class: DataShift::LoadObject
- Inherits:
-
SimpleDelegator
- Object
- SimpleDelegator
- DataShift::LoadObject
- Defined in:
- lib/datashift/load_object.rb
Instance Attribute Summary collapse
-
#instance ⇒ Object
Returns the value of attribute instance.
Instance Method Summary collapse
-
#initialize(current_object) ⇒ LoadObject
constructor
A new instance of LoadObject.
-
#save_if_new ⇒ Object
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.
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
#instance ⇒ Object
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_new ⇒ Object
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
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..inspect}" end |