Module: Contrast::Components::Scope::InstanceMethods

Defined in:
lib/contrast/components/scope.rb

Overview

:nodoc:

Instance Method Summary collapse

Instance Method Details

#enter_contrast_scope!Object



51
52
53
# File 'lib/contrast/components/scope.rb', line 51

def enter_contrast_scope!
  scope_for_current_ec.enter_contrast_scope!
end

#enter_deserialization_scope!Object



55
56
57
# File 'lib/contrast/components/scope.rb', line 55

def enter_deserialization_scope!
  scope_for_current_ec.enter_deserialization_scope!
end

#enter_scope!(name) ⇒ Object



59
60
61
# File 'lib/contrast/components/scope.rb', line 59

def enter_scope! name
  scope_for_current_ec.enter_scope! name
end

#exit_contrast_scope!Object



63
64
65
# File 'lib/contrast/components/scope.rb', line 63

def exit_contrast_scope!
  scope_for_current_ec.exit_contrast_scope!
end

#exit_deserialization_scope!Object



67
68
69
# File 'lib/contrast/components/scope.rb', line 67

def exit_deserialization_scope!
  scope_for_current_ec.exit_deserialization_scope!
end

#exit_scope!(name) ⇒ Object



71
72
73
# File 'lib/contrast/components/scope.rb', line 71

def exit_scope! name
  scope_for_current_ec.exit_scope! name
end

#in_contrast_scope?Boolean

Returns:

  • (Boolean)


75
76
77
# File 'lib/contrast/components/scope.rb', line 75

def in_contrast_scope?
  scope_for_current_ec.in_contrast_scope?
end

#in_deserialization_scope?Boolean

Returns:

  • (Boolean)


79
80
81
# File 'lib/contrast/components/scope.rb', line 79

def in_deserialization_scope?
  scope_for_current_ec.in_deserialization_scope?
end

#in_request_context?Boolean

TODO: RUBY-572

Current behavior is to no-op if we’re not “in a request context”. Our C functions were previously checking to see if we had a scope, because scope was tacked on to a request context – so “we have a scope, therefore, we have a request context.” We’ve decoupled scopes from request contexts, so now it checks “do we have a request context.” RUBY-290 should remove all of that, including this method.

Returns:

  • (Boolean)


108
109
110
# File 'lib/contrast/components/scope.rb', line 108

def in_request_context?
  !!Contrast::Agent::REQUEST_TRACKER.current
end

#in_scope?(name) ⇒ Boolean

Returns:

  • (Boolean)


83
84
85
# File 'lib/contrast/components/scope.rb', line 83

def in_scope? name
  scope_for_current_ec.in_scope? name
end

#scope_for_current_ecObject

For each instance method on a scope, define a forwarder to the scope on the current execution context’s scope.



45
46
47
48
49
# File 'lib/contrast/components/scope.rb', line 45

def scope_for_current_ec
  MONITOR.synchronize do
    return EXECUTION_CONTEXT[Fiber.current] ||= Contrast::Agent::Scope.new
  end
end

#with_contrast_scopeObject



87
88
89
90
91
92
# File 'lib/contrast/components/scope.rb', line 87

def with_contrast_scope
  scope_for_current_ec.enter_contrast_scope!
  yield
ensure
  scope_for_current_ec.exit_contrast_scope!
end

#with_deserialization_scopeObject



94
95
96
97
98
# File 'lib/contrast/components/scope.rb', line 94

def with_deserialization_scope
  scope_for_current_ec.enter_deserialization_scope!
ensure
  scope_for_current_ec.exit_deserialization_scope!
end