Class: ProjectlockerErrata::Configuration

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

Overview

Used to set up and modify settings for the notifier.

Constant Summary collapse

OPTIONS =
[:api_key, :js_api_key, :backtrace_filters, :development_environments,
:development_lookup, :environment_name, :host,
:http_open_timeout, :http_read_timeout, :ignore, :ignore_by_filters,
:ignore_user_agent, :notifier_name, :notifier_url, :notifier_version,
:params_filters, :project_root, :port, :protocol, :proxy_host,
:proxy_pass, :proxy_port, :proxy_user, :secure, :use_system_ssl_cert_chain, 
:framework, :user_information, :rescue_rake_exceptions].freeze
DEFAULT_PARAMS_FILTERS =
%w(password password_confirmation).freeze
DEFAULT_BACKTRACE_FILTERS =
[
  lambda { |line|
    if defined?(ProjectlockerErrata.configuration.project_root) && ProjectlockerErrata.configuration.project_root.to_s != ''
      line.sub(/#{ProjectlockerErrata.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/projectlocker_errata} }
].freeze
IGNORE_DEFAULT =
['ActiveRecord::RecordNotFound',
'ActionController::RoutingError',
'ActionController::InvalidAuthenticityToken',
'CGI::Session::CookieStore::TamperedWithCookie',
'ActionController::UnknownAction',
'AbstractController::ActionNotFound',
'Mongoid::Errors::DocumentNotFound']

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
# File 'lib/projectlocker_errata/configuration.rb', line 136

def initialize
  @secure                   = false
  @use_system_ssl_cert_chain= false
  @host                     = 'errors.projectlocker.com'
  @http_open_timeout        = 2
  @http_read_timeout        = 5
  @params_filters           = DEFAULT_PARAMS_FILTERS.dup
  @backtrace_filters        = DEFAULT_BACKTRACE_FILTERS.dup
  @ignore_by_filters        = []
  @ignore                   = IGNORE_DEFAULT.dup
  @ignore_user_agent        = []
  @development_environments = %w(development test cucumber)
  @development_lookup       = true
  @notifier_name            = 'ProjectlockerErrata Notifier'
  @notifier_version         = VERSION
  @notifier_url             = 'http://rubyforge.org/projects/pl-errata/'
  @framework                = 'Standalone'
  @user_information         = 'ProjectlockerErrata Error {{error_id}}'
  @rescue_rake_exceptions   = nil
end

Instance Attribute Details

#api_keyObject

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



14
15
16
# File 'lib/projectlocker_errata/configuration.rb', line 14

def api_key
  @api_key
end

#backtrace_filtersObject (readonly)

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



58
59
60
# File 'lib/projectlocker_errata/configuration.rb', line 58

def backtrace_filters
  @backtrace_filters
end

#development_environmentsObject

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



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

def development_environments
  @development_environments
end

#development_lookupObject

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



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

def development_lookup
  @development_lookup
end

#environment_nameObject

The name of the environment the application is running in



76
77
78
# File 'lib/projectlocker_errata/configuration.rb', line 76

def environment_name
  @environment_name
end

#frameworkObject

The framework ProjectlockerErrata is configured to use



97
98
99
# File 'lib/projectlocker_errata/configuration.rb', line 97

def framework
  @framework
end

#hostObject

The host to connect to (defaults to errors.projectlocker.com).



23
24
25
# File 'lib/projectlocker_errata/configuration.rb', line 23

def host
  @host
end

#http_open_timeoutObject

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



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

def http_open_timeout
  @http_open_timeout
end

#http_read_timeoutObject

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



39
40
41
# File 'lib/projectlocker_errata/configuration.rb', line 39

def http_read_timeout
  @http_read_timeout
end

#ignoreObject (readonly)

A list of exception classes to ignore. The array can be appended to.



64
65
66
# File 'lib/projectlocker_errata/configuration.rb', line 64

def ignore
  @ignore
end

#ignore_by_filtersObject (readonly)

A list of filters for ignoring exceptions. See #ignore_by_filter.



61
62
63
# File 'lib/projectlocker_errata/configuration.rb', line 61

def ignore_by_filters
  @ignore_by_filters
end

#ignore_user_agentObject (readonly)

A list of user agents that are being ignored. The array can be appended to.



67
68
69
# File 'lib/projectlocker_errata/configuration.rb', line 67

def ignore_user_agent
  @ignore_user_agent
end

#js_api_keyObject



260
261
262
# File 'lib/projectlocker_errata/configuration.rb', line 260

def js_api_key
  @js_api_key || self.api_key
end

#loggerObject

The logger used by ProjectlockerErrata



91
92
93
# File 'lib/projectlocker_errata/configuration.rb', line 91

def logger
  @logger
end

#notifier_nameObject

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



82
83
84
# File 'lib/projectlocker_errata/configuration.rb', line 82

def notifier_name
  @notifier_name
end

#notifier_urlObject

The url of the notifier library being used to send notifications



88
89
90
# File 'lib/projectlocker_errata/configuration.rb', line 88

def notifier_url
  @notifier_url
end

#notifier_versionObject

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



85
86
87
# File 'lib/projectlocker_errata/configuration.rb', line 85

def notifier_version
  @notifier_version
end

#params_filtersObject (readonly)

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



55
56
57
# File 'lib/projectlocker_errata/configuration.rb', line 55

def params_filters
  @params_filters
end

#portObject

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



27
28
29
# File 'lib/projectlocker_errata/configuration.rb', line 27

def port
  @port
end

#project_rootObject

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



79
80
81
# File 'lib/projectlocker_errata/configuration.rb', line 79

def project_root
  @project_root
end

#proxy_hostObject

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



42
43
44
# File 'lib/projectlocker_errata/configuration.rb', line 42

def proxy_host
  @proxy_host
end

#proxy_passObject

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



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

def proxy_pass
  @proxy_pass
end

#proxy_portObject

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



45
46
47
# File 'lib/projectlocker_errata/configuration.rb', line 45

def proxy_port
  @proxy_port
end

#proxy_userObject

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



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

def proxy_user
  @proxy_user
end

#rescue_rake_exceptionsObject

Should ProjectlockerErrata 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)



101
102
103
# File 'lib/projectlocker_errata/configuration.rb', line 101

def rescue_rake_exceptions
  @rescue_rake_exceptions
end

#secureObject Also known as: secure?

true for https connections, false for http connections.



30
31
32
# File 'lib/projectlocker_errata/configuration.rb', line 30

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 ProjectlockerErrata itself (reccomended and default)



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

def use_system_ssl_cert_chain
  @use_system_ssl_cert_chain
end

#user_informationObject

The text that the placeholder is replaced with. {error_id} is the actual error number.



94
95
96
# File 'lib/projectlocker_errata/configuration.rb', line 94

def user_information
  @user_information
end

Instance Method Details

#[](option) ⇒ Object

Allows config options to be read like a hash

Parameters:

  • option (Symbol)

    Key for a given attribute



203
204
205
# File 'lib/projectlocker_errata/configuration.rb', line 203

def [](option)
  send(option)
end

#async(&block) ⇒ Object Also known as: async?

Should ProjectlockerErrata send notifications asynchronously (boolean, nil or callable; default is nil). Can be used as callable-setter when block provided.



246
247
248
249
250
251
# File 'lib/projectlocker_errata/configuration.rb', line 246

def async(&block)
  if block_given?
    @async = block
  end
  @async
end

#async=(use_default_or_this) ⇒ Object



254
255
256
257
258
# File 'lib/projectlocker_errata/configuration.rb', line 254

def async=(use_default_or_this)
  @async = use_default_or_this == true ?
    default_async_processor :
    use_default_or_this
end

#ca_bundle_pathObject



273
274
275
276
277
278
279
# File 'lib/projectlocker_errata/configuration.rb', line 273

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

#environment_filtersObject



268
269
270
271
# File 'lib/projectlocker_errata/configuration.rb', line 268

def environment_filters
  warn 'config.environment_filters has been deprecated and has no effect.'
  []
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.



168
169
170
# File 'lib/projectlocker_errata/configuration.rb', line 168

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

#ignore_by_filter(&block) {|data| ... } ⇒ Object

Takes a block and adds it to the list of ignore filters. When the filters run, the block will be handed the exception.

Examples:

config.ignore_by_filter do |exception_data|
  true if exception_data[:error_class] == "RuntimeError"
end

Parameters:

  • block (Proc)

    The new ignore filter

Yield Parameters:

  • data (Hash)

    The exception data given to ProjectlockerErrata.notify

Yield Returns:

  • (Boolean)

    If the block returns true the exception will be ignored, otherwise it will be processed by projectlocker_errata.



182
183
184
# File 'lib/projectlocker_errata/configuration.rb', line 182

def ignore_by_filter(&block)
  self.ignore_by_filters << block
end

#ignore_only=(names) ⇒ Object

Overrides the list of default ignored errors.

Parameters:

  • names (Array<Exception>)

    A list of exceptions to ignore.



189
190
191
# File 'lib/projectlocker_errata/configuration.rb', line 189

def ignore_only=(names)
  @ignore = [names].flatten
end

#ignore_user_agent_only=(names) ⇒ Object

Overrides the list of default ignored user agents

Parameters:



196
197
198
# File 'lib/projectlocker_errata/configuration.rb', line 196

def ignore_user_agent_only=(names)
  @ignore_user_agent = [names].flatten
end

#js_notifier=(*args) ⇒ Object



264
265
266
# File 'lib/projectlocker_errata/configuration.rb', line 264

def js_notifier=(*args)
  warn '[PROJECTLOCKER_ERRATA] config.js_notifier has been deprecated and has no effect.  You should use <%= projectlocker_errata_javascript_notifier %> directly at the top of your layouts.  Be sure to place it before all other javascript.'
end

#local_cert_pathObject



281
282
283
# File 'lib/projectlocker_errata/configuration.rb', line 281

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



218
219
220
# File 'lib/projectlocker_errata/configuration.rb', line 218

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



235
236
237
238
239
240
241
# File 'lib/projectlocker_errata/configuration.rb', line 235

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.



224
225
226
# File 'lib/projectlocker_errata/configuration.rb', line 224

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

#to_hashObject

Returns a hash of all configurable options



208
209
210
211
212
213
# File 'lib/projectlocker_errata/configuration.rb', line 208

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