Class: Lapsoss::MergedScope
- Inherits:
-
Object
- Object
- Lapsoss::MergedScope
- Defined in:
- lib/lapsoss/merged_scope.rb
Overview
Performance-optimized scope that provides a merged view without cloning
Instance Method Summary collapse
- #add_breadcrumb(message, type: :default, **metadata) ⇒ Object
- #breadcrumbs ⇒ Object
- #extra ⇒ Object
-
#initialize(scope_stack, base_scope) ⇒ MergedScope
constructor
A new instance of MergedScope.
- #set_transaction_name(name, source: nil) ⇒ Object
- #tags ⇒ Object
- #transaction_name ⇒ Object
- #transaction_source ⇒ Object
- #user ⇒ Object
Constructor Details
#initialize(scope_stack, base_scope) ⇒ MergedScope
Returns a new instance of MergedScope.
6 7 8 9 10 |
# File 'lib/lapsoss/merged_scope.rb', line 6 def initialize(scope_stack, base_scope) @scope_stack = scope_stack @base_scope = base_scope || Scope.new = [] end |
Instance Method Details
#add_breadcrumb(message, type: :default, **metadata) ⇒ Object
46 47 48 49 50 51 52 53 |
# File 'lib/lapsoss/merged_scope.rb', line 46 def (, type: :default, **) = Breadcrumb.build(, type: type, metadata: ) << # Keep breadcrumbs to a reasonable limit .shift if .length > 20 # Clear cached breadcrumbs to force recomputation = nil end |
#breadcrumbs ⇒ Object
24 25 26 |
# File 'lib/lapsoss/merged_scope.rb', line 24 def ||= end |
#extra ⇒ Object
20 21 22 |
# File 'lib/lapsoss/merged_scope.rb', line 20 def extra @extra ||= merge_hash_contexts(:extra) end |
#set_transaction_name(name, source: nil) ⇒ Object
55 56 57 |
# File 'lib/lapsoss/merged_scope.rb', line 55 def set_transaction_name(name, source: nil) @base_scope.set_transaction_name(name, source: source) end |
#tags ⇒ Object
12 13 14 |
# File 'lib/lapsoss/merged_scope.rb', line 12 def ||= merge_hash_contexts(:tags) end |
#transaction_name ⇒ Object
28 29 30 31 32 33 34 35 |
# File 'lib/lapsoss/merged_scope.rb', line 28 def transaction_name # Check scope stack first (most recent wins) @scope_stack.reverse_each do |context| return context[:transaction_name] if context[:transaction_name] end # Fall back to base scope @base_scope.transaction_name end |
#transaction_source ⇒ Object
37 38 39 40 41 42 43 44 |
# File 'lib/lapsoss/merged_scope.rb', line 37 def transaction_source # Check scope stack first (most recent wins) @scope_stack.reverse_each do |context| return context[:transaction_source] if context[:transaction_source] end # Fall back to base scope @base_scope.transaction_source end |
#user ⇒ Object
16 17 18 |
# File 'lib/lapsoss/merged_scope.rb', line 16 def user @user ||= merge_hash_contexts(:user) end |