Class: NaturalDSL::Command
- Inherits:
-
Object
- Object
- NaturalDSL::Command
- Defined in:
- lib/natural_dsl/command.rb
Instance Attribute Summary collapse
-
#execution_block ⇒ Object
readonly
Returns the value of attribute execution_block.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Class Method Summary collapse
Instance Method Summary collapse
- #build(&block) ⇒ Object
- #expectations ⇒ Object
-
#initialize(name) ⇒ Command
constructor
A new instance of Command.
- #run(vm) ⇒ Object
Constructor Details
#initialize(name) ⇒ Command
Returns a new instance of Command.
12 13 14 |
# File 'lib/natural_dsl/command.rb', line 12 def initialize(name) @name = name end |
Instance Attribute Details
#execution_block ⇒ Object (readonly)
Returns the value of attribute execution_block.
10 11 12 |
# File 'lib/natural_dsl/command.rb', line 10 def execution_block @execution_block end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
10 11 12 |
# File 'lib/natural_dsl/command.rb', line 10 def name @name end |
Class Method Details
.build(command_name, &block) ⇒ Object
6 7 8 |
# File 'lib/natural_dsl/command.rb', line 6 def self.build(command_name, &block) new(command_name).build(&block) end |
Instance Method Details
#build(&block) ⇒ Object
16 17 18 19 20 21 22 23 24 25 |
# File 'lib/natural_dsl/command.rb', line 16 def build(&block) tap do |command| command.instance_eval(&block) invalid_expectations = command.expectations[0..-2].select(&:with_value?) if invalid_expectations.any? raise "Command #{command.name} attempts to consume value after #{invalid_expectations.first}" end end end |
#expectations ⇒ Object
31 32 33 |
# File 'lib/natural_dsl/command.rb', line 31 def expectations @expectations ||= [] end |
#run(vm) ⇒ Object
27 28 29 |
# File 'lib/natural_dsl/command.rb', line 27 def run(vm) CommandRunner.new(self, vm).run end |