Class: Tracelogger::App

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

Overview

Application run scenario.

Instance Method Summary collapse

Constructor Details

#initializeApp

Initializes the app’s settings and parses the CLI options.



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/tracelogger.rb', line 54

def initialize
  @config = Configuration.new
  options = {}
  OptionParser.new do |opts|
    opts.banner = "Usage: dumb_tracer [options] host\n" +
      "  Traces the route to destination host and sends\n" +
      "  the traceroute result to SYSLOG's 'daemon' facility"

    opts.separator ""
    opts.separator "Optional parameters:"

    opts.on_tail "-h", "--help", "Show this message" do
      puts opts.help
    end

  end.parse!

  @config.options = options
  @config.host    = ARGV.first

  @log = Log.new
end

Instance Method Details

#log(message) ⇒ Object

Logs the message.



78
79
80
# File 'lib/tracelogger.rb', line 78

def log message # :nodoc:
  @log.info message
end

#runObject

Runs the app scenario.



98
99
100
101
102
# File 'lib/tracelogger.rb', line 98

def run
  start
  trace
  wrapup
end

#startObject

Executed right after the start.



83
84
85
# File 'lib/tracelogger.rb', line 83

def start # :nodoc:
  log "Starting"
end

#traceObject

Logs the underlying traceroute’s result.



93
94
95
# File 'lib/tracelogger.rb', line 93

def trace # :nodoc:
  log Traceroute.new.trace @config.host
end

#wrapupObject

Executed right before the end.



88
89
90
# File 'lib/tracelogger.rb', line 88

def wrapup # :nodoc:
  log "Finishing"
end