Class: Airbrake::Context Private

Inherits:
Object
  • Object
show all
Defined in:
lib/airbrake-ruby/context.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Represents a thread-safe Airbrake context object, which carries arbitrary information added via merge_context calls.

Examples:

Airbrake::Context.current.merge!(foo: 'bar')

Since:

  • v5.2.1

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeContext

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Context.

Since:

  • v5.2.1



17
18
19
20
# File 'lib/airbrake-ruby/context.rb', line 17

def initialize
  @mutex = Mutex.new
  @context = {}
end

Class Method Details

.currentself

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns current, thread-local, context.

Returns:

  • (self)

Since:

  • v5.2.1



13
14
15
# File 'lib/airbrake-ruby/context.rb', line 13

def self.current
  Thread.current[:airbrake_context] ||= new
end

Instance Method Details

#clearHash

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns clears (resets) the current context.

Returns:

  • (Hash)

    clears (resets) the current context

Since:

  • v5.2.1



40
41
42
43
44
# File 'lib/airbrake-ruby/context.rb', line 40

def clear
  @mutex.synchronize do
    @context.clear
  end
end

#empty?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns checks whether the context has any data.

Returns:

  • (Boolean)

    checks whether the context has any data

Since:

  • v5.2.1



47
48
49
# File 'lib/airbrake-ruby/context.rb', line 47

def empty?
  @context.empty?
end

#merge!(other) ⇒ void

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.

Merges the given context with the current one.

Parameters:

  • other (Hash{Object=>Object})

Since:

  • v5.2.1



26
27
28
29
30
# File 'lib/airbrake-ruby/context.rb', line 26

def merge!(other)
  @mutex.synchronize do
    @context.merge!(other)
  end
end

#to_hHash

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns duplicated Hash context.

Returns:

  • (Hash)

    duplicated Hash context

Since:

  • v5.2.1



33
34
35
36
37
# File 'lib/airbrake-ruby/context.rb', line 33

def to_h
  @mutex.synchronize do
    @context.dup
  end
end