Class: Contrast::Agent::Patching::Policy::PolicyNode Abstract

Inherits:
Object
  • Object
show all
Includes:
Components::Interface
Defined in:
lib/contrast/agent/patching/policy/policy_node.rb

Overview

This class is abstract.

This class functions to translate our policy.json into an actionable Ruby object, allowing for dynamic patching over hardcoded patching.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Components::Interface

included

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_nameObject

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_methodObject

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_nameObject

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_scopeObject (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_visibilityObject

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

#propertiesObject (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

#featureObject

Raises:

  • (NoMethodError)


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

#idObject



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

Returns:

  • (Boolean)


59
60
61
# File 'lib/contrast/agent/patching/policy/policy_node.rb', line 59

def instance_method?
  instance_method
end

#node_classObject

Raises:

  • (NoMethodError)


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

#validateObject

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.

Raises:

  • (ArgumentError)


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