Class: ScoutApm::Context

Inherits:
Object
  • Object
show all
Defined in:
lib/scout_apm/context.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeContext

Returns a new instance of Context.



8
9
10
11
# File 'lib/scout_apm/context.rb', line 8

def initialize
  @extra = {}
  @user = {}
end

Class Method Details

.add(hash) ⇒ Object

Convenience accessor so you can just call @ScoutAPM::Context#add@



38
39
40
# File 'lib/scout_apm/context.rb', line 38

def self.add(hash)
  self.current.add(hash)
end

.add_user(hash) ⇒ Object

Convenience accessor so you can just call @ScoutAPM::Context#add_user@



43
44
45
# File 'lib/scout_apm/context.rb', line 43

def self.add_user(hash)
  self.current.add_user(hash)
end

.clear!Object



23
24
25
# File 'lib/scout_apm/context.rb', line 23

def self.clear!
  Thread.current[:scout_context] = nil
end

.currentObject



19
20
21
# File 'lib/scout_apm/context.rb', line 19

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

Instance Method Details

#add(hash) ⇒ Object

Add context ScoutApm::Context.add(account: current_account.name)



29
30
31
# File 'lib/scout_apm/context.rb', line 29

def add(hash)
  update_context(:extra,hash)
end

#add_user(hash) ⇒ Object



33
34
35
# File 'lib/scout_apm/context.rb', line 33

def add_user(hash)
  update_context(:user,hash)
end

#to_hashObject

Generates a hash representation of the Context. Example: => 100, :user => {:ip => ‘127.0.0.1’}



15
16
17
# File 'lib/scout_apm/context.rb', line 15

def to_hash
  @extra.merge({:user => @user})
end