Class: Tinymon::Scope
- Inherits:
-
Object
- Object
- Tinymon::Scope
- Defined in:
- lib/tinymon/scope.rb
Overview
Process-wide user/tags/breadcrumbs that ride along with every event.
Constant Summary collapse
- MAX_BREADCRUMBS =
50
Instance Attribute Summary collapse
-
#breadcrumbs ⇒ Object
readonly
Returns the value of attribute breadcrumbs.
-
#tags ⇒ Object
readonly
Returns the value of attribute tags.
-
#user ⇒ Object
readonly
Returns the value of attribute user.
Instance Method Summary collapse
- #add_breadcrumb(crumb) ⇒ Object
-
#initialize ⇒ Scope
constructor
A new instance of Scope.
- #set_tag(key, value) ⇒ Object
- #set_user(user) ⇒ Object
- #snapshot ⇒ Object
Constructor Details
#initialize ⇒ Scope
Returns a new instance of Scope.
10 11 12 13 14 15 |
# File 'lib/tinymon/scope.rb', line 10 def initialize @mutex = Mutex.new @user = {} @tags = {} @breadcrumbs = [] end |
Instance Attribute Details
#breadcrumbs ⇒ Object (readonly)
Returns the value of attribute breadcrumbs.
8 9 10 |
# File 'lib/tinymon/scope.rb', line 8 def @breadcrumbs end |
#tags ⇒ Object (readonly)
Returns the value of attribute tags.
8 9 10 |
# File 'lib/tinymon/scope.rb', line 8 def @tags end |
#user ⇒ Object (readonly)
Returns the value of attribute user.
8 9 10 |
# File 'lib/tinymon/scope.rb', line 8 def user @user end |
Instance Method Details
#add_breadcrumb(crumb) ⇒ Object
25 26 27 28 29 30 |
# File 'lib/tinymon/scope.rb', line 25 def (crumb) @mutex.synchronize do @breadcrumbs.push(crumb) @breadcrumbs.shift if @breadcrumbs.length > MAX_BREADCRUMBS end end |
#set_tag(key, value) ⇒ Object
21 22 23 |
# File 'lib/tinymon/scope.rb', line 21 def set_tag(key, value) @mutex.synchronize { @tags[key.to_s] = value } end |
#set_user(user) ⇒ Object
17 18 19 |
# File 'lib/tinymon/scope.rb', line 17 def set_user(user) @mutex.synchronize { @user = user.dup } end |
#snapshot ⇒ Object
32 33 34 35 36 37 38 39 40 |
# File 'lib/tinymon/scope.rb', line 32 def snapshot @mutex.synchronize do { user: @user.dup, tags: @tags.dup, breadcrumbs: @breadcrumbs.dup, } end end |