Introduced Sequencer Unit base class Sequencer::Unit::Common::FallbackProvider to handle simple setting fallback values of state attributes if not already present.
This commit is contained in:
parent
598d7b2060
commit
e73f75c458
6 changed files with 65 additions and 34 deletions
|
@ -9,6 +9,7 @@ class Sequencer
|
|||
'Import::Ldap::Users::StaticAttributes',
|
||||
'Import::Ldap::Users::DryRun::Flag',
|
||||
'Import::Ldap::Users::DryRun::Payload',
|
||||
'Ldap::Config',
|
||||
'Ldap::Connection',
|
||||
'Import::Ldap::Users::UserRoles',
|
||||
'Import::Ldap::Users::Sum',
|
||||
|
|
29
lib/sequencer/unit/common/fallback_provider.rb
Normal file
29
lib/sequencer/unit/common/fallback_provider.rb
Normal file
|
@ -0,0 +1,29 @@
|
|||
class Sequencer
|
||||
class Unit
|
||||
module Common
|
||||
class FallbackProvider < Sequencer::Unit::Base
|
||||
|
||||
def process
|
||||
provides = self.class.provides
|
||||
raise 'Only one provide attribute possible' if provides.size != 1
|
||||
|
||||
attribute = provides.shift
|
||||
return if state.provided?(attribute)
|
||||
|
||||
result = fallback
|
||||
|
||||
# don't store nil values which are default anyway
|
||||
return if result.nil?
|
||||
|
||||
state.provide(attribute, result)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def fallback
|
||||
raise 'Missing implementation of fallback method'
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,27 +1,22 @@
|
|||
class Sequencer
|
||||
class Unit
|
||||
module Exchange
|
||||
class Connection < Sequencer::Unit::Base
|
||||
class Connection < Sequencer::Unit::Common::FallbackProvider
|
||||
|
||||
uses :ews_config
|
||||
provides :ews_connection
|
||||
|
||||
def process
|
||||
# check if EWS connection is already given (sub sequence)
|
||||
return if state.provided?(:ews_connection)
|
||||
|
||||
state.provide(:ews_connection) do
|
||||
Viewpoint::EWSClient.new(
|
||||
config[:endpoint],
|
||||
config[:user],
|
||||
config[:password],
|
||||
additional_opts
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def fallback
|
||||
Viewpoint::EWSClient.new(
|
||||
config[:endpoint],
|
||||
config[:user],
|
||||
config[:password],
|
||||
additional_opts
|
||||
)
|
||||
end
|
||||
|
||||
def config
|
||||
@config ||= begin
|
||||
ews_config || ::Import::Exchange.config
|
||||
|
|
|
@ -3,19 +3,14 @@ class Sequencer
|
|||
module Import
|
||||
module Exchange
|
||||
module FolderContacts
|
||||
class FolderIds < Sequencer::Unit::Base
|
||||
include ::Sequencer::Unit::Exchange::Folders::Mixin::Folder
|
||||
class FolderIds < Sequencer::Unit::Common::FallbackProvider
|
||||
|
||||
provides :ews_folder_ids
|
||||
|
||||
def process
|
||||
# check if ids are already processed
|
||||
return if state.provided?(:ews_folder_ids)
|
||||
private
|
||||
|
||||
state.provide(:ews_folder_ids) do
|
||||
config = ::Import::Exchange.config
|
||||
config[:folders]
|
||||
end
|
||||
def fallback
|
||||
::Import::Exchange.config[:folders]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
17
lib/sequencer/unit/ldap/config.rb
Normal file
17
lib/sequencer/unit/ldap/config.rb
Normal file
|
@ -0,0 +1,17 @@
|
|||
require 'import/ldap'
|
||||
|
||||
class Sequencer
|
||||
class Unit
|
||||
module Ldap
|
||||
class Config < Sequencer::Unit::Common::FallbackProvider
|
||||
provides :ldap_config
|
||||
|
||||
private
|
||||
|
||||
def fallback
|
||||
::Import::Ldap.config
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,22 +1,16 @@
|
|||
require 'ldap'
|
||||
require 'import/ldap'
|
||||
|
||||
class Sequencer
|
||||
class Unit
|
||||
module Ldap
|
||||
class Connection < Sequencer::Unit::Base
|
||||
class Connection < Sequencer::Unit::Common::FallbackProvider
|
||||
uses :ldap_config
|
||||
provides :ldap_connection
|
||||
|
||||
def process
|
||||
return if state.provided?(:ldap_connection)
|
||||
private
|
||||
|
||||
state.provide(:ldap_connection) do
|
||||
config = ldap_config
|
||||
config ||= ::Import::Ldap.config
|
||||
|
||||
::Ldap.new(config)
|
||||
end
|
||||
def fallback
|
||||
::Ldap.new(ldap_config)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue