Class: WIP::Runner::UI

Inherits:
Object
  • Object
show all
Defined in:
lib/wip/runner/ui.rb

Direct Known Subclasses

Spec::Helpers::UIHelpers::CustomUI

Instance Method Summary collapse

Constructor Details

#initialize(input = $stdin, out = $stdout, err = $stderr) ⇒ UI

Returns a new instance of UI.



6
7
8
9
10
# File 'lib/wip/runner/ui.rb', line 6

def initialize(input = $stdin, out = $stdout, err = $stderr)
  @out    = HighLine.new(input, out, nil, nil, 2, 0)
  @err    = HighLine.new(input, err, nil, nil, 2, 0)
  @output = @out
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args, &block) ⇒ Object (protected)



52
53
54
55
56
57
58
# File 'lib/wip/runner/ui.rb', line 52

def method_missing(method_name, *args, &block)
  if @output.respond_to?(method_name)
    @output.send(method_name, *args, &block)
  else
    super
  end
end

Instance Method Details

#errObject



12
13
14
15
16
17
18
19
20
21
22
# File 'lib/wip/runner/ui.rb', line 12

def err
  if block_given?
    current = @output
    @output = @err
    result  = yield
    @output = current
    result
  else
    @err
  end
end

#indent(*args, &block) ⇒ Object



36
37
38
39
40
41
42
43
# File 'lib/wip/runner/ui.rb', line 36

def indent(*args, &block)
  increase = args.shift || 1
  @out.indent_level += increase
  @err.indent_level += increase
  @output.indent(0, *args, &block)
  @out.indent_level -= increase
  @err.indent_level -= increase
end

#indent_level=(level) ⇒ Object



45
46
47
48
# File 'lib/wip/runner/ui.rb', line 45

def indent_level=(level)
  @out.indent_level = level
  @err.indent_level = level
end

#outObject



24
25
26
27
28
29
30
31
32
33
34
# File 'lib/wip/runner/ui.rb', line 24

def out
  if block_given?
    current = @output
    @output = @out
    result  = yield
    @output = current
    result
  else
    @out
  end
end