Class: SenroUsecaser::Step
- Inherits:
-
Object
- Object
- SenroUsecaser::Step
- Defined in:
- lib/senro_usecaser/base.rb
Overview
Represents a step in an organized pipeline
Instance Attribute Summary collapse
-
#all_conditions ⇒ Object
readonly
Returns the value of attribute all_conditions.
-
#any_conditions ⇒ Object
readonly
Returns the value of attribute any_conditions.
-
#if_condition ⇒ Object
readonly
Returns the value of attribute if_condition.
-
#input_mapping ⇒ Object
readonly
Returns the value of attribute input_mapping.
-
#on_failure ⇒ Object
readonly
Returns the value of attribute on_failure.
-
#unless_condition ⇒ Object
readonly
Returns the value of attribute unless_condition.
-
#use_case_class ⇒ Object
readonly
Returns the value of attribute use_case_class.
Instance Method Summary collapse
-
#initialize(use_case_class, if_condition: nil, unless_condition: nil, on_failure: nil, all_conditions: nil, any_conditions: nil, input_mapping: nil) ⇒ Step
constructor
rubocop:disable Metrics/ParameterLists : (singleton(Base), ?if_condition: (Symbol | Proc)?, ?unless_condition: (Symbol | Proc)?, ?on_failure: Symbol?, : ?all_conditions: Array[(Symbol | Proc)]?, ?any_conditions: Array[(Symbol | Proc)]?, : ?input_mapping: (Symbol | Proc)?) -> void.
-
#map_input(input, use_case_instance) ⇒ Object
Maps the input for this step based on input_mapping configuration.
-
#should_execute?(input, use_case_instance) ⇒ Boolean
Checks if this step should be executed based on conditions.
Constructor Details
#initialize(use_case_class, if_condition: nil, unless_condition: nil, on_failure: nil, all_conditions: nil, any_conditions: nil, input_mapping: nil) ⇒ Step
rubocop:disable Metrics/ParameterLists : (singleton(Base), ?if_condition: (Symbol | Proc)?, ?unless_condition: (Symbol | Proc)?, ?on_failure: Symbol?, : ?all_conditions: Array[(Symbol | Proc)]?, ?any_conditions: Array[(Symbol | Proc)]?, : ?input_mapping: (Symbol | Proc)?) -> void
15 16 17 18 19 20 21 22 23 24 |
# File 'lib/senro_usecaser/base.rb', line 15 def initialize(use_case_class, if_condition: nil, unless_condition: nil, on_failure: nil, all_conditions: nil, any_conditions: nil, input_mapping: nil) @use_case_class = use_case_class @if_condition = if_condition @unless_condition = unless_condition @on_failure = on_failure @all_conditions = all_conditions @any_conditions = any_conditions @input_mapping = input_mapping end |
Instance Attribute Details
#all_conditions ⇒ Object (readonly)
Returns the value of attribute all_conditions.
8 9 10 |
# File 'lib/senro_usecaser/base.rb', line 8 def all_conditions @all_conditions end |
#any_conditions ⇒ Object (readonly)
Returns the value of attribute any_conditions.
8 9 10 |
# File 'lib/senro_usecaser/base.rb', line 8 def any_conditions @any_conditions end |
#if_condition ⇒ Object (readonly)
Returns the value of attribute if_condition.
8 9 10 |
# File 'lib/senro_usecaser/base.rb', line 8 def if_condition @if_condition end |
#input_mapping ⇒ Object (readonly)
Returns the value of attribute input_mapping.
8 9 10 |
# File 'lib/senro_usecaser/base.rb', line 8 def input_mapping @input_mapping end |
#on_failure ⇒ Object (readonly)
Returns the value of attribute on_failure.
8 9 10 |
# File 'lib/senro_usecaser/base.rb', line 8 def on_failure @on_failure end |
#unless_condition ⇒ Object (readonly)
Returns the value of attribute unless_condition.
8 9 10 |
# File 'lib/senro_usecaser/base.rb', line 8 def unless_condition @unless_condition end |
#use_case_class ⇒ Object (readonly)
Returns the value of attribute use_case_class.
8 9 10 |
# File 'lib/senro_usecaser/base.rb', line 8 def use_case_class @use_case_class end |
Instance Method Details
#map_input(input, use_case_instance) ⇒ Object
Maps the input for this step based on input_mapping configuration
: (untyped, untyped) -> untyped
42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/senro_usecaser/base.rb', line 42 def map_input(input, use_case_instance) return input unless input_mapping case input_mapping when Symbol use_case_instance.send(input_mapping, input) when Proc input_mapping.call(input) else input end end |
#should_execute?(input, use_case_instance) ⇒ Boolean
Checks if this step should be executed based on conditions
: (untyped, untyped) -> bool
30 31 32 33 34 35 36 37 |
# File 'lib/senro_usecaser/base.rb', line 30 def should_execute?(input, use_case_instance) return false if if_condition && !evaluate_condition(if_condition, input, use_case_instance) return false if unless_condition && evaluate_condition(unless_condition, input, use_case_instance) return false if all_conditions && !all_conditions_met?(input, use_case_instance) return false if any_conditions && !any_condition_met?(input, use_case_instance) true end |