Class: GenSpec::Shell

Inherits:
Thor::Shell::Basic
  • Object
show all
Defined in:
lib/genspec/shell.rb

Overview

Just like a Thor::Shell::Basic except that input and output are both redirected to the specified streams. By default, these are initialized to instances of StringIO.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(output = "", input = "") ⇒ Shell

Returns a new instance of Shell.



23
24
25
26
# File 'lib/genspec/shell.rb', line 23

def initialize(output = "", input = "")
  super()
  new(output, input)
end

Instance Attribute Details

#stderrObject

Returns the value of attribute stderr.



7
8
9
# File 'lib/genspec/shell.rb', line 7

def stderr
  @stderr
end

#stdinObject Also known as: input

Returns the value of attribute stdin.



7
8
9
# File 'lib/genspec/shell.rb', line 7

def stdin
  @stdin
end

#stdoutObject Also known as: output

Returns the value of attribute stdout.



7
8
9
# File 'lib/genspec/shell.rb', line 7

def stdout
  @stdout
end

Instance Method Details

#ask(statement, color = nil) ⇒ Object



13
14
15
16
17
18
19
20
21
# File 'lib/genspec/shell.rb', line 13

def ask(statement, color = nil)
  say "#{statement} ", color
  response = stdin.gets
  if response
    response.strip
  else
    raise "Asked '#{statement}', but input.gets returned nil!"
  end
end

#new(output = "", input = "") ⇒ Object

Reinitializes this Shell with the given input and output streams.



29
30
31
32
33
34
# File 'lib/genspec/shell.rb', line 29

def new(output="", input="")
  init_stream(:output, output)
  init_stream(:input,  input)
  @stderr = @stdout
  self
end