Class: Radar::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/radar/config.rb,
lib/radar/config.rb

Overview

The configuration class used for applications. To configure your application see Application#config. This is also where all the examples are.

Defined Under Namespace

Classes: UseArray

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfig

Returns a new instance of Config.



14
15
16
17
18
19
20
21
22
23
# File 'lib/radar/config.rb', line 14

def initialize
  @reporters       = UseArray.new(&method(:add_reporter))
  @data_extensions = UseArray.new(&method(:add_data_extension))
  @matchers        = UseArray.new(&method(:add_matcher))
  @rejecters       = UseArray.new(&method(:add_matcher))
  @filters         = UseArray.new(&method(:add_filter))
  @log_location    = nil

  @data_extensions.use DataExtensions::HostEnvironment
end

Instance Attribute Details

#data_extensionsObject (readonly)

Returns the value of attribute data_extensions.



8
9
10
# File 'lib/radar/config.rb', line 8

def data_extensions
  @data_extensions
end

#filtersObject (readonly)

Returns the value of attribute filters.



11
12
13
# File 'lib/radar/config.rb', line 11

def filters
  @filters
end

#log_locationObject

Returns the value of attribute log_location.



12
13
14
# File 'lib/radar/config.rb', line 12

def log_location
  @log_location
end

#matchersObject (readonly)

Returns the value of attribute matchers.



9
10
11
# File 'lib/radar/config.rb', line 9

def matchers
  @matchers
end

#rejectersObject (readonly)

Returns the value of attribute rejecters.



10
11
12
# File 'lib/radar/config.rb', line 10

def rejecters
  @rejecters
end

#reportersObject (readonly)

Returns the value of attribute reporters.



7
8
9
# File 'lib/radar/config.rb', line 7

def reporters
  @reporters
end

Instance Method Details

#data_extension(*args, &block) ⇒ Object

Adds a data extension to the application. By default, the exception data generated by Radar is quite lean and only includes the basic information about the application and exception. Through the use of data extensions, you can add any sort of information to the exception data that you want.

Built-in data extensions can be enabled via a symbol:

config.data_extension :host_environment

Custom data extensions can be enabled via a class:

config.data_extension MyCustomExtension

Any arguments given will be passed on to the data extension class.



66
67
68
# File 'lib/radar/config.rb', line 66

def data_extension(*args, &block)
  @data_extensions.use(*args, &block)
end

#filter(*args, &block) ⇒ Object

Adds a filter to the application. Filters provide a method of filtering the exception data just prior to the data being sent to the reporters. This enables you to filter out sensitive information such as passwords, or even just to remove unnecessary keys.

Built-in filters can be enabled using a symbol shortcut:

config.filter :key, :key => :password

Custom filters can be enabled using a class:

config.filter MyCustomFilter

Or simple filters can be created using lambda functions:

config.filter do |data|
  # do something with the data and return it
  data
end

Any arguments given will be passed on to the filter class.



125
126
127
# File 'lib/radar/config.rb', line 125

def filter(*args, &block)
  @filters.use(*args, &block)
end

#match(*args, &block) ⇒ Object

Adds a matcher rule to the application. An application will only report an exception if the event agrees with at least one of the matchers.

To use a matcher, there are two options. The first is to use a symbol for the name:

config.match :class, StandardError

This will cause Radar to search for a class named "ClassMatcher" under the namespace Matchers.

A second option is to use a class itself:

config.match Radar::Matchers::ClassMatcher, StandardError

Radar will then use the specified class as the matcher.



87
88
89
# File 'lib/radar/config.rb', line 87

def match(*args, &block)
  @matchers.use(*args, &block)
end

#reject(*args, &block) ⇒ Object

Adds a rejecter rule to the application. A rejecter is the same as a matcher, so if you're not familiar with matchers, please read the documentation above #match first. The only difference with a rejecter is that if any of the rejecters return true, then the exception event is not sent to reporters.

Another important note is that rejecters always take precedence over matchers. So even if a matcher would have matched the exception, if it matches a rejecter, then it won't continue.



100
101
102
# File 'lib/radar/config.rb', line 100

def reject(*args, &block)
  @rejecters.use(*args, &block)
end

#reporter(*args, &block) ⇒ Object

Adds a reporter to the application. Unlike most exception notifiers, Radar on its own doesn't actually do anything with the exception data once it has processed it. Instead, it is up to reporters to take the exception data and do something with it. Using this method, you can enable reporters.

Built-in reporters can be accessed via a symbol:

config.reporter :file

Custom reporters can be accessed via a class:

config.reporter MyCustomReporter

And for simple reporters, you may even just use a block:

config.reporter do |event|
  # Do something with the event
end

Any arguments other than the first, including any given blocks, are passed on to the reporter class.



47
48
49
# File 'lib/radar/config.rb', line 47

def reporter(*args, &block)
  @reporters.use(*args, &block)
end