Class: StubShell::Shell

Inherits:
Object
  • Object
show all
Defined in:
lib/stub_shell/shell.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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_contextObject (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