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
Returns a new instance of Step.
8 9 10 11 |
# File 'lib/tzu/step.rb', line 8 def initialize(klass) @klass = klass @invoke_method = :run end |
Instance Attribute Details
#klass ⇒ Object (readonly)
Returns the value of attribute klass.
6 7 8 |
# File 'lib/tzu/step.rb', line 6 def klass @klass end |
#single_mutator ⇒ Object (readonly)
Returns the value of attribute single_mutator.
6 7 8 |
# File 'lib/tzu/step.rb', line 6 def single_mutator @single_mutator end |
#splat_mutator ⇒ Object (readonly)
Returns the value of attribute splat_mutator.
6 7 8 |
# File 'lib/tzu/step.rb', line 6 def splat_mutator @splat_mutator end |
Instance Method Details
#as(name) ⇒ Object
38 39 40 |
# File 'lib/tzu/step.rb', line 38 def as(name) @name = name end |
#invoke_with(method) ⇒ Object
42 43 44 |
# File 'lib/tzu/step.rb', line 42 def invoke_with(method) @invoke_method = method end |
#name ⇒ Object
23 24 25 26 |
# File 'lib/tzu/step.rb', line 23 def name return @name if @name && @name.is_a?(Symbol) @klass.to_s.split('::').last.symbolize end |
#receives(&block) ⇒ Object
28 29 30 31 |
# File 'lib/tzu/step.rb', line 28 def receives(&block) double_mutator_error if splat? @single_mutator = block end |
#receives_many(&block) ⇒ Object
33 34 35 36 |
# File 'lib/tzu/step.rb', line 33 def receives_many(&block) double_mutator_error if @single_mutator.present? @splat_mutator = block end |
#run(*params, prior_results) ⇒ Object
13 14 15 16 17 18 19 20 21 |
# File 'lib/tzu/step.rb', line 13 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 |