Class: Hotdog::Application
- Inherits:
-
Object
- Object
- Hotdog::Application
- Defined in:
- lib/hotdog/application.rb
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
-
#initialize ⇒ Application
constructor
A new instance of Application.
- #main(argv = []) ⇒ Object
- #run_command(command, args = []) ⇒ Object
Constructor Details
#initialize ⇒ Application
Returns a new instance of Application.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/hotdog/application.rb', line 12 def initialize() @confdir = File.join(ENV["HOME"], ".hotdog") @optparse = OptionParser.new @options = { environment: "default", minimum_expiry: 28800, # 8 hours random_expiry: 57600, # 16 hours force: false, formatter: get_formatter("plain").new, headers: false, listing: false, logger: Logger.new(STDERR), api_key: ENV["DATADOG_API_KEY"], application_key: ENV["DATADOG_APPLICATION_KEY"], print0: false, print1: true, tags: [], } @options[:logger].level = Logger::INFO end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
33 34 35 |
# File 'lib/hotdog/application.rb', line 33 def @options end |
Instance Method Details
#main(argv = []) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/hotdog/application.rb', line 35 def main(argv=[]) config = File.join(@confdir, "config.yml") if File.file?(config) @options = @options.merge(YAML.load(File.read(config))) end args = @optparse.parse(argv) unless [:api_key] raise("DATADOG_API_KEY is not set") end unless [:application_key] raise("DATADOG_APPLICATION_KEY is not set") end sqlite = File.(File.join(@confdir, "#{[:environment]}.db")) FileUtils.mkdir_p(File.dirname(sqlite)) @db = SQLite3::Database.new(sqlite) @db.synchronous = "off" begin command = ( args.shift || "help" ) run_command(command, args) rescue Errno::EPIPE # nop end end |
#run_command(command, args = []) ⇒ Object
63 64 65 |
# File 'lib/hotdog/application.rb', line 63 def run_command(command, args=[]) get_command(command).new(@db, .merge(application: self)).run(args) end |