Class: ScoutApm::Context

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

Constant Summary collapse

VALID_TYPES =
[String, Symbol, Numeric, Time, Date, TrueClass, FalseClass]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(context) ⇒ Context

Returns a new instance of Context.



12
13
14
15
16
# File 'lib/scout_apm/context.rb', line 12

def initialize(context)
  @context = context
  @extra = {}
  @user = {}
end

Instance Attribute Details

#contextObject (readonly)

Returns the value of attribute context.



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

def context
  @context
end

Class Method Details

.add(hash) ⇒ Object

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



52
53
54
# File 'lib/scout_apm/context.rb', line 52

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

.add_user(hash) ⇒ Object

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



57
58
59
# File 'lib/scout_apm/context.rb', line 57

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

.currentObject



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

def self.current
  RequestManager.lookup.context
end

Instance Method Details

#add(hash) ⇒ Object

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



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

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

#add_user(hash) ⇒ Object



47
48
49
# File 'lib/scout_apm/context.rb', line 47

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

#loggerObject



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

def logger
  context.logger
end

#to_flat_hashObject



28
29
30
31
32
33
34
35
# File 'lib/scout_apm/context.rb', line 28

def to_flat_hash
  h = to_hash
  user = h.delete(:user)
  if user
    user.each { |k,v| h["user_#{k}"] = v}
  end
  h
end

#to_hashObject

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



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

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