lib/contrast/components/scope.rb in contrast-agent-4.1.0 vs lib/contrast/components/scope.rb in contrast-agent-4.2.0
- old
+ new
@@ -40,19 +40,62 @@
module InstanceMethods # :nodoc:
# For each instance method on a scope, define a forwarder
# to the scope on the current execution context's scope.
- Contrast::Agent::Scope.public_instance_methods(false).each do |method_sym|
- define_method(method_sym) do |*args, &block|
- scope_for_current_ec.send(method_sym, *args, &block)
- end
- end
-
def scope_for_current_ec
MONITOR.synchronize do
return EXECUTION_CONTEXT[Fiber.current] ||= Contrast::Agent::Scope.new
end
+ end
+
+ def enter_contrast_scope!
+ scope_for_current_ec.enter_contrast_scope!
+ end
+
+ def enter_deserialization_scope!
+ scope_for_current_ec.enter_deserialization_scope!
+ end
+
+ def enter_scope! name
+ scope_for_current_ec.enter_scope! name
+ end
+
+ def exit_contrast_scope!
+ scope_for_current_ec.exit_contrast_scope!
+ end
+
+ def exit_deserialization_scope!
+ scope_for_current_ec.exit_deserialization_scope!
+ end
+
+ def exit_scope! name
+ scope_for_current_ec.exit_scope! name
+ end
+
+ def in_contrast_scope?
+ scope_for_current_ec.in_contrast_scope?
+ end
+
+ def in_deserialization_scope?
+ scope_for_current_ec.in_deserialization_scope?
+ end
+
+ def in_scope? name
+ scope_for_current_ec.in_scope? name
+ end
+
+ def with_contrast_scope
+ scope_for_current_ec.enter_contrast_scope!
+ yield
+ ensure
+ scope_for_current_ec.exit_contrast_scope!
+ end
+
+ def with_deserialization_scope
+ scope_for_current_ec.enter_deserialization_scope!
+ ensure
+ scope_for_current_ec.exit_deserialization_scope!
end
# TODO: RUBY-572
#
# Current behavior is to no-op if we're not "in a request context".