Class: Airbrake::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/airbrake-ruby/config.rb

Overview

Represents the Airbrake config. A config contains all the options that you can use to configure an Airbrake instance.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(user_config = {}) ⇒ Config

Returns a new instance of Config.

Parameters:

  • user_config (Hash{Symbol=>Object}) (defaults to: {})

    the hash to be used to build the config



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/airbrake-ruby/config.rb', line 59

def initialize(user_config = {})
  self.proxy = {}
  self.queue_size = 100
  self.workers = 1

  self.logger = Logger.new(STDOUT)
  logger.level = Logger::WARN

  self.project_id = user_config[:project_id]
  self.project_key = user_config[:project_key]
  self.host = 'https://airbrake.io'

  self.ignore_environments = []

  merge(user_config)
end

Instance Attribute Details

#app_versionString

Returns the version of the user’s application.

Returns:

  • (String)

    the version of the user’s application



25
26
27
# File 'lib/airbrake-ruby/config.rb', line 25

def app_version
  @app_version
end

#environmentString, Symbol

Returns the environment the application is running in.

Returns:

  • (String, Symbol)

    the environment the application is running in



47
48
49
# File 'lib/airbrake-ruby/config.rb', line 47

def environment
  @environment
end

#hostString

Returns the host, which provides the API endpoint to which exceptions should be sent.

Returns:

  • (String)

    the host, which provides the API endpoint to which exceptions should be sent



39
40
41
# File 'lib/airbrake-ruby/config.rb', line 39

def host
  @host
end

#ignore_environmentsArray<String, Symbol>

Returns the array of environments that forbids sending exceptions when the application is running in them. Other possible environments not listed in the array will allow sending occurring exceptions.

Returns:

  • (Array<String, Symbol>)

    the array of environments that forbids sending exceptions when the application is running in them. Other possible environments not listed in the array will allow sending occurring exceptions.



54
55
56
# File 'lib/airbrake-ruby/config.rb', line 54

def ignore_environments
  @ignore_environments
end

#loggerLogger

Returns the default logger used for debug output.

Returns:

  • (Logger)

    the default logger used for debug output



21
22
23
# File 'lib/airbrake-ruby/config.rb', line 21

def logger
  @logger
end

#project_idInteger

Returns the project identificator. This value must be set.

Returns:

  • (Integer)

    the project identificator. This value must be set.



8
9
10
# File 'lib/airbrake-ruby/config.rb', line 8

def project_id
  @project_id
end

#project_keyString

Returns the project key. This value must be set.

Returns:

  • (String)

    the project key. This value must be set.



12
13
14
# File 'lib/airbrake-ruby/config.rb', line 12

def project_key
  @project_key
end

#proxyHash

Returns the proxy parameters such as (:host, :port, :user and :password).

Returns:

  • (Hash)

    the proxy parameters such as (:host, :port, :user and :password)



17
18
19
# File 'lib/airbrake-ruby/config.rb', line 17

def proxy
  @proxy
end

#queue_sizeInteger

Returns the max number of notices that can be queued up.

Returns:

  • (Integer)

    the max number of notices that can be queued up



29
30
31
# File 'lib/airbrake-ruby/config.rb', line 29

def queue_size
  @queue_size
end

#root_directoryString, Pathname

Returns the working directory of your project.

Returns:

  • (String, Pathname)

    the working directory of your project



43
44
45
# File 'lib/airbrake-ruby/config.rb', line 43

def root_directory
  @root_directory
end

#workersInteger

Returns the number of worker threads that process the notice queue.

Returns:

  • (Integer)

    the number of worker threads that process the notice queue



34
35
36
# File 'lib/airbrake-ruby/config.rb', line 34

def workers
  @workers
end

Instance Method Details

#endpointURI

The full URL to the Airbrake Notice API. Based on the :host option.

Returns:

  • (URI)

    the endpoint address



79
80
81
82
83
84
85
86
# File 'lib/airbrake-ruby/config.rb', line 79

def endpoint
  @endpoint ||=
    begin
      self.host = ('https://' << host) if host !~ %r{\Ahttps?://}
      api = "/api/v3/projects/#{project_id}/notices?key=#{project_key}"
      URI.join(host, api)
    end
end

#merge(config_hash) ⇒ self

Merges the given config_hash with itself.

Examples:

config.merge(host: 'localhost:8080')

Returns:

  • (self)

    the merged config



102
103
104
105
# File 'lib/airbrake-ruby/config.rb', line 102

def merge(config_hash)
  config_hash.each_pair { |option, value| set_option(option, value) }
  self
end