Class: GemInstaller::OutputProxy

Inherits:
Object
  • Object
show all
Defined in:
lib/geminstaller/output_proxy.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#options=(value) ⇒ Object (writeonly)

Sets the attribute options

Parameters:

  • value

    the value to set the attribute options to.



3
4
5
# File 'lib/geminstaller/output_proxy.rb', line 3

def options=(value)
  @options = value
end

Instance Method Details

#default_stream=(stream) ⇒ Object



4
5
6
7
# File 'lib/geminstaller/output_proxy.rb', line 4

def default_stream=(stream)
  raise GemInstaller::GemInstallerError.new("Invalid default stream: #{stream}") unless stream == :stderr or stream == :stdout
  @default_stream = stream
end

#output(output) ⇒ Object

TODO: should remove this, make callers explicitly choose.



24
25
26
27
28
29
30
# File 'lib/geminstaller/output_proxy.rb', line 24

def output(output)
  if @default_stream == :stdout
    sysout(output)
  else
    syserr(output)
  end
end

#silent?Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/geminstaller/output_proxy.rb', line 32

def silent?
  @options && @options[:silent]
end

#syserr(err) ⇒ Object



14
15
16
17
18
19
20
21
# File 'lib/geminstaller/output_proxy.rb', line 14

def syserr(err)
  return if silent?
  if @options[:redirect_stderr_to_stdout]
    $stdout.print err
  else
    $stderr.print err
  end
end

#sysout(out) ⇒ Object



9
10
11
12
# File 'lib/geminstaller/output_proxy.rb', line 9

def sysout(out)
  return if silent?
  $stdout.print out
end