Refactoring: Improved and unified instance_action skipping possiblities into one Mixin.
This commit is contained in:
parent
90c1a0faef
commit
00f0bd8212
11 changed files with 79 additions and 55 deletions
|
@ -6,6 +6,9 @@ class Sequencer
|
|||
module Attributes
|
||||
class AddByIds < Sequencer::Unit::Base
|
||||
include ::Sequencer::Unit::Import::Common::Mapping::Mixin::ProvideMapped
|
||||
prepend ::Sequencer::Unit::Import::Common::Model::Mixin::Skip::InstanceAction
|
||||
|
||||
skip_any_instance_action
|
||||
|
||||
def process
|
||||
provide_mapped do
|
||||
|
|
|
@ -5,7 +5,9 @@ class Sequencer
|
|||
module Model
|
||||
module Attributes
|
||||
class CheckMandatory < Sequencer::Unit::Base
|
||||
prepend ::Sequencer::Unit::Import::Common::Model::Mixin::SkipOnProvidedInstanceAction
|
||||
prepend ::Sequencer::Unit::Import::Common::Model::Mixin::Skip::InstanceAction
|
||||
|
||||
skip_any_instance_action
|
||||
|
||||
uses :mapped
|
||||
provides :instance_action
|
||||
|
|
|
@ -5,7 +5,9 @@ class Sequencer
|
|||
module Model
|
||||
class Create < Sequencer::Unit::Base
|
||||
include ::Sequencer::Unit::Import::Common::Model::Mixin::HandleFailure
|
||||
prepend ::Sequencer::Unit::Import::Common::Model::Mixin::SkipOnProvidedInstanceAction
|
||||
prepend ::Sequencer::Unit::Import::Common::Model::Mixin::Skip::InstanceAction
|
||||
|
||||
skip_any_instance_action
|
||||
|
||||
uses :mapped, :model_class
|
||||
provides :instance, :instance_action
|
||||
|
|
|
@ -0,0 +1,55 @@
|
|||
class Sequencer
|
||||
class Unit
|
||||
module Import
|
||||
module Common
|
||||
module Model
|
||||
module Mixin
|
||||
module Skip
|
||||
module InstanceAction
|
||||
|
||||
module ClassMethods
|
||||
|
||||
def skip_instance_action(*instance_actions)
|
||||
declaration_accessor(
|
||||
key: __method__,
|
||||
attributes: instance_actions
|
||||
)
|
||||
end
|
||||
alias skip_instance_actions skip_instance_action
|
||||
|
||||
def skip_any_instance_action
|
||||
skip_instance_actions(:any)
|
||||
end
|
||||
|
||||
def skip_instance_action?(instance_action)
|
||||
logger.debug("Checking if skip is necessary for instance_action #{instance_action.inspect}.")
|
||||
return false if instance_action.blank?
|
||||
logger.debug("Checking if skip is necessary for skip_instance_actions #{skip_instance_actions.inspect}.")
|
||||
return false if skip_instance_actions.blank?
|
||||
return true if skip_instance_actions.include?(instance_action)
|
||||
return true if skip_instance_actions.include?(:any)
|
||||
false
|
||||
end
|
||||
end
|
||||
|
||||
def self.prepended(base)
|
||||
base.extend(ClassMethods)
|
||||
end
|
||||
|
||||
def process
|
||||
instance_action = state.optional(:instance_action)
|
||||
if self.class.skip_instance_action?(instance_action)
|
||||
logger.debug("Skipping due to provided instance_action #{instance_action.inspect}.")
|
||||
else
|
||||
logger.debug("Nope. Won't skip instance_action #{instance_action.inspect}.")
|
||||
super
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,22 +0,0 @@
|
|||
class Sequencer
|
||||
class Unit
|
||||
module Import
|
||||
module Common
|
||||
module Model
|
||||
module Mixin
|
||||
module SkipOnProvidedInstanceAction
|
||||
|
||||
def process
|
||||
if state.provided?(:instance_action)
|
||||
logger.debug("Skipping. Attribute 'instance_action' already provided.")
|
||||
else
|
||||
super
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,26 +0,0 @@
|
|||
class Sequencer
|
||||
class Unit
|
||||
module Import
|
||||
module Common
|
||||
module Model
|
||||
module Mixin
|
||||
module SkipOnSkippedInstance
|
||||
|
||||
def self.prepended(base)
|
||||
base.uses :instance_action
|
||||
end
|
||||
|
||||
def process
|
||||
if instance_action == :skipped
|
||||
logger.debug("Skipping. Attribute 'instance_action' is set to :skipped.")
|
||||
else
|
||||
super
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -8,8 +8,10 @@ class Sequencer
|
|||
module Skip
|
||||
module Blank
|
||||
class Base < Sequencer::Unit::Base
|
||||
prepend ::Sequencer::Unit::Import::Common::Model::Mixin::SkipOnProvidedInstanceAction
|
||||
include ::Sequencer::Unit::Common::Mixin::DynamicAttribute
|
||||
prepend ::Sequencer::Unit::Import::Common::Model::Mixin::Skip::InstanceAction
|
||||
|
||||
skip_any_instance_action
|
||||
|
||||
provides :instance_action
|
||||
|
||||
|
|
|
@ -8,8 +8,10 @@ class Sequencer
|
|||
module Skip
|
||||
module MissingMandatory
|
||||
class Base < Sequencer::Unit::Base
|
||||
prepend ::Sequencer::Unit::Import::Common::Model::Mixin::SkipOnProvidedInstanceAction
|
||||
include ::Sequencer::Unit::Common::Mixin::DynamicAttribute
|
||||
prepend ::Sequencer::Unit::Import::Common::Model::Mixin::Skip::InstanceAction
|
||||
|
||||
skip_any_instance_action
|
||||
|
||||
provides :instance_action
|
||||
|
||||
|
|
|
@ -5,7 +5,9 @@ class Sequencer
|
|||
module Model
|
||||
class Update < Sequencer::Unit::Base
|
||||
include ::Sequencer::Unit::Import::Common::Model::Mixin::HandleFailure
|
||||
prepend ::Sequencer::Unit::Import::Common::Model::Mixin::SkipOnProvidedInstanceAction
|
||||
prepend ::Sequencer::Unit::Import::Common::Model::Mixin::Skip::InstanceAction
|
||||
|
||||
skip_any_instance_action
|
||||
|
||||
uses :instance, :mapped
|
||||
provides :instance_action
|
||||
|
|
|
@ -5,7 +5,9 @@ class Sequencer
|
|||
module User
|
||||
module Attributes
|
||||
class Downcase < Sequencer::Unit::Base
|
||||
prepend ::Sequencer::Unit::Import::Common::Model::Mixin::SkipOnSkippedInstance
|
||||
prepend ::Sequencer::Unit::Import::Common::Model::Mixin::Skip::InstanceAction
|
||||
|
||||
skip_instance_action :skipped
|
||||
|
||||
uses :mapped
|
||||
|
||||
|
|
|
@ -5,7 +5,9 @@ class Sequencer
|
|||
module User
|
||||
module Email
|
||||
class CheckValidity < Sequencer::Unit::Base
|
||||
prepend ::Sequencer::Unit::Import::Common::Model::Mixin::SkipOnSkippedInstance
|
||||
prepend ::Sequencer::Unit::Import::Common::Model::Mixin::Skip::InstanceAction
|
||||
|
||||
skip_instance_action :skipped
|
||||
|
||||
uses :mapped
|
||||
|
||||
|
|
Loading…
Reference in a new issue