Class: Datumfactory::Config
- Inherits:
-
Object
- Object
- Datumfactory::Config
show all
- Extended by:
- Forwardable
- Defined in:
- lib/datumfactory/config/yaml.rb,
lib/datumfactory/util/config.rb,
lib/datumfactory/config/defaults.rb
Defined Under Namespace
Modules: Yaml
Classes: Boolean, ConfigError
Constant Summary
collapse
- KEY_REPLACEMENT =
Regexp.new('[^a-z\d_]', Regexp::IGNORECASE).freeze
- DOTTED_KEY =
Regexp.new('\A([^\.]+)\.(.+)\z').freeze
- NOT_BLANK =
Regexp.new('\S').freeze
- DEVELOPMENT_ENVIRONMENTS =
%w[development test].map(&:freeze).freeze
- DEFAULT_PATHS =
['config/datumfactory.yml'].map(&:freeze).freeze
- OPTIONS =
{
api_key: {
description: 'The API key for your Datumfactory container.',
default: nil,
type: String
}
}.freeze
- DEFAULTS =
Hash[OPTIONS.map{|k,v| [k, v[:default]] }].freeze
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(opts = {}) ⇒ Config
Returns a new instance of Config.
24
25
26
27
28
29
|
# File 'lib/datumfactory/util/config.rb', line 24
def initialize(opts = {})
@ruby = opts.freeze
@env = {}.freeze
@yaml = {}.freeze
@framework = {}.freeze
end
|
Instance Attribute Details
#env ⇒ Object
Returns the value of attribute env.
31
32
33
|
# File 'lib/datumfactory/util/config.rb', line 31
def env
@env
end
|
#framework ⇒ Object
Returns the value of attribute framework.
31
32
33
|
# File 'lib/datumfactory/util/config.rb', line 31
def framework
@framework
end
|
#ruby ⇒ Object
Returns the value of attribute ruby.
31
32
33
|
# File 'lib/datumfactory/util/config.rb', line 31
def ruby
@ruby
end
|
#yaml ⇒ Object
Returns the value of attribute yaml.
31
32
33
|
# File 'lib/datumfactory/util/config.rb', line 31
def yaml
@yaml
end
|
Instance Method Details
#backend ⇒ Object
120
121
122
123
|
# File 'lib/datumfactory/util/config.rb', line 120
def backend
init_backend! unless @backend
@backend
end
|
#backend=(backend) ⇒ Object
125
126
127
128
|
# File 'lib/datumfactory/util/config.rb', line 125
def backend=(backend)
set(:backend, backend)
@backend = nil
end
|
#backtrace_filter(&block) ⇒ Object
52
53
54
55
56
57
58
59
|
# File 'lib/datumfactory/util/config.rb', line 52
def backtrace_filter(&block)
if block_given?
warn('DEPRECATED: backtrace_filter is deprecated. Please use before_notify instead. See https://docs.honeybadger.io/ruby/support/v4-upgrade#backtrace_filter')
self[:backtrace_filter] = block
end
self[:backtrace_filter]
end
|
#before_notify_hooks ⇒ Object
61
62
63
|
# File 'lib/datumfactory/util/config.rb', line 61
def before_notify_hooks
(ruby[:before_notify] || []).clone
end
|
#ca_bundle_path ⇒ Object
163
164
165
166
167
168
169
170
171
|
# File 'lib/datumfactory/util/config.rb', line 163
def ca_bundle_path
if self[:'connection.system_ssl_cert_chain'] && File.exist?(OpenSSL::X509::DEFAULT_CERT_FILE)
OpenSSL::X509::DEFAULT_CERT_FILE
elsif self[:'connection.ssl_ca_bundle_path']
self[:'connection.ssl_ca_bundle_path']
else
local_cert_path
end
end
|
44
45
46
47
48
49
50
|
# File 'lib/datumfactory/util/config.rb', line 44
def configure
new_ruby = Ruby.new(self)
yield(new_ruby)
self.ruby = ruby.merge(new_ruby).freeze
@logger = @backend = nil
self
end
|
#connection_port ⇒ Object
177
178
179
180
181
182
183
184
185
|
# File 'lib/datumfactory/util/config.rb', line 177
def connection_port
if self[:'connection.port']
self[:'connection.port']
elsif self[:'connection.secure']
443
else
80
end
end
|
#connection_protocol ⇒ Object
187
188
189
190
191
192
193
|
# File 'lib/datumfactory/util/config.rb', line 187
def connection_protocol
if self[:'connection.secure']
'https'
else
'http'
end
end
|
145
146
147
|
# File 'lib/datumfactory/util/config.rb', line 145
def debug?
!!self[:debug]
end
|
#detected_framework ⇒ Object
240
241
242
243
244
245
246
247
248
249
250
251
252
|
# File 'lib/datumfactory/util/config.rb', line 240
def detected_framework
if self[:framework] =~ NOT_BLANK
self[:framework].to_sym
elsif defined?(::Rails::VERSION) && ::Rails::VERSION::STRING > '3.0'
:rails
elsif defined?(::Sinatra::VERSION)
:sinatra
elsif defined?(::Rack.release)
:rack
else
:ruby
end
end
|
130
131
132
|
# File 'lib/datumfactory/util/config.rb', line 130
def dev?
self[:env] && Array(self[:development_environments]).include?(self[:env])
end
|
#exception_filter(&block) ⇒ Object
65
66
67
68
69
70
71
72
|
# File 'lib/datumfactory/util/config.rb', line 65
def exception_filter(&block)
if block_given?
warn('DEPRECATED: exception_filter is deprecated. Please use before_notify instead. See https://docs.honeybadger.io/ruby/support/v4-upgrade#exception_filter')
self[:exception_filter] = block
end
self[:exception_filter]
end
|
#exception_fingerprint(&block) ⇒ Object
74
75
76
77
78
79
80
81
|
# File 'lib/datumfactory/util/config.rb', line 74
def exception_fingerprint(&block)
if block_given?
warn('DEPRECATED: exception_fingerprint is deprecated. Please use before_notify instead. See https://docs.honeybadger.io/ruby/support/v4-upgrade#exception_fingerprint')
self[:exception_fingerprint] = block
end
self[:exception_fingerprint]
end
|
#excluded_request_keys ⇒ Object
203
204
205
206
207
208
209
210
|
# File 'lib/datumfactory/util/config.rb', line 203
def excluded_request_keys
[].tap do |keys|
keys << :session if self[:'request.disable_session']
keys << :params if self[:'request.disable_params']
keys << :cgi_data if self[:'request.disable_environment']
keys << :url if self[:'request.disable_url']
end
end
|
#framework_name ⇒ Object
254
255
256
257
258
259
260
261
262
|
# File 'lib/datumfactory/util/config.rb', line 254
def framework_name
case detected_framework
when :rails then "Rails #{::Rails::VERSION::STRING}"
when :sinatra then "Sinatra #{::Sinatra::VERSION}"
when :rack then "Rack #{::Rack.release}"
else
"Ruby #{RUBY_VERSION}"
end
end
|
#get(key) ⇒ Object
Also known as:
[]
83
84
85
86
87
88
89
90
91
92
|
# File 'lib/datumfactory/util/config.rb', line 83
def get(key)
IVARS.each do |var|
source = instance_variable_get(var)
if source.has_key?(key)
return source[key]
end
end
DEFAULTS[key]
end
|
#ignored_classes ⇒ Object
155
156
157
158
159
160
161
|
# File 'lib/datumfactory/util/config.rb', line 155
def ignored_classes
ignore_only = get(:'exceptions.ignore_only')
return ignore_only if ignore_only
return DEFAULTS[:'exceptions.ignore'] unless ignore = get(:'exceptions.ignore')
DEFAULTS[:'exceptions.ignore'] | Array(ignore)
end
|
#load!(framework: {}, env: ENV) ⇒ Object
33
34
35
36
37
38
39
40
41
42
|
# File 'lib/datumfactory/util/config.rb', line 33
def load!(framework: {}, env: ENV)
return self if @load
self.framework = framework.freeze
self.env = Env.new(env).freeze
load_config_from_disk {|yaml| self.yaml = yaml.freeze }
detect_revision!
@loaded = true
self
end
|
#load_plugin?(name) ⇒ Boolean
223
224
225
226
227
228
|
# File 'lib/datumfactory/util/config.rb', line 223
def load_plugin?(name)
return false if includes_token?(self[:'skipped_plugins'], name)
return true unless self[:plugins].kind_of?(Array)
includes_token?(self[:plugins], name)
end
|
#local_cert_path ⇒ Object
173
174
175
|
# File 'lib/datumfactory/util/config.rb', line 173
def local_cert_path
File.expand_path(File.join('..', '..', '..', 'resources', 'ca-bundle.crt'), __FILE__)
end
|
149
150
151
152
153
|
# File 'lib/datumfactory/util/config.rb', line 149
def log_debug?
return debug? if self[:'logging.debug'].nil?
!!self[:'logging.debug']
end
|
#log_level(key = :'logging.level') ⇒ Object
212
213
214
215
216
217
218
219
220
221
|
# File 'lib/datumfactory/util/config.rb', line 212
def log_level(key = :'logging.level')
case self[key].to_s
when /\A(0|debug)\z/i then Logger::DEBUG
when /\A(1|info)\z/i then Logger::INFO
when /\A(2|warn)\z/i then Logger::WARN
when /\A(3|error)\z/i then Logger::ERROR
else
Logger::INFO
end
end
|
#logger ⇒ Object
115
116
117
118
|
# File 'lib/datumfactory/util/config.rb', line 115
def logger
init_logging! unless @logger
@logger
end
|
#max_queue_size ⇒ Object
195
196
197
|
# File 'lib/datumfactory/util/config.rb', line 195
def max_queue_size
self[:max_queue_size]
end
|
#params_filters ⇒ Object
199
200
201
|
# File 'lib/datumfactory/util/config.rb', line 199
def params_filters
Array(self[:'request.filter_keys'])
end
|
138
139
140
141
142
143
|
# File 'lib/datumfactory/util/config.rb', line 138
def public?
return true if self[:report_data]
return false if self[:report_data] == false
!self[:env] || !dev?
end
|
#root_regexp ⇒ Object
230
231
232
233
234
235
236
237
238
|
# File 'lib/datumfactory/util/config.rb', line 230
def root_regexp
return @root_regexp if @root_regexp
return nil if @no_root
root = get(:root).to_s
@no_root = true and return nil unless root =~ NOT_BLANK
@root_regexp = Regexp.new("^#{ Regexp.escape(root) }")
end
|
#set(key, value) ⇒ Object
Also known as:
[]=
95
96
97
98
|
# File 'lib/datumfactory/util/config.rb', line 95
def set(key, value)
self.ruby = ruby.merge(key => value).freeze
@logger = @backend = nil
end
|
#to_hash(defaults = false) ⇒ Object
Also known as:
to_h
101
102
103
104
105
106
107
108
109
|
# File 'lib/datumfactory/util/config.rb', line 101
def to_hash(defaults = false)
hash = [:@ruby, :@env, :@yaml, :@framework].reverse.reduce({}) do |a,e|
a.merge!(instance_variable_get(e))
end
hash = DEFAULTS.merge(hash) if defaults
undotify_keys(hash.select {|k,v| DEFAULTS.has_key?(k) })
end
|
#warn_development? ⇒ Boolean
134
135
136
|
# File 'lib/datumfactory/util/config.rb', line 134
def warn_development?
dev? && backend.kind_of?(Backend::Null)
end
|