Class: StubShell::Shell
- Inherits:
-
Object
- Object
- StubShell::Shell
- Defined in:
- lib/stub_shell/shell.rb
Instance Attribute Summary collapse
-
#parent_context ⇒ Object
readonly
Returns the value of attribute parent_context.
Instance Method Summary collapse
- #command(name, &block) ⇒ Object
-
#execute(command_string) ⇒ Object
Resolves the requested command and returns the command definition and the context from which to execute the next command.
-
#initialize(parent_context = nil, &block) ⇒ Shell
constructor
A new instance of Shell.
Constructor Details
#initialize(parent_context = nil, &block) ⇒ Shell
Returns a new instance of Shell.
5 6 7 8 9 10 |
# File 'lib/stub_shell/shell.rb', line 5 def initialize parent_context = nil, &block @parent_context = parent_context @commands = [ ] instance_eval &block end |
Instance Attribute Details
#parent_context ⇒ Object (readonly)
Returns the value of attribute parent_context.
3 4 5 |
# File 'lib/stub_shell/shell.rb', line 3 def parent_context @parent_context end |
Instance Method Details
#command(name, &block) ⇒ Object
12 13 14 |
# File 'lib/stub_shell/shell.rb', line 12 def command name, &block @commands << Command.new(name, self, &block) end |
#execute(command_string) ⇒ Object
Resolves the requested command and returns the command definition and the context from which to execute the next command.
18 19 20 21 |
# File 'lib/stub_shell/shell.rb', line 18 def execute command_string resolved_command = resolve(command_string) [resolved_command, resolved_command.current_context || self] end |