Module: CLI::UI::StdoutRouter

Defined in:
lib/cli/ui/stdout_router.rb

Defined Under Namespace

Classes: Capture, Writer

Constant Summary collapse

WRITE_WITHOUT_CLI_UI =
:write_without_cli_ui
NotEnabled =
Class.new(StandardError)

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.duplicate_output_toObject

Returns the value of attribute duplicate_output_to


8
9
10
# File 'lib/cli/ui/stdout_router.rb', line 8

def duplicate_output_to
  @duplicate_output_to
end

Class Method Details

.assert_enabled!Object

Raises:


134
135
136
# File 'lib/cli/ui/stdout_router.rb', line 134

def assert_enabled!
  raise NotEnabled unless enabled?
end

.disableObject


161
162
163
164
165
166
# File 'lib/cli/ui/stdout_router.rb', line 161

def disable
  return false unless enabled?($stdout) && enabled?($stderr)
  deactivate($stdout)
  deactivate($stderr)
  true
end

.enableObject


150
151
152
153
154
155
# File 'lib/cli/ui/stdout_router.rb', line 150

def enable
  return false if enabled?($stdout) || enabled?($stderr)
  activate($stdout, :stdout)
  activate($stderr, :stderr)
  true
end

.enabled?(stream = $stdout) ⇒ Boolean

Returns:

  • (Boolean)

157
158
159
# File 'lib/cli/ui/stdout_router.rb', line 157

def enabled?(stream = $stdout)
  stream.respond_to?(WRITE_WITHOUT_CLI_UI)
end

.ensure_activatedObject

TODO: remove this


146
147
148
# File 'lib/cli/ui/stdout_router.rb', line 146

def ensure_activated
  enable unless enabled?
end

.with_enabledObject


138
139
140
141
142
143
# File 'lib/cli/ui/stdout_router.rb', line 138

def with_enabled
  enable
  yield
ensure
  disable
end