Class: ScoutApm::Context
- Inherits:
-
Object
- Object
- ScoutApm::Context
- Defined in:
- lib/scout_apm/context.rb
Constant Summary collapse
- VALID_TYPES =
[String, Symbol, Numeric, Time, Date, TrueClass, FalseClass]
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.
12 13 14 15 16 |
# File 'lib/scout_apm/context.rb', line 12 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@
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 |
.current ⇒ Object
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 |
#logger ⇒ Object
18 19 20 |
# File 'lib/scout_apm/context.rb', line 18 def logger context.logger end |
#to_flat_hash ⇒ Object
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_hash ⇒ Object
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 |