Class: HydraulicBrake::Configuration

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

Overview

Used to set up and modify settings for the notifier.

Constant Summary collapse

OPTIONS =
[
  :api_key,
  :backtrace_filters,
  :development_environments,
  :development_lookup,
  :environment_name,
  :framework,
  :host,
  :http_open_timeout,
  :http_read_timeout,
  :notifier_name,
  :notifier_url,
  :notifier_version,
  :params_filters,
  :port,
  :project_root,
  :protocol,
  :proxy_host,
  :proxy_pass,
  :proxy_port,
  :proxy_user,
  :rake_environment_filters,
  :rescue_rake_exceptions,
  :secure,
  :use_system_ssl_cert_chain,
].freeze
DEFAULT_PARAMS_FILTERS =
%w(password password_confirmation).freeze
DEFAULT_USER_ATTRIBUTES =
%w(id name username email).freeze
DEFAULT_BACKTRACE_FILTERS =
[
  lambda { |line|
    if defined?(HydraulicBrake.configuration.project_root) && HydraulicBrake.configuration.project_root.to_s != ''
      line.sub(/#{HydraulicBrake.configuration.project_root}/, "[PROJECT_ROOT]")
    else
      line
    end
  },
  lambda { |line| line.gsub(/^\.\//, "") },
  lambda { |line|
    if defined?(Gem)
      Gem.path.inject(line) do |line, path|
        line.gsub(/#{path}/, "[GEM_ROOT]")
      end
    end
  },
  lambda { |line| line if line !~ %r{lib/hydraulic_brake} }
].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
# File 'lib/hydraulic_brake/configuration.rb', line 141

def initialize
  @secure                   = false
  @use_system_ssl_cert_chain= false
  @host                     = 'api.airbrake.io'
  @http_open_timeout        = 2
  @http_read_timeout        = 5
  @params_filters           = DEFAULT_PARAMS_FILTERS.dup
  @backtrace_filters        = DEFAULT_BACKTRACE_FILTERS.dup
  @development_environments = %w(development test cucumber)
  @development_lookup       = true
  @notifier_name            = 'HydraulicBrake Notifier'
  @notifier_version         = VERSION
  @notifier_url             = 'https://github.com/stevecrozz/hydraulic_brake'
  @framework                = 'Standalone'
  @rescue_rake_exceptions   = nil
  @user_attributes          = DEFAULT_USER_ATTRIBUTES.dup
  @rake_environment_filters = []
end

Instance Attribute Details

#api_keyObject

The API key for your project, found on the project edit form.



33
34
35
# File 'lib/hydraulic_brake/configuration.rb', line 33

def api_key
  @api_key
end

#backtrace_filtersObject (readonly)

A list of filters for cleaning and pruning the backtrace. See #filter_backtrace.



73
74
75
# File 'lib/hydraulic_brake/configuration.rb', line 73

def backtrace_filters
  @backtrace_filters
end

#development_environmentsObject

A list of environments in which notifications should not be sent.



80
81
82
# File 'lib/hydraulic_brake/configuration.rb', line 80

def development_environments
  @development_environments
end

#development_lookupObject

true if you want to check for production errors matching development errors, false otherwise.



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

def development_lookup
  @development_lookup
end

#environment_nameObject

The name of the environment the application is running in



86
87
88
# File 'lib/hydraulic_brake/configuration.rb', line 86

def environment_name
  @environment_name
end

#frameworkObject

The framework HydraulicBrake is configured to use



105
106
107
# File 'lib/hydraulic_brake/configuration.rb', line 105

def framework
  @framework
end

#hostObject

The host to connect to



36
37
38
# File 'lib/hydraulic_brake/configuration.rb', line 36

def host
  @host
end

#http_open_timeoutObject

The HTTP open timeout in seconds (defaults to 2).



51
52
53
# File 'lib/hydraulic_brake/configuration.rb', line 51

def http_open_timeout
  @http_open_timeout
end

#http_read_timeoutObject

The HTTP read timeout in seconds (defaults to 5).



54
55
56
# File 'lib/hydraulic_brake/configuration.rb', line 54

def http_read_timeout
  @http_read_timeout
end

#loggerObject

The logger used by HydraulicBrake



102
103
104
# File 'lib/hydraulic_brake/configuration.rb', line 102

def logger
  @logger
end

#notifier_nameObject

The name of the notifier library being used to send notifications (such as “HydraulicBrake Notifier”)



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

def notifier_name
  @notifier_name
end

#notifier_urlObject

The url of the notifier library being used to send notifications



99
100
101
# File 'lib/hydraulic_brake/configuration.rb', line 99

def notifier_url
  @notifier_url
end

#notifier_versionObject

The version of the notifier library being used to send notifications (such as “1.0.2”)



96
97
98
# File 'lib/hydraulic_brake/configuration.rb', line 96

def notifier_version
  @notifier_version
end

#params_filtersObject (readonly)

A list of parameters that should be filtered out of what is sent to Airbrake. By default, all “password” attributes will have their contents replaced.



70
71
72
# File 'lib/hydraulic_brake/configuration.rb', line 70

def params_filters
  @params_filters
end

#portObject

The port on which your Airbrake server runs (defaults to 443 for secure connections, 80 for insecure connections).



40
41
42
# File 'lib/hydraulic_brake/configuration.rb', line 40

def port
  @port
end

#project_rootObject

The path to the project in which the error occurred, such as the Rails.root



89
90
91
# File 'lib/hydraulic_brake/configuration.rb', line 89

def project_root
  @project_root
end

#proxy_hostObject

The hostname of your proxy server (if using a proxy)



57
58
59
# File 'lib/hydraulic_brake/configuration.rb', line 57

def proxy_host
  @proxy_host
end

#proxy_passObject

The password to use when logging into your proxy server (if using a proxy)



66
67
68
# File 'lib/hydraulic_brake/configuration.rb', line 66

def proxy_pass
  @proxy_pass
end

#proxy_portObject

The port of your proxy server (if using a proxy)



60
61
62
# File 'lib/hydraulic_brake/configuration.rb', line 60

def proxy_port
  @proxy_port
end

#proxy_userObject

The username to use when logging into your proxy server (if using a proxy)



63
64
65
# File 'lib/hydraulic_brake/configuration.rb', line 63

def proxy_user
  @proxy_user
end

#rake_environment_filtersObject (readonly)

A list of environment keys that will be ignored from what is sent to Airbrake server Empty by default and used only in rake handler



77
78
79
# File 'lib/hydraulic_brake/configuration.rb', line 77

def rake_environment_filters
  @rake_environment_filters
end

#rescue_rake_exceptionsObject

Should HydraulicBrake catch exceptions from Rake tasks? (boolean or nil; set to nil to catch exceptions when rake isn’t running from a terminal; default is nil)



109
110
111
# File 'lib/hydraulic_brake/configuration.rb', line 109

def rescue_rake_exceptions
  @rescue_rake_exceptions
end

#secureObject Also known as: secure?

true for https connections, false for http connections.



43
44
45
# File 'lib/hydraulic_brake/configuration.rb', line 43

def secure
  @secure
end

#use_system_ssl_cert_chainObject Also known as: use_system_ssl_cert_chain?

true to use whatever CAs OpenSSL has installed on your system. false to use the ca-bundle.crt file included in HydraulicBrake itself (reccomended and default)



48
49
50
# File 'lib/hydraulic_brake/configuration.rb', line 48

def use_system_ssl_cert_chain
  @use_system_ssl_cert_chain
end

#user_attributesObject

User attributes that are being captured



112
113
114
# File 'lib/hydraulic_brake/configuration.rb', line 112

def user_attributes
  @user_attributes
end

Instance Method Details

#[](option) ⇒ Object

Allows config options to be read like a hash

Parameters:

  • option (Symbol)

    Key for a given attribute



178
179
180
# File 'lib/hydraulic_brake/configuration.rb', line 178

def [](option)
  send(option)
end

#ca_bundle_pathObject



218
219
220
221
222
223
224
# File 'lib/hydraulic_brake/configuration.rb', line 218

def ca_bundle_path
  if use_system_ssl_cert_chain? && File.exist?(OpenSSL::X509::DEFAULT_CERT_FILE)
    OpenSSL::X509::DEFAULT_CERT_FILE
  else
    local_cert_path # ca-bundle.crt built from source, see resources/README.md
  end
end

#filter_backtrace(&block) {|line| ... } ⇒ Object

Takes a block and adds it to the list of backtrace filters. When the filters run, the block will be handed each line of the backtrace and can modify it as necessary.

Examples:

config.filter_bracktrace do |line|
  line.gsub(/^#{Rails.root}/, "[Rails.root]")
end

Parameters:

  • block (Proc)

    The new backtrace filter.

Yield Parameters:

  • line (String)

    A line in the backtrace.



171
172
173
# File 'lib/hydraulic_brake/configuration.rb', line 171

def filter_backtrace(&block)
  self.backtrace_filters << block
end

#local_cert_pathObject



226
227
228
# File 'lib/hydraulic_brake/configuration.rb', line 226

def local_cert_path
  File.expand_path(File.join("..", "..", "..", "resources", "ca-bundle.crt"), __FILE__)
end

#merge(hash) ⇒ Object

Returns a hash of all configurable options merged with hash

Parameters:

  • hash (Hash)

    A set of configuration options that will take precedence over the defaults



193
194
195
# File 'lib/hydraulic_brake/configuration.rb', line 193

def merge(hash)
  to_hash.merge(hash)
end

#protocolString

Determines whether protocol should be “http” or “https”. configuration, and “https” otherwise.

Returns:

  • (String)

    Returns “http” if you’ve set secure to false in



210
211
212
213
214
215
216
# File 'lib/hydraulic_brake/configuration.rb', line 210

def protocol
  if secure?
    'https'
  else
    'http'
  end
end

#public?Boolean

Determines if the notifier will send notices.

Returns:

  • (Boolean)

    Returns false if in a development environment, true otherwise.



199
200
201
# File 'lib/hydraulic_brake/configuration.rb', line 199

def public?
  !development_environments.include?(environment_name)
end

#to_hashObject

Returns a hash of all configurable options



183
184
185
186
187
188
# File 'lib/hydraulic_brake/configuration.rb', line 183

def to_hash
  OPTIONS.inject({}) do |hash, option|
    hash[option.to_sym] = self.send(option)
    hash
  end
end