Class: Guard::ArubaAdapter

Inherits:
Object
  • Object
show all
Defined in:
lib/guard/aruba_adapter.rb

Instance Method Summary collapse

Constructor Details

#initialize(argv, stdin = STDIN, stdout = STDOUT, stderr = STDERR, kernel = Kernel) ⇒ ArubaAdapter

Returns a new instance of ArubaAdapter


5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/guard/aruba_adapter.rb', line 5

def initialize(argv, stdin = STDIN, stdout = STDOUT, stderr = STDERR,
               kernel = Kernel)
  @argv = argv
  @stdin = stdin
  @stdout = stdout
  @stderr = stderr
  @kernel = kernel

  if ENV["INSIDE_ARUBA_TEST"] == "1"
    UI.options = UI.options.merge(flush_seconds: 0)
  end
end

Instance Method Details

#executeObject


24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/guard/aruba_adapter.rb', line 24

def execute
  # Thor accesses these streams directly rather than letting
  # them be injected, so we replace them...
  $stderr = @stderr
  $stdin = @stdin
  $stdout = @stdout

  # Run our normal Thor app the way we know and love.
  CLI.start(@argv)

  # Thor::Base#start does not have a return value, assume
  # success if no exception is raised.
  0
rescue StandardError => e
  # The ruby interpreter would pipe this to STDERR and exit 1 in the case
  # of an unhandled exception
  b = e.backtrace
  @stderr.puts "#{b.shift}: #{e.message} (#{e.class})"
  @stderr.puts b.map { |s| "\tfrom #{s}" }.join("\n")
  1
rescue SystemExit => e
  e.status
ensure
  # flush the logger so the output doesn't appear in next CLI invocation
  Guard.listener.stop if Guard.listener
  UI.logger.flush
  UI.logger.close
  UI.reset_logger

  # ...then we put them back.
  $stderr = STDERR
  $stdin = STDIN
  $stdout = STDOUT
end

#execute!Object


18
19
20
21
22
# File 'lib/guard/aruba_adapter.rb', line 18

def execute!
  exit_code = execute
  # Proxy our exit code back to the injected kernel.
  @kernel.exit(exit_code)
end