Class: ScoutApm::Context
- Inherits:
-
Object
- Object
- ScoutApm::Context
- Defined in:
- lib/scout_apm/context.rb
Instance Attribute Summary collapse
-
#context ⇒ Object
readonly
Returns the value of attribute context.
Class Method Summary collapse
-
.add(hash) ⇒ Object
Convenience accessor so you can just call @ScoutAPM::Context#add@.
-
.add_user(hash) ⇒ Object
Convenience accessor so you can just call @ScoutAPM::Context#add_user@.
- .current ⇒ Object
Instance Method Summary collapse
-
#add(hash) ⇒ Object
Add context ScoutApm::Context.add(account: current_account.name).
- #add_user(hash) ⇒ Object
-
#initialize(context) ⇒ Context
constructor
A new instance of Context.
- #logger ⇒ Object
- #to_flat_hash ⇒ Object
-
#to_hash ⇒ Object
Generates a hash representation of the Context.
Constructor Details
#initialize(context) ⇒ Context
Returns a new instance of Context.
10 11 12 13 14 |
# File 'lib/scout_apm/context.rb', line 10 def initialize(context) @context = context @extra = {} @user = {} end |
Instance Attribute Details
#context ⇒ Object (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@
50 51 52 |
# File 'lib/scout_apm/context.rb', line 50 def self.add(hash) self.current.add(hash) end |
.add_user(hash) ⇒ Object
Convenience accessor so you can just call @ScoutAPM::Context#add_user@
55 56 57 |
# File 'lib/scout_apm/context.rb', line 55 def self.add_user(hash) self.current.add_user(hash) end |
.current ⇒ Object
35 36 37 |
# File 'lib/scout_apm/context.rb', line 35 def self.current RequestManager.lookup.context end |
Instance Method Details
#add(hash) ⇒ Object
Add context ScoutApm::Context.add(account: current_account.name)
41 42 43 |
# File 'lib/scout_apm/context.rb', line 41 def add(hash) update_context(:extra,hash) end |
#add_user(hash) ⇒ Object
45 46 47 |
# File 'lib/scout_apm/context.rb', line 45 def add_user(hash) update_context(:user,hash) end |
#logger ⇒ Object
16 17 18 |
# File 'lib/scout_apm/context.rb', line 16 def logger context.logger end |
#to_flat_hash ⇒ Object
26 27 28 29 30 31 32 33 |
# File 'lib/scout_apm/context.rb', line 26 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_hash ⇒ Object
Generates a hash representation of the Context. Example: => 100, :user => {:ip => ‘127.0.0.1’}
22 23 24 |
# File 'lib/scout_apm/context.rb', line 22 def to_hash @extra.merge({:user => @user}) end |