Class: Ni::Flows::WaitForCondition
- Inherits:
-
Object
- Object
- Ni::Flows::WaitForCondition
- Defined in:
- lib/ni/flows/wait_for_condition.rb
Constant Summary collapse
- SKIP =
:skip
- WAIT =
:wait
- COMPLETED =
:completed
- METADATA_REPOSITORY_KEY =
'multiple_wait_for'
Instance Attribute Summary collapse
-
#condition ⇒ Object
Returns the value of attribute condition.
-
#timer ⇒ Object
Returns the value of attribute timer.
-
#wait_id ⇒ Object
Returns the value of attribute wait_id.
Instance Method Summary collapse
- #clear_timer!(context, metadata_repository_klass) ⇒ Object
-
#initialize(condition, interactor_klass, options = {}) ⇒ WaitForCondition
constructor
A new instance of WaitForCondition.
- #setup_timer!(context, metadata_repository_klass) ⇒ Object
- #wait_or_continue(check, context, metadata_repository_klass) ⇒ Object
- #waited_for_name?(name) ⇒ Boolean
Constructor Details
#initialize(condition, interactor_klass, options = {}) ⇒ WaitForCondition
Returns a new instance of WaitForCondition.
11 12 13 14 15 16 17 |
# File 'lib/ni/flows/wait_for_condition.rb', line 11 def initialize(condition, interactor_klass, ={}) self.timer = [:timer] condition = condition.interactor_id! if condition.is_a?(Class) self.condition = condition end |
Instance Attribute Details
#condition ⇒ Object
Returns the value of attribute condition.
9 10 11 |
# File 'lib/ni/flows/wait_for_condition.rb', line 9 def condition @condition end |
#timer ⇒ Object
Returns the value of attribute timer.
9 10 11 |
# File 'lib/ni/flows/wait_for_condition.rb', line 9 def timer @timer end |
#wait_id ⇒ Object
Returns the value of attribute wait_id.
9 10 11 |
# File 'lib/ni/flows/wait_for_condition.rb', line 9 def wait_id @wait_id end |
Instance Method Details
#clear_timer!(context, metadata_repository_klass) ⇒ Object
58 59 60 61 62 63 64 |
# File 'lib/ni/flows/wait_for_condition.rb', line 58 def clear_timer!(context, ) return unless self.timer.present? unique_timer_id = "#{self.wait_id}-#{context.system_uid}" .clear_timer!(unique_timer_id) end |
#setup_timer!(context, metadata_repository_klass) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/ni/flows/wait_for_condition.rb', line 46 def setup_timer!(context, ) return unless self.timer.present? datetime_proc, timer_klass, timer_action = self.timer datetime = datetime_proc.call timer_action ||= :perform unique_timer_id = "#{self.wait_id}-#{context.system_uid}" .setup_timer!(unique_timer_id, datetime, timer_klass.name, timer_action.to_s, contex.system_uid) end |
#wait_or_continue(check, context, metadata_repository_klass) ⇒ Object
36 37 38 39 40 41 42 43 44 |
# File 'lib/ni/flows/wait_for_condition.rb', line 36 def wait_or_continue(check, context, ) if condition.is_a?(Symbol) single_condition(check) elsif condition.is_a?(Hash) multiple_condition(check, context, ) else raise "Condition format doesn't recognized" end end |
#waited_for_name?(name) ⇒ Boolean
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/ni/flows/wait_for_condition.rb', line 19 def waited_for_name?(name) case condition when Symbol # wait_for(:some_unique_name) self.condition == name when Class #wait_for(OtherInteractor) self.condition.interactor_id! == name when Hash #wait_for(:main_key => [:name, SomeClass, [:name, -> (ctx) { ctx.a == 1 }]]) self.condition.values .flatten .select { |item| item.is_a?(Symbol) || item.is_a?(Class) } .map { |item| item.is_a?(Class) ? item.interactor_id! : item } .include?(name) else raise "Wrong WaitFor options" end end |