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.
45 46 47 |
# File 'lib/contrast/agent/patching/policy/module_policy.rb', line 45 def deadzone_nodes @deadzone_nodes end |
#inventory_nodes ⇒ Object
Returns the value of attribute inventory_nodes.
45 46 47 |
# File 'lib/contrast/agent/patching/policy/module_policy.rb', line 45 def inventory_nodes @inventory_nodes end |
#propagator_nodes ⇒ Object
Returns the value of attribute propagator_nodes.
45 46 47 |
# File 'lib/contrast/agent/patching/policy/module_policy.rb', line 45 def propagator_nodes @propagator_nodes end |
#protect_nodes ⇒ Object
Returns the value of attribute protect_nodes.
45 46 47 |
# File 'lib/contrast/agent/patching/policy/module_policy.rb', line 45 def protect_nodes @protect_nodes end |
#source_nodes ⇒ Object
Returns the value of attribute source_nodes.
45 46 47 |
# File 'lib/contrast/agent/patching/policy/module_policy.rb', line 45 def source_nodes @source_nodes end |
#trigger_nodes ⇒ Object
Returns the value of attribute trigger_nodes.
45 46 47 |
# File 'lib/contrast/agent/patching/policy/module_policy.rb', line 45 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
21 22 23 24 25 26 27 28 29 30 |
# File 'lib/contrast/agent/patching/policy/module_policy.rb', line 21 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.
40 41 42 |
# File 'lib/contrast/agent/patching/policy/module_policy.rb', line 40 def nodes_for_module nodes, class_name nodes.select { |node| class_name == node.class_name } end |
Instance Method Details
#empty? ⇒ Boolean
47 48 49 50 51 52 53 54 55 56 |
# File 'lib/contrast/agent/patching/policy/module_policy.rb', line 47 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.
62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/contrast/agent/patching/policy/module_policy.rb', line 62 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 |