Class: ZTK::UI

Inherits:
Base
  • Object
show all
Defined in:
lib/ztk/ui.rb

Overview

UI Class

This class encapsulates a STDOUT, STDERR, STDIN and logging device.

Author:

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Methods inherited from Base

build_config, #config, #direct_log, hash_config, log_and_raise, #log_and_raise

Constructor Details

- (UI) initialize(configuration = {})

Returns a new instance of UI



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/ztk/ui.rb', line 23

def initialize(configuration={})
  defined?(Rails) and (rails_logger = Rails.logger)
  null_logger = (::ZTK::Logger.new("/dev/null") rescue ::Logger.new("/dev/null"))

  @stdout = (configuration[:stdout] || $stdout || STDOUT)
  @stderr = (configuration[:stderr] || $stderr || STDERR)
  @stdin  = (configuration[:stdin]  || $stdin  || STDIN)
  @logger = (configuration[:logger] || $logger || rails_logger || null_logger)

  (@stdout && @stdout.respond_to?(:sync=)) and @stdout.sync = true
  (@stderr && @stderr.respond_to?(:sync=)) and @stderr.sync = true
  (@stdin  && @stdin.respond_to?(:sync=))  and @stdin.sync  = true
  (@logger && @logger.respond_to?(:sync=)) and @logger.sync = true

  @verbose = (configuration[:verbose] || false)
  @quiet   = (configuration[:quiet]   || false)
end

Instance Attribute Details

- (Object) logger

Returns the value of attribute logger



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

def logger
  @logger
end

- (Object) quiet

Returns the value of attribute quiet



21
22
23
# File 'lib/ztk/ui.rb', line 21

def quiet
  @quiet
end

- (Object) stderr

Returns the value of attribute stderr



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

def stderr
  @stderr
end

- (Object) stdin

Returns the value of attribute stdin



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

def stdin
  @stdin
end

- (Object) stdout

Returns the value of attribute stdout



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

def stdout
  @stdout
end

- (Object) verbose

Returns the value of attribute verbose



20
21
22
# File 'lib/ztk/ui.rb', line 20

def verbose
  @verbose
end

Instance Method Details

- (Boolean) quiet?

Returns:

  • (Boolean)


45
46
47
# File 'lib/ztk/ui.rb', line 45

def quiet?
  (@quiet == true)
end

- (Boolean) verbose?

Returns:

  • (Boolean)


41
42
43
# File 'lib/ztk/ui.rb', line 41

def verbose?
  (@verbose == true)
end