Class: Roast::OutputRouter

Inherits:
Object
  • Object
show all
Defined in:
lib/roast/output_router.rb

Constant Summary collapse

WRITE_WITHOUT_ROAST =

This is the name of the alias methods for ‘:write` on the $stdout and $stderr objects that bypass OutputRouter’s wrapper. Calling this method will write to those output stream directly.

:write_without_roast

Class Method Summary collapse

Class Method Details

.disable!Object

: () -> bool



22
23
24
25
26
27
28
29
# File 'lib/roast/output_router.rb', line 22

def disable!
  return false unless enabled?

  deactivate($stdout)
  deactivate($stderr)
  @output_fiber = nil
  true
end

.enable!Object

: () -> bool



12
13
14
15
16
17
18
19
# File 'lib/roast/output_router.rb', line 12

def enable!
  return false if enabled?

  activate($stdout, :stdout)
  activate($stderr, :stderr)
  mark_as_output_fiber!
  true
end

.enabled?Boolean

: () -> bool

Returns:

  • (Boolean)


32
33
34
# File 'lib/roast/output_router.rb', line 32

def enabled?
  $stdout.respond_to?(WRITE_WITHOUT_ROAST)
end

.mark_as_output_fiber!Object

: () -> void



42
43
44
# File 'lib/roast/output_router.rb', line 42

def mark_as_output_fiber!
  @output_fiber = Fiber.current
end

.output_fiber?Boolean

: () -> bool

Returns:

  • (Boolean)


37
38
39
# File 'lib/roast/output_router.rb', line 37

def output_fiber?
  @output_fiber == Fiber.current
end