Class: Tzu::Step
- Inherits:
-
Object
- Object
- Tzu::Step
- Defined in:
- lib/tzu/step.rb
Constant Summary collapse
- DOUBLE_MUTATOR =
"You cannot define both receives and receives_many"
Instance Attribute Summary collapse
-
#klass ⇒ Object
readonly
Returns the value of attribute klass.
-
#single_mutator ⇒ Object
readonly
Returns the value of attribute single_mutator.
-
#splat_mutator ⇒ Object
readonly
Returns the value of attribute splat_mutator.
Instance Method Summary collapse
- #as(name) ⇒ Object
-
#initialize(klass) ⇒ Step
constructor
A new instance of Step.
- #invoke_with(method) ⇒ Object
- #name ⇒ Object
- #receives(&block) ⇒ Object
- #receives_many(&block) ⇒ Object
- #run(*params, prior_results) ⇒ Object
Constructor Details
#initialize(klass) ⇒ Step
11 12 13 14 |
# File 'lib/tzu/step.rb', line 11 def initialize(klass) @klass = klass @invoke_method = :run end |
Instance Attribute Details
#klass ⇒ Object (readonly)
Returns the value of attribute klass.
9 10 11 |
# File 'lib/tzu/step.rb', line 9 def klass @klass end |
#single_mutator ⇒ Object (readonly)
Returns the value of attribute single_mutator.
9 10 11 |
# File 'lib/tzu/step.rb', line 9 def single_mutator @single_mutator end |
#splat_mutator ⇒ Object (readonly)
Returns the value of attribute splat_mutator.
9 10 11 |
# File 'lib/tzu/step.rb', line 9 def splat_mutator @splat_mutator end |
Instance Method Details
#as(name) ⇒ Object
42 43 44 |
# File 'lib/tzu/step.rb', line 42 def as(name) @name = name end |
#invoke_with(method) ⇒ Object
46 47 48 |
# File 'lib/tzu/step.rb', line 46 def invoke_with(method) @invoke_method = method end |
#name ⇒ Object
26 27 28 29 30 |
# File 'lib/tzu/step.rb', line 26 def name return @name if @name&.is_a?(Symbol) @klass.to_s.split("::").last.underscore.to_sym end |
#receives(&block) ⇒ Object
32 33 34 35 |
# File 'lib/tzu/step.rb', line 32 def receives(&block) double_mutator_error if splat? @single_mutator = block end |
#receives_many(&block) ⇒ Object
37 38 39 40 |
# File 'lib/tzu/step.rb', line 37 def receives_many(&block) double_mutator_error if @single_mutator.present? @splat_mutator = block end |
#run(*params, prior_results) ⇒ Object
16 17 18 19 20 21 22 23 24 |
# File 'lib/tzu/step.rb', line 16 def run(*params, prior_results) # Forward parameters as splat if no mutators are defined return @klass.send(@invoke_method, *params) if mutator.nil? command_params = process(*params, prior_results) return @klass.send(@invoke_method, command_params) unless splat? @klass.send(@invoke_method, *command_params) end |