Class: Instrumental::Configuration

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

Constant Summary collapse

DEFAULT_REPORT_INTERVAL =
15.0

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



16
17
18
19
20
21
22
23
# File 'lib/instrumental/configuration.rb', line 16

def initialize
  @enabled         = defined?(::Rails.env) ? Rails.env.production? : true
  @host            = 'in.imperialapp.com'
  @port            = 80
  @name_prefix     = ''
  @path            = '/in/'
  @report_interval = DEFAULT_REPORT_INTERVAL
end

Instance Attribute Details

#enabledObject

Returns the value of attribute enabled.



12
13
14
# File 'lib/instrumental/configuration.rb', line 12

def enabled
  @enabled
end

#hostObject

Returns the value of attribute host.



8
9
10
# File 'lib/instrumental/configuration.rb', line 8

def host
  @host
end

#loggerObject



63
64
65
66
67
# File 'lib/instrumental/configuration.rb', line 63

def logger
  # The Rails logger is not available in an initializer, so we have to look for on-demand.
  @logger ||= defined?(::Rails.logger) ? Rails.logger : Logger.new(STDOUT)
  @logger
end

#name_prefixObject

Returns the value of attribute name_prefix.



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

def name_prefix
  @name_prefix
end

#pathObject

Returns the value of attribute path.



10
11
12
# File 'lib/instrumental/configuration.rb', line 10

def path
  @path
end

#portObject

Returns the value of attribute port.



9
10
11
# File 'lib/instrumental/configuration.rb', line 9

def port
  @port
end

#report_intervalObject

Returns the value of attribute report_interval.



11
12
13
# File 'lib/instrumental/configuration.rb', line 11

def report_interval
  @report_interval
end

Instance Method Details

#api_keyObject



59
60
61
# File 'lib/instrumental/configuration.rb', line 59

def api_key
  @api_key || raise(ArgumentError, 'API key must be set in configuration')
end

#api_key=(val) ⇒ Object

Raises:

  • (ArgumentError)


53
54
55
56
57
# File 'lib/instrumental/configuration.rb', line 53

def api_key=(val)
  @api_key = val

  raise(ArgumentError, 'API key is invalid') unless @api_key =~ /^[a-f\d]{32}$/
end

#enabled?Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/instrumental/configuration.rb', line 25

def enabled?
  !!@enabled
end