module FlatMap::ModelMapper::Skipping
This helper module slightly enhances ofunctionality of the {FlatMap::OpenMapper::Skipping} module for most commonly used ActiveRecord
targets.
Public Instance Methods
skip!()
click to toggle source
Extend original skip!
method for Rails-models-based targets
Note that this will mark the target record as destroyed if it is a new record. Thus, this record will not be a subject of Rails associated validation procedures, and will not be saved as an associated record.
@return [Object]
Calls superclass method
# File lib/flat_map/model_mapper/skipping.rb, line 15 def skip! super if target.is_a?(ActiveRecord::Base) if target.new_record? # Using the instance variable directly as {ActiveRecord::Base#delete} # will freeze the record. target.instance_variable_set('@destroyed', true) else # Using reload instead of reset_changes! to reset associated nested # model changes also target.reload end end end
use!()
click to toggle source
Extend original use!
method for Rails-models-based targets, as acoompanied to skip!
method.
@return [Object]
Calls superclass method
# File lib/flat_map/model_mapper/skipping.rb, line 34 def use! super if target.is_a?(ActiveRecord::Base) if target.new_record? target.instance_variable_set('@destroyed', false) else all_nested_mountings.each(&:use!) end end end