2017-08-14 11:56:23 +00:00
|
|
|
require 'sequencer/unit/import/common/model/mixin/handle_failure'
|
|
|
|
|
|
|
|
class Sequencer
|
|
|
|
class Unit
|
|
|
|
module Import
|
|
|
|
module Common
|
|
|
|
module Model
|
|
|
|
class Save < Sequencer::Unit::Base
|
|
|
|
include ::Sequencer::Unit::Import::Common::Model::Mixin::HandleFailure
|
|
|
|
|
|
|
|
uses :instance, :dry_run
|
2017-08-30 15:16:27 +00:00
|
|
|
provides :instance
|
2017-08-14 11:56:23 +00:00
|
|
|
|
|
|
|
def process
|
|
|
|
return if dry_run
|
|
|
|
return if instance.blank?
|
|
|
|
instance.save!
|
|
|
|
rescue => e
|
|
|
|
handle_failure(e)
|
2017-08-30 15:16:27 +00:00
|
|
|
|
|
|
|
# unset instance if something went wrong
|
|
|
|
state.provide(:instance, nil)
|
2017-08-14 11:56:23 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|