Class: Contrast::Agent::Patching::Policy::MethodPolicy
- Defined in:
- lib/contrast/agent/patching/policy/method_policy.rb
Overview
This class is used to map each method to the trigger node that applies to it
Instance Attribute Summary collapse
-
#deadzone_node ⇒ Object
readonly
Returns the value of attribute deadzone_node.
-
#instance_method ⇒ Object
Returns the value of attribute instance_method.
-
#inventory_node ⇒ Object
readonly
Returns the value of attribute inventory_node.
-
#method_name ⇒ Object
Returns the value of attribute method_name.
-
#method_visibility ⇒ Object
Returns the value of attribute method_visibility.
-
#propagation_node ⇒ Object
readonly
Returns the value of attribute propagation_node.
-
#protect_node ⇒ Object
readonly
Returns the value of attribute protect_node.
-
#source_node ⇒ Object
Returns the value of attribute source_node.
-
#trigger_node ⇒ Object
readonly
Returns the value of attribute trigger_node.
Class Method Summary collapse
-
.build_method_policy(method_name, module_policy, instance_method) ⇒ Contrast::Agent::Patching::Policy::MethodPolicy
Given a Contrast::Agent::Patching::Policy::ModulePolicy, parse out its information for the given method in order to construct a Contrast::Agent::Patching::Policy::MethodPolicy.
- .find_method_node(nodes, method_name, is_instance_method) ⇒ Object
- .find_visibility(*nodes) ⇒ Object
Instance Method Summary collapse
- #empty? ⇒ Boolean
-
#initialize(source_node: nil, propagation_node: nil, trigger_node: nil, inventory_node: nil, protect_node: nil, deadzone_node: nil, method_name: nil, method_visibility: nil, instance_method: nil) ⇒ MethodPolicy
constructor
A new instance of MethodPolicy.
- #private_method? ⇒ Boolean
- #requires_custom_patch? ⇒ Boolean
- #scopes_to_enter ⇒ Object
- #scopes_to_exit ⇒ Object
Constructor Details
#initialize(source_node: nil, propagation_node: nil, trigger_node: nil, inventory_node: nil, protect_node: nil, deadzone_node: nil, method_name: nil, method_visibility: nil, instance_method: nil) ⇒ MethodPolicy
Returns a new instance of MethodPolicy.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/contrast/agent/patching/policy/method_policy.rb', line 13 def initialize(source_node: nil, propagation_node: nil, trigger_node: nil, inventory_node: nil, protect_node: nil, deadzone_node: nil, method_name: nil, method_visibility: nil, instance_method: nil) @method_name = method_name @method_visibility = method_visibility @instance_method = instance_method @source_node = source_node @propagation_node = propagation_node @trigger_node = trigger_node @inventory_node = inventory_node @protect_node = protect_node @deadzone_node = deadzone_node end |
Instance Attribute Details
#deadzone_node ⇒ Object (readonly)
Returns the value of attribute deadzone_node.
10 11 12 |
# File 'lib/contrast/agent/patching/policy/method_policy.rb', line 10 def deadzone_node @deadzone_node end |
#instance_method ⇒ Object
Returns the value of attribute instance_method.
11 12 13 |
# File 'lib/contrast/agent/patching/policy/method_policy.rb', line 11 def instance_method @instance_method end |
#inventory_node ⇒ Object (readonly)
Returns the value of attribute inventory_node.
10 11 12 |
# File 'lib/contrast/agent/patching/policy/method_policy.rb', line 10 def inventory_node @inventory_node end |
#method_name ⇒ Object
Returns the value of attribute method_name.
11 12 13 |
# File 'lib/contrast/agent/patching/policy/method_policy.rb', line 11 def method_name @method_name end |
#method_visibility ⇒ Object
Returns the value of attribute method_visibility.
11 12 13 |
# File 'lib/contrast/agent/patching/policy/method_policy.rb', line 11 def method_visibility @method_visibility end |
#propagation_node ⇒ Object (readonly)
Returns the value of attribute propagation_node.
10 11 12 |
# File 'lib/contrast/agent/patching/policy/method_policy.rb', line 10 def propagation_node @propagation_node end |
#protect_node ⇒ Object (readonly)
Returns the value of attribute protect_node.
10 11 12 |
# File 'lib/contrast/agent/patching/policy/method_policy.rb', line 10 def protect_node @protect_node end |
#source_node ⇒ Object
Returns the value of attribute source_node.
11 12 13 |
# File 'lib/contrast/agent/patching/policy/method_policy.rb', line 11 def source_node @source_node end |
#trigger_node ⇒ Object (readonly)
Returns the value of attribute trigger_node.
10 11 12 |
# File 'lib/contrast/agent/patching/policy/method_policy.rb', line 10 def trigger_node @trigger_node end |
Class Method Details
.build_method_policy(method_name, module_policy, instance_method) ⇒ Contrast::Agent::Patching::Policy::MethodPolicy
Given a Contrast::Agent::Patching::Policy::ModulePolicy, parse out its information for the given method in order to construct a Contrast::Agent::Patching::Policy::MethodPolicy
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/contrast/agent/patching/policy/method_policy.rb', line 72 def build_method_policy method_name, module_policy, instance_method source_node = find_method_node(module_policy.source_nodes, method_name, instance_method) propagation_node = find_method_node(module_policy.propagator_nodes, method_name, instance_method) trigger_node = find_method_node(module_policy.trigger_nodes, method_name, instance_method) protect_node = find_method_node(module_policy.protect_nodes, method_name, instance_method) inventory_node = find_method_node(module_policy.inventory_nodes, method_name, instance_method) deadzone_node = find_method_node(module_policy.deadzone_nodes, method_name, instance_method) method_visibility = find_visibility(source_node, propagation_node, trigger_node, protect_node, inventory_node, deadzone_node) MethodPolicy.new(method_name: method_name, method_visibility: method_visibility, instance_method: instance_method, source_node: source_node, propagation_node: propagation_node, trigger_node: trigger_node, protect_node: protect_node, inventory_node: inventory_node, deadzone_node: deadzone_node) end |
.find_method_node(nodes, method_name, is_instance_method) ⇒ Object
91 92 93 94 95 96 97 |
# File 'lib/contrast/agent/patching/policy/method_policy.rb', line 91 def find_method_node nodes, method_name, is_instance_method return nil unless nodes nodes.find do |node| node.instance_method? == is_instance_method && node.method_name == method_name end end |
.find_visibility(*nodes) ⇒ Object
99 100 101 |
# File 'lib/contrast/agent/patching/policy/method_policy.rb', line 99 def find_visibility *nodes nodes.find { |node| node }&.method_visibility end |
Instance Method Details
#empty? ⇒ Boolean
33 34 35 |
# File 'lib/contrast/agent/patching/policy/method_policy.rb', line 33 def empty? nodes.none? end |
#private_method? ⇒ Boolean
29 30 31 |
# File 'lib/contrast/agent/patching/policy/method_policy.rb', line 29 def private_method? method_visibility == :private end |
#requires_custom_patch? ⇒ Boolean
45 46 47 |
# File 'lib/contrast/agent/patching/policy/method_policy.rb', line 45 def requires_custom_patch? !!@trigger_node&.custom_patch? end |
#scopes_to_enter ⇒ Object
37 38 39 |
# File 'lib/contrast/agent/patching/policy/method_policy.rb', line 37 def scopes_to_enter @_scopes_to_enter ||= method_scopes end |
#scopes_to_exit ⇒ Object
41 42 43 |
# File 'lib/contrast/agent/patching/policy/method_policy.rb', line 41 def scopes_to_exit @_scopes_to_exit ||= method_scopes.reverse end |