Class: Fission::UI

Inherits:
Object show all
Defined in:
lib/fission/ui.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(stdout = $stdout) ⇒ UI

Internal: Initialize a UI object.

stdout - The object to use for stdout (default: $stdout). This provides

an easy way to capture/silence output if needed.

Examples

Fission::UI.new

str_io = StringIO.new
Fission::UI.new str_io


18
19
20
# File 'lib/fission/ui.rb', line 18

def initialize(stdout=$stdout)
  @stdout = stdout
end

Instance Attribute Details

#stdoutObject (readonly)

Internal: Returns the stdout value.



5
6
7
# File 'lib/fission/ui.rb', line 5

def stdout
  @stdout
end

Instance Method Details

#output(s) ⇒ Object

Internal: Outputs the specified argument to the configured stdout object. The ‘puts’ method will be called on the stdout object.

s - The String to output.

Examples

ui.output "foo bar\n"

Returns nothing.



32
33
34
# File 'lib/fission/ui.rb', line 32

def output(s)
  @stdout.puts s
end

#output_and_exit(s, exit_code) ⇒ Object

Internal: Outputs the specified argument to the configured stdout object and exits with the specified exit code.

s - The String to output. exit_code - The Integer exit code.

Examples

ui.output_and_exit 'something went wrong', 99

ui.output_and_exit 'all done', 0

Returns nothing.



66
67
68
69
# File 'lib/fission/ui.rb', line 66

def output_and_exit(s, exit_code)
  output s
  exit exit_code
end

#output_printf(string, key, value) ⇒ Object

Internal: Outputs the specified arguments printf style. The ‘printf’ method will be called on the stdout object. Currently, this assuems there are two data items.

string - The printf String. key - The String for the first data item. value - The String for the second data item.

Examples

ui.output_printf "%s    %s\n", 'foo', bar

Returns nothing.



49
50
51
# File 'lib/fission/ui.rb', line 49

def output_printf(string, key, value)
  @stdout.send :printf, string, key, value
end