Class: Sentinel::Configuration

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

Constant Summary collapse

DEFAULT_URI =
(ENV['sentinel_uri'] || 'http://localhost:3000/reports').freeze
DEFAULT_LEVEL =
(ENV['sentinel_level'] || 'INFO').freeze
DEFAULT_METHOD =
(ENV['sentinel_method'] || 'post').freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



12
13
14
15
16
# File 'lib/sentinel/configuration.rb', line 12

def initialize(uri:, level:, method:)
  @uri = uri
  @level = level
  @method = method
end

Instance Attribute Details

#levelObject

Returns the value of attribute level.



5
6
7
# File 'lib/sentinel/configuration.rb', line 5

def level
  @level
end

#methodObject

Returns the value of attribute method.



6
7
8
# File 'lib/sentinel/configuration.rb', line 6

def method
  @method
end

#uriObject

Returns the value of attribute uri.



4
5
6
# File 'lib/sentinel/configuration.rb', line 4

def uri
  @uri
end

Instance Method Details

#default_loggerObject



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

def default_logger
  @default_logger ||= defined?(::Rails) ? ::Rails.logger : ::Logger.new(STDERR)
end

#merge(options) ⇒ Object



24
25
26
27
28
29
# File 'lib/sentinel/configuration.rb', line 24

def merge(options)
  new_configuration = clone
  new_configuration.merge!(options)

  new_configuration
end

#merge!(options) ⇒ Object



31
32
33
34
35
36
37
38
39
40
# File 'lib/sentinel/configuration.rb', line 31

def merge!(options)
  options.each do |name, value|
    variable_name = "@#{name}"
    next unless instance_variable_defined?(variable_name)

    instance_variable_set(variable_name, value)
  end

  self
end

#use_ssl?Boolean

Returns:

  • (Boolean)


46
47
48
# File 'lib/sentinel/configuration.rb', line 46

def use_ssl?
  uri.match(/^https:/) ? true : false
end