class Airbrake::Config

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

@api private @since v1.0.0

Attributes

app_version[RW]

@return [String] the version of the user's application

blacklist_keys[RW]

@return [Array<String, Symbol, Regexp>] the keys, which should be

filtered

@since 1.2.0

code_hunks[RW]

@return [Boolean] true if the library should attach code hunks to each

frame in a backtrace, false otherwise

@since v2.5.0

environment[RW]

@return [String, Symbol] the environment the application is running in

host[RW]

@return [String] the host, which provides the API endpoint to which

exceptions should be sent
ignore_environments[RW]

@return [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.
logger[R]

@return [Logger] the default logger used for debug output

project_id[RW]

@return [Integer] the project identificator. This value must be set.

project_key[RW]

@return [String] the project key. This value must be set.

proxy[RW]

@return [Hash] the proxy parameters such as (:host, :port, :user and

:password)
queue_size[RW]

@return [Integer] the max number of notices that can be queued up

root_directory[RW]

@return [String, Pathname] the working directory of your project

timeout[RW]

@return [Integer] The HTTP timeout in seconds.

whitelist_keys[RW]

@return [Array<String, Symbol, Regexp>] the keys, which shouldn't be

filtered

@since 1.2.0

workers[RW]

@return [Integer] the number of worker threads that process the notice

queue

Public Class Methods

new(user_config = {}) click to toggle source

@param [Hash{Symbol=>Object}] user_config the hash to be used to build the

config
# File lib/airbrake-ruby/config.rb, line 84
def initialize(user_config = {})
  @validator = Config::Validator.new(self)

  self.proxy = {}
  self.queue_size = 100
  self.workers = 1
  self.code_hunks = true

  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 = []

  self.timeout = user_config[:timeout]

  self.blacklist_keys = []
  self.whitelist_keys = []

  self.root_directory = File.realpath(
    (defined?(Bundler) && Bundler.root) ||
    Dir.pwd
  )

  merge(user_config)
end

Public Instance Methods

endpoint() click to toggle source

The full URL to the Airbrake Notice API. Based on the :host option. @return [URI] the endpoint address

# File lib/airbrake-ruby/config.rb, line 117
def endpoint
  @endpoint ||=
    begin
      self.host = ('https://' << host) if host !~ %r{\Ahttps?://}
      api = "api/v3/projects/#{project_id}/notices"
      URI.join(host, api)
    end
end
ignored_environment?() click to toggle source

@return [Boolean] true if the config ignores current environment, false

otherwise
# File lib/airbrake-ruby/config.rb, line 165
def ignored_environment?
  if ignore_environments.any? && environment.nil?
    logger.warn("#{LOG_LABEL} the 'environment' option is not set, " \
                "'ignore_environments' has no effect")
  end

  ignore_environments.map(&:to_s).include?(environment.to_s)
end
logger=(logger) click to toggle source

Sets the logger. Never allows to assign `nil` as the logger. @return [Logger] the logger

# File lib/airbrake-ruby/config.rb, line 129
def logger=(logger)
  @logger = logger || @logger
end
merge(config_hash) click to toggle source

Merges the given config_hash with itself.

@example

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

@return [self] the merged config

# File lib/airbrake-ruby/config.rb, line 140
def merge(config_hash)
  config_hash.each_pair { |option, value| set_option(option, value) }
  self
end
valid?() click to toggle source

@return [Boolean] true if the config meets the requirements, false

otherwise
# File lib/airbrake-ruby/config.rb, line 148
def valid?
  return true if ignored_environment?

  return false unless @validator.valid_project_id?
  return false unless @validator.valid_project_key?
  return false unless @validator.valid_environment?

  true
end
validation_error_message() click to toggle source
# File lib/airbrake-ruby/config.rb, line 158
def validation_error_message
  @validator.error_message
end

Private Instance Methods

set_option(option, value) click to toggle source
# File lib/airbrake-ruby/config.rb, line 176
def set_option(option, value)
  __send__("#{option}=", value)
rescue NoMethodError
  raise Airbrake::Error, "unknown option '#{option}'"
end