Class: Contrast::Agent::Patching::Policy::PatchStatus

Inherits:
Object
  • Object
show all
Defined in:
lib/contrast/agent/patching/policy/patch_status.rb,
ext/cs__contrast_patch/cs__contrast_patch.c

Overview

This indicates the status of the Module into which Contrast is being woven

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#patch_statusObject (readonly)

Returns the value of attribute patch_status.



135
136
137
# File 'lib/contrast/agent/patching/policy/patch_status.rb', line 135

def patch_status
  @patch_status
end

Class Method Details

.get_status(mod) ⇒ Contrast::Agent::Patching::Policy::PatchStatus

Gives the current status for the provided module, setting one if one does not exist.

Parameters:

  • mod (Module)

    the Module for which the status is asked

Returns:



17
18
19
20
21
# File 'lib/contrast/agent/patching/policy/patch_status.rb', line 17

def get_status mod
  return mod.cs__const_get(status_key) if mod.cs__const_defined?(status_key, false)

  mod.cs__const_set(status_key, new)
end

.info_for(mod, method, is_instance_method) ⇒ Contrast::Agent::Patching::Policy::MethodPolicy

Allows our C patches to look up the :MethodPolicy for a given Module and method

Parameters:

  • mod (Module or Class)

    the entity on which the patch has been placed

  • method (Symbol)

    the name of the method to which the patch applies

  • is_instance_method (Boolean)

    is the method being patched an instance method or not (not implying class method).

Returns:



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/contrast/agent/patching/policy/patch_status.rb', line 33

def info_for mod, method, is_instance_method
  mod = mod.cs__class unless mod.cs__is_a?(Module)
  method_key = method_name_key(method, is_instance_method)
  # Ideally, we'll get to a point where this is all that is needed
  ret = find_info_for_one(mod, method_key)
  return ret if ret

  # But to start, the lookup will be on the ancestor, not the
  # calling class. We need to traverse the ancestors, included
  # modules, and Module itself the first time a method is called in
  # a given class. Then we save that lookup to the class
  ret = find_info_for(mod.ancestors, method_key)
  ret ||= find_info_for(mod.cs__singleton_class.included_modules, method_key)
  ret ||= find_info_for(MOD_ARRAY, method_key)
  update_holder(mod, method_key, ret) if ret
  ret
end

.set_info_for(mod, method, method_policy, is_instance_method, cs_method) ⇒ Object

Allows our C patches to set the :MethodPolicy for a given Module and method

Parameters:

  • mod (Module or Class)

    the entity on which the patch will be placed

  • method (Symbol)

    the name of the method to which the patch applies

  • method_policy (:MethodPolicy)

    the policy that applies to the given mod & method

  • is_instance_method (Boolean)

    is the method being patched an instance method or not (not implying class method).

  • cs_method (Symbol)

    the name to which the original method was aliased, cached for performance reasons



64
65
66
67
68
69
70
71
# File 'lib/contrast/agent/patching/policy/patch_status.rb', line 64

def set_info_for mod, method, method_policy, is_instance_method, cs_method
  mod.instance_variable_set(method_info_key, {}) unless mod.instance_variable_defined?(method_info_key)
  holder = mod.instance_variable_get(method_info_key)
  # if we already have this information, then we don't need to set it as we'll update the info on access
  return if holder.key?(method)

  holder[method_name_key(method, is_instance_method)] = [method_policy, cs_method]
end

Instance Method Details

#failed_patch!Object



153
154
155
# File 'lib/contrast/agent/patching/policy/patch_status.rb', line 153

def failed_patch!
  @patch_status = :FAILED
end

#no_patch!Object



145
146
147
# File 'lib/contrast/agent/patching/policy/patch_status.rb', line 145

def no_patch!
  @patch_status = :NONE
end

#partial_patch!Object



141
142
143
# File 'lib/contrast/agent/patching/policy/patch_status.rb', line 141

def partial_patch!
  @patch_status = :PARTIAL
end

#patched!Object



149
150
151
# File 'lib/contrast/agent/patching/policy/patch_status.rb', line 149

def patched!
  @patch_status = :PATCHED
end

#patched?Boolean

Returns:

  • (Boolean)


161
162
163
# File 'lib/contrast/agent/patching/policy/patch_status.rb', line 161

def patched?
  @patch_status == :PATCHED || @patch_status == :NONE || @patch_status == :FAILED
end

#patching!Object



137
138
139
# File 'lib/contrast/agent/patching/policy/patch_status.rb', line 137

def patching!
  @patch_status = :PATCHING
end

#patching?Boolean

Returns:

  • (Boolean)


157
158
159
# File 'lib/contrast/agent/patching/policy/patch_status.rb', line 157

def patching?
  @patch_status == :PATCHING
end