Class: Contrast::Agent::Patching::Policy::PolicyNode Abstract
- Includes:
- Components::Interface
- Defined in:
- lib/contrast/agent/patching/policy/policy_node.rb
Overview
This class functions to translate our policy.json into an actionable Ruby object, allowing for dynamic patching over hardcoded patching.
Direct Known Subclasses
Assess::Policy::PolicyNode, Deadzone::Policy::DeadzoneNode, TriggerNode
Instance Attribute Summary collapse
-
#class_name ⇒ Object
Returns the value of attribute class_name.
-
#instance_method ⇒ Object
Returns the value of attribute instance_method.
-
#method_name ⇒ Object
Returns the value of attribute method_name.
-
#method_scope ⇒ Object
readonly
Returns the value of attribute method_scope.
-
#method_visibility ⇒ Object
Returns the value of attribute method_visibility.
-
#properties ⇒ Object
readonly
Returns the value of attribute properties.
Instance Method Summary collapse
- #feature ⇒ Object
- #id ⇒ Object
-
#initialize(policy_hash = {}) ⇒ PolicyNode
constructor
A new instance of PolicyNode.
-
#instance_method? ⇒ Boolean
just turns this into a ruby-ism.
- #node_class ⇒ Object
-
#validate ⇒ Object
Don’t let nodes be created that will be missing things we need later on.
Methods included from Components::Interface
Constructor Details
#initialize(policy_hash = {}) ⇒ PolicyNode
Returns a new instance of PolicyNode.
29 30 31 32 33 34 35 36 37 |
# File 'lib/contrast/agent/patching/policy/policy_node.rb', line 29 def initialize policy_hash = {} @class_name = policy_hash[JSON_CLASS_NAME] @instance_method = policy_hash[JSON_INSTANCE_METHOD] @method_name = policy_hash[JSON_METHOD_NAME] @method_scope = policy_hash[JSON_METHOD_SCOPE] @method_visibility = policy_hash[JSON_METHOD_VISIBILITY] @properties = policy_hash[JSON_PROPERTIES] symbolize end |
Instance Attribute Details
#class_name ⇒ Object
Returns the value of attribute class_name.
18 19 20 |
# File 'lib/contrast/agent/patching/policy/policy_node.rb', line 18 def class_name @class_name end |
#instance_method ⇒ Object
Returns the value of attribute instance_method.
18 19 20 |
# File 'lib/contrast/agent/patching/policy/policy_node.rb', line 18 def instance_method @instance_method end |
#method_name ⇒ Object
Returns the value of attribute method_name.
18 19 20 |
# File 'lib/contrast/agent/patching/policy/policy_node.rb', line 18 def method_name @method_name end |
#method_scope ⇒ Object (readonly)
Returns the value of attribute method_scope.
19 20 21 |
# File 'lib/contrast/agent/patching/policy/policy_node.rb', line 19 def method_scope @method_scope end |
#method_visibility ⇒ Object
Returns the value of attribute method_visibility.
18 19 20 |
# File 'lib/contrast/agent/patching/policy/policy_node.rb', line 18 def method_visibility @method_visibility end |
#properties ⇒ Object (readonly)
Returns the value of attribute properties.
19 20 21 |
# File 'lib/contrast/agent/patching/policy/policy_node.rb', line 19 def properties @properties end |
Instance Method Details
#feature ⇒ Object
25 26 27 |
# File 'lib/contrast/agent/patching/policy/policy_node.rb', line 25 def feature raise NoMethodError, 'specify the name of the feature for which this node patches' end |
#id ⇒ Object
39 40 41 |
# File 'lib/contrast/agent/patching/policy/policy_node.rb', line 39 def id @_id ||= "#{ feature }:#{ node_class }:#{ class_name }#{ instance_method? ? '#' : '.' }#{ method_name }" end |
#instance_method? ⇒ Boolean
just turns this into a ruby-ism
59 60 61 |
# File 'lib/contrast/agent/patching/policy/policy_node.rb', line 59 def instance_method? instance_method end |
#node_class ⇒ Object
21 22 23 |
# File 'lib/contrast/agent/patching/policy/policy_node.rb', line 21 def node_class raise NoMethodError, 'specify the type of the feature for which this node patches' end |
#validate ⇒ Object
Don’t let nodes be created that will be missing things we need later on. Really, if they don’t have these things, they couldn’t have done their jobs anyway.
46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/contrast/agent/patching/policy/policy_node.rb', line 46 def validate raise(ArgumentError, "#{ node_class } #{ id } did not have a proper class name. Unable to create.") unless class_name raise(ArgumentError, "#{ node_class } #{ id } did not have a proper method name. Unable to create.") unless method_name raise(ArgumentError, "#{ node_class } #{ id } has a non symbol @method_name value. Unable to create.") unless method_name.is_a?(Symbol) raise(ArgumentError, "#{ node_class } #{ id } has a non symbol @method_visibility value. Unable to create.") unless method_visibility.is_a?(Symbol) unless method_scope.nil? || Contrast::Agent::Scope.valid_scope?(method_scope) raise(ArgumentError, "#{ node_class } #{ id } requires an undefined scope. Unable to create.") end nil end |