Class: UseCases::Stack
- Inherits:
-
Object
- Object
- UseCases::Stack
- Defined in:
- lib/use_cases/stack.rb
Instance Attribute Summary collapse
-
#current_step ⇒ Object
Returns the value of attribute current_step.
-
#prev_step_result ⇒ Object
Returns the value of attribute prev_step_result.
-
#steps ⇒ Object
readonly
Returns the value of attribute steps.
Instance Method Summary collapse
- #bind(object) ⇒ Object
- #call(initial_value = nil) ⇒ Object
- #find_step(step_name) ⇒ Object
- #in_first_step? ⇒ Boolean
- #include_step?(step_name) ⇒ Boolean
-
#initialize(steps) ⇒ Stack
constructor
A new instance of Stack.
- #previous_result_empty? ⇒ Boolean
- #previous_step_value ⇒ Object
- #step_names ⇒ Object
Constructor Details
#initialize(steps) ⇒ Stack
Returns a new instance of Stack.
9 10 11 |
# File 'lib/use_cases/stack.rb', line 9 def initialize(steps) @steps = steps end |
Instance Attribute Details
#current_step ⇒ Object
Returns the value of attribute current_step.
7 8 9 |
# File 'lib/use_cases/stack.rb', line 7 def current_step @current_step end |
#prev_step_result ⇒ Object
Returns the value of attribute prev_step_result.
7 8 9 |
# File 'lib/use_cases/stack.rb', line 7 def prev_step_result @prev_step_result end |
#steps ⇒ Object (readonly)
Returns the value of attribute steps.
5 6 7 |
# File 'lib/use_cases/stack.rb', line 5 def steps @steps end |
Instance Method Details
#bind(object) ⇒ Object
13 14 15 16 |
# File 'lib/use_cases/stack.rb', line 13 def bind(object) steps.map! { |step| step.bind(object) } self end |
#call(initial_value = nil) ⇒ Object
18 19 20 21 22 23 24 25 |
# File 'lib/use_cases/stack.rb', line 18 def call(initial_value = nil) steps.reduce(initial_value) do |prev_result, current_step| self.current_step = current_step self.prev_step_result = prev_result yield end end |
#find_step(step_name) ⇒ Object
47 48 49 |
# File 'lib/use_cases/stack.rb', line 47 def find_step(step_name) steps.find { |step| step.name == step_name } end |
#in_first_step? ⇒ Boolean
27 28 29 |
# File 'lib/use_cases/stack.rb', line 27 def in_first_step? steps.find_index(current_step).zero? end |
#include_step?(step_name) ⇒ Boolean
43 44 45 |
# File 'lib/use_cases/stack.rb', line 43 def include_step?(step_name) step_names.include?(step_name) end |
#previous_result_empty? ⇒ Boolean
31 32 33 |
# File 'lib/use_cases/stack.rb', line 31 def previous_result_empty? prev_step_result.nil? end |
#previous_step_value ⇒ Object
35 36 37 |
# File 'lib/use_cases/stack.rb', line 35 def previous_step_value prev_step_result.value end |
#step_names ⇒ Object
39 40 41 |
# File 'lib/use_cases/stack.rb', line 39 def step_names steps.map(&:name) end |