Introduced new simple provider structure to DRY up Units and enforce sanitized naming.
This commit is contained in:
parent
59d642faa5
commit
de6d8c54ae
7 changed files with 62 additions and 37 deletions
|
@ -1,29 +0,0 @@
|
|||
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.first
|
||||
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
|
36
lib/sequencer/unit/common/provider/attribute.rb
Normal file
36
lib/sequencer/unit/common/provider/attribute.rb
Normal file
|
@ -0,0 +1,36 @@
|
|||
class Sequencer
|
||||
class Unit
|
||||
module Common
|
||||
module Provider
|
||||
class Attribute < Sequencer::Unit::Base
|
||||
|
||||
def process
|
||||
return if ignore?
|
||||
state.provide(attribute, value)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def attribute
|
||||
@attribute ||= provides
|
||||
end
|
||||
|
||||
def provides
|
||||
provides_list = self.class.provides
|
||||
raise "Only single provide attribute possible for class #{self.class.name}" if provides_list.size != 1
|
||||
provides_list.first
|
||||
end
|
||||
|
||||
def value
|
||||
@value ||= send(attribute)
|
||||
end
|
||||
|
||||
def ignore?
|
||||
# don't store nil values which are default anyway
|
||||
value.nil?
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
16
lib/sequencer/unit/common/provider/fallback.rb
Normal file
16
lib/sequencer/unit/common/provider/fallback.rb
Normal file
|
@ -0,0 +1,16 @@
|
|||
class Sequencer
|
||||
class Unit
|
||||
module Common
|
||||
module Provider
|
||||
class Fallback < Sequencer::Unit::Common::Provider::Attribute
|
||||
|
||||
private
|
||||
|
||||
def ignore?
|
||||
state.provided?(attribute) || super
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,14 +1,14 @@
|
|||
class Sequencer
|
||||
class Unit
|
||||
module Exchange
|
||||
class Connection < Sequencer::Unit::Common::FallbackProvider
|
||||
class Connection < Sequencer::Unit::Common::Provider::Fallback
|
||||
|
||||
uses :ews_config
|
||||
provides :ews_connection
|
||||
|
||||
private
|
||||
|
||||
def fallback
|
||||
def ews_connection
|
||||
Viewpoint::EWSClient.new(
|
||||
config[:endpoint],
|
||||
config[:user],
|
||||
|
|
|
@ -3,13 +3,13 @@ class Sequencer
|
|||
module Import
|
||||
module Exchange
|
||||
module FolderContacts
|
||||
class FolderIds < Sequencer::Unit::Common::FallbackProvider
|
||||
class FolderIds < Sequencer::Unit::Common::Provider::Fallback
|
||||
|
||||
provides :ews_folder_ids
|
||||
|
||||
private
|
||||
|
||||
def fallback
|
||||
def ews_folder_ids
|
||||
::Import::Exchange.config[:folders]
|
||||
end
|
||||
end
|
||||
|
|
|
@ -3,12 +3,13 @@ require 'import/ldap'
|
|||
class Sequencer
|
||||
class Unit
|
||||
module Ldap
|
||||
class Config < Sequencer::Unit::Common::FallbackProvider
|
||||
class Config < Sequencer::Unit::Common::Provider::Fallback
|
||||
|
||||
provides :ldap_config
|
||||
|
||||
private
|
||||
|
||||
def fallback
|
||||
def ldap_config
|
||||
::Import::Ldap.config
|
||||
end
|
||||
end
|
||||
|
|
|
@ -3,13 +3,14 @@ require 'ldap'
|
|||
class Sequencer
|
||||
class Unit
|
||||
module Ldap
|
||||
class Connection < Sequencer::Unit::Common::FallbackProvider
|
||||
class Connection < Sequencer::Unit::Common::Provider::Fallback
|
||||
|
||||
uses :ldap_config
|
||||
provides :ldap_connection
|
||||
|
||||
private
|
||||
|
||||
def fallback
|
||||
def ldap_connection
|
||||
::Ldap.new(ldap_config)
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue