Class: Expectacle::ThrowerBase

Inherits:
Object
  • Object
show all
Defined in:
lib/expectacle/thrower_base.rb

Overview

Basic state setup/management

Direct Known Subclasses

Thrower

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(timeout: 60, verbose: true, base_dir: Dir.pwd, logger: $stdout) ⇒ Expectacle::ThrowerBase

Constructor

Parameters:

  • timeout (Integer) (defaults to: 60)

    Seconds to timeout. (default: 60sec)

  • verbose (Boolean) (defaults to: true)

    Flag to enable verbose output. (default: true)

  • base_dir (String) (defaults to: Dir.pwd)

    Base directory to find files. (default: Dir.pwd)

  • logger (IO) (defaults to: $stdout)

    IO Object to logging. (default $stdout)



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/expectacle/thrower_base.rb', line 25

def initialize(timeout: 60, verbose: true,
               base_dir: Dir.pwd, logger: $stdout)
  # default
  @host_param = {}
  # remote connection timeout (sec)
  @timeout = timeout
  # cli mode flag
  @enable_mode = false
  # debug (use debug print to stdout)
  $expect_verbose = verbose
  # base dir
  @base_dir = File.expand_path(base_dir)
  # logger
  @logger = Logger.new(logger)
  setup_default_logger
end

Instance Attribute Details

#base_dirString (readonly)

Returns Base directory path to find params/hosts/commands file.

Returns:

  • (String)

    Base directory path to find params/hosts/commands file.



15
16
17
# File 'lib/expectacle/thrower_base.rb', line 15

def base_dir
  @base_dir
end

#loggerLogger

Returns Logger instance.

Returns:

  • (Logger)

    Logger instance.



13
14
15
# File 'lib/expectacle/thrower_base.rb', line 13

def logger
  @logger
end

Instance Method Details

#commands_dirString

Path to command list file directory.

Returns:

  • (String)


56
57
58
# File 'lib/expectacle/thrower_base.rb', line 56

def commands_dir
  File.join @base_dir, 'commands'
end

#hosts_dirString

Path to host list file directory.

Returns:

  • (String)


50
51
52
# File 'lib/expectacle/thrower_base.rb', line 50

def hosts_dir
  File.join @base_dir, 'hosts'
end

#prompts_dirString

Path to prompt file directory.

Returns:

  • (String)


44
45
46
# File 'lib/expectacle/thrower_base.rb', line 44

def prompts_dir
  File.join @base_dir, 'prompts'
end

#setup_loggerObject

Setup common settings of logger instance.



61
62
63
64
65
66
# File 'lib/expectacle/thrower_base.rb', line 61

def setup_logger
  @logger.level = Logger::INFO
  @logger.formatter = proc do |severity, datetime, progname, msg|
    "#{datetime} #{progname} [#{severity}] #{msg}\n"
  end
end