Class: Contrast::Agent::Patching::Policy::ModulePolicy
- Defined in:
- lib/contrast/agent/patching/policy/module_policy.rb
Overview
This class is used to map a class to all policy nodes utilizing that class. It should be initialized using the create_module_policy method rather than new.
Instance Attribute Summary collapse
-
#deadzone_nodes ⇒ Object
Returns the value of attribute deadzone_nodes.
-
#inventory_nodes ⇒ Object
Returns the value of attribute inventory_nodes.
-
#propagator_nodes ⇒ Object
Returns the value of attribute propagator_nodes.
-
#protect_nodes ⇒ Object
Returns the value of attribute protect_nodes.
-
#source_nodes ⇒ Object
Returns the value of attribute source_nodes.
-
#trigger_nodes ⇒ Object
Returns the value of attribute trigger_nodes.
Class Method Summary collapse
-
.create_module_policy(module_name) ⇒ Contrast::Agent::Patching::Policy::ModulePolicy
Given the name of a module, create a :ModulePolicy for it using the Policy of each supported feature.
-
.nodes_for_module(nodes, class_name) ⇒ Array<Contrast::Agent::Patching::Policy::PolicyNode>
Find any of the given patchers that match this class’ names.
Instance Method Summary collapse
- #empty? ⇒ Boolean
-
#num_expected_patches ⇒ Integer
The number of expected patches for this policy is the sum of unique targeted methods for the Module to which this policy applies.
Instance Attribute Details
#deadzone_nodes ⇒ Object
Returns the value of attribute deadzone_nodes.
49 50 51 |
# File 'lib/contrast/agent/patching/policy/module_policy.rb', line 49 def deadzone_nodes @deadzone_nodes end |
#inventory_nodes ⇒ Object
Returns the value of attribute inventory_nodes.
49 50 51 |
# File 'lib/contrast/agent/patching/policy/module_policy.rb', line 49 def inventory_nodes @inventory_nodes end |
#propagator_nodes ⇒ Object
Returns the value of attribute propagator_nodes.
49 50 51 |
# File 'lib/contrast/agent/patching/policy/module_policy.rb', line 49 def propagator_nodes @propagator_nodes end |
#protect_nodes ⇒ Object
Returns the value of attribute protect_nodes.
49 50 51 |
# File 'lib/contrast/agent/patching/policy/module_policy.rb', line 49 def protect_nodes @protect_nodes end |
#source_nodes ⇒ Object
Returns the value of attribute source_nodes.
49 50 51 |
# File 'lib/contrast/agent/patching/policy/module_policy.rb', line 49 def source_nodes @source_nodes end |
#trigger_nodes ⇒ Object
Returns the value of attribute trigger_nodes.
49 50 51 |
# File 'lib/contrast/agent/patching/policy/module_policy.rb', line 49 def trigger_nodes @trigger_nodes end |
Class Method Details
.create_module_policy(module_name) ⇒ Contrast::Agent::Patching::Policy::ModulePolicy
Given the name of a module, create a :ModulePolicy for it using the Policy of each supported feature.
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/contrast/agent/patching/policy/module_policy.rb', line 19 def create_module_policy module_name module_policy = Contrast::Agent::Patching::Policy::ModulePolicy.new module_policy.source_nodes = nodes_for_module( Contrast::Agent::Assess::Policy::Policy.instance.sources, module_name) module_policy.propagator_nodes = nodes_for_module( Contrast::Agent::Assess::Policy::Policy.instance.propagators, module_name) module_policy.trigger_nodes = nodes_for_module( Contrast::Agent::Assess::Policy::Policy.instance.triggers, module_name) module_policy.protect_nodes = nodes_for_module( Contrast::Agent::Protect::Policy::Policy.instance.triggers, module_name) module_policy.inventory_nodes = nodes_for_module( Contrast::Agent::Inventory::Policy::Policy.instance.triggers, module_name) module_policy.deadzone_nodes = nodes_for_module( Contrast::Agent::Deadzone::Policy::Policy.instance.deadzones, module_name) module_policy end |
.nodes_for_module(nodes, class_name) ⇒ Array<Contrast::Agent::Patching::Policy::PolicyNode>
Find any of the given patchers that match this class’ names. Always returns an array, even if it’s empty.
44 45 46 |
# File 'lib/contrast/agent/patching/policy/module_policy.rb', line 44 def nodes_for_module nodes, class_name nodes.select { |node| class_name == node.class_name } end |
Instance Method Details
#empty? ⇒ Boolean
52 53 54 55 56 57 58 59 60 61 |
# File 'lib/contrast/agent/patching/policy/module_policy.rb', line 52 def empty? return false if source_nodes.any? return false if propagator_nodes.any? return false if trigger_nodes.any? return false if inventory_nodes.any? return false if protect_nodes.any? return false if deadzone_nodes.any? true end |
#num_expected_patches ⇒ Integer
The number of expected patches for this policy is the sum of unique targeted methods for the Module to which this policy applies.
67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/contrast/agent/patching/policy/module_policy.rb', line 67 def num_expected_patches @_num_expected_patches ||= begin instance_methods = Set.new singleton_methods = Set.new sort_method_names(source_nodes, instance_methods, singleton_methods) sort_method_names(propagator_nodes, instance_methods, singleton_methods) sort_method_names(trigger_nodes, instance_methods, singleton_methods) sort_method_names(inventory_nodes, instance_methods, singleton_methods) sort_method_names(protect_nodes, instance_methods, singleton_methods) sort_method_names(deadzone_nodes, instance_methods, singleton_methods) instance_methods.length + singleton_methods.length end end |