Module: Nadir

Extended by:
Nadir
Included in:
Nadir
Defined in:
lib/nadir.rb,
lib/nadir/cli.rb,
lib/nadir/config.rb,
lib/nadir/version.rb,
lib/nadir/notification.rb,
lib/nadir/plugins/rails.rb,
lib/nadir/middleware/rack.rb,
lib/nadir/plugins/sidekiq.rb,
lib/nadir/transport/http_async.rb

Defined Under Namespace

Modules: Middleware, Transport Classes: CLI, Config, NadirTestException, Notification, Railtie, Sidekiq

Constant Summary collapse

VERSION =
'1.2.1'

Instance Method Summary collapse

Instance Method Details

#configObject



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

def config
  @config ||= Config.new
end

#configure {|config| ... } ⇒ Object

Yields:



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

def configure
  yield config if block_given?
end

#loggerObject



18
19
20
# File 'lib/nadir.rb', line 18

def logger
  config.logger
end

#notify(exception, params = {}) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/nadir.rb', line 22

def notify(exception, params = {})
  return false unless config.validate

  notification = Notification.new(exception, process_params(params))

  transport.deliver notification.to_params

  true
rescue => e
  logger.error "[Nadir] Internal error: #{e.inspect}"

  false
end

#process_params(params) ⇒ Object



36
37
38
39
40
41
42
43
44
45
# File 'lib/nadir.rb', line 36

def process_params(params)
  ctx = Thread.current[:nadir_context]

  if ctx
    params[:job] = ctx.delete(:job) if ctx[:job]
    params[:context] = ctx if ctx
  end

  params
end

#with_context(payload) ⇒ Object



47
48
49
50
51
52
# File 'lib/nadir.rb', line 47

def with_context(payload)
  Thread.current[:nadir_context] = payload
  yield
ensure
  Thread.current[:nadir_context] = nil
end