Class: Options

Inherits:
Object
  • Object
show all
Defined in:
lib/airbrake/cli/options.rb

Constant Summary collapse

ATTRIBUTES =
[:error, :message, :api_key, :host, :port, :auth_token, :name,
:account, :rails_env, :scm_revision, :scm_repository, :local_username]

Instance Method Summary collapse

Constructor Details

#initialize(array = []) ⇒ Options

Parses all the options passed and stores them in attributes



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/airbrake/cli/options.rb', line 20

def initialize(array = [])
  opts = Hash[*array]
  self.error          = opts.delete("-e") || opts.delete("--error")   { RuntimeError }
  self.message        = opts.delete("-m") || opts.delete("--message") { "I've made a huge mistake" }
  self.api_key        = opts.delete("-k") || opts.delete("--api-key")        || config_from_file.api_key || ENV["AIRBRAKE_API_KEY"]
  self.host           = opts.delete("-h") || opts.delete("--host")           || config_from_file.host
  self.port           = opts.delete("-p") || opts.delete("--port")           || config_from_file.port
  self.auth_token     = opts.delete("-t") || opts.delete("--auth-token")     || ENV["AIRBRAKE_AUTH_TOKEN"]
  self.name           = opts.delete("-n") || opts.delete("--name")
  self.        = opts.delete("-a") || opts.delete("--account")        || ENV["AIRBRAKE_ACCOUNT"]
  self.rails_env      = opts.delete("-E") || opts.delete("--rails-env")      || ENV["RAILS_ENV"] || "production"
  self.scm_revision   = opts.delete("-r") || opts.delete("--scm-revision")   || ENV["REVISION"]
  self.scm_repository = opts.delete("-R") || opts.delete("--scm-repository") || ENV["REPO"]
  self.local_username = opts.delete("-u") || opts.delete("--local-username") || ENV["USER"]
  opts
end

Instance Method Details

#config_from_fileObject

Fallback to read from the initializer



38
39
40
41
42
43
44
# File 'lib/airbrake/cli/options.rb', line 38

def config_from_file
  begin
    load "config/initializers/airbrake.rb"
  rescue LoadError
  end
  Airbrake.configuration
end