Class: Contrast::Agent::Patching::Policy::MethodPolicy

Inherits:
Object
  • Object
show all
Extended by:
MethodPolicyExtend
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

Instance Method Summary collapse

Methods included from MethodPolicyExtend

build_method_policy, check_method_policy_nodes_empty?, find_method_node, find_visibility

Constructor Details

#initialize(method_policy) ⇒ MethodPolicy

Initialize new method policy with:

Parameters:

  • method_policy (Hash)

    source_node       [ Contrast::Agent::Assess::Policy::SourceNode      ]
    propagation_node  [ Contrast::Agent::Assess::Policy::PropagationNode ]
    trigger_node      [ Contrast::Agent::Assess::Policy::TriggerNode     ]
    inventory_node    [ Contrast::Agent::Inventory::Policy::TriggerNode   ]
    protect_node      [ Contrast::Agent::Protect::Policy::TriggerNode     ]
    deadzone_node     [ Contrast::Agent::Deadzone::Policy::DeadzoneNode   ]
    method_name       [ Symbol                                            ]
                        the name of the method for this policy
    method_visibility [ Symbol                                            ]
                        Public, Private Protected
    instance_method   [ Boolean                                           ]
                        true if this method is an instance method
    



33
34
35
36
37
38
39
40
41
42
43
# File 'lib/contrast/agent/patching/policy/method_policy.rb', line 33

def initialize method_policy
  @method_name = method_policy[:method_name]
  @method_visibility = method_policy[:method_visibility]
  @instance_method = method_policy[:instance_method]
  @source_node = method_policy[:source_node]
  @propagation_node = method_policy[:propagation_node]
  @trigger_node = method_policy[:trigger_node]
  @inventory_node = method_policy[:inventory_node]
  @protect_node = method_policy[:protect_node]
  @deadzone_node = method_policy[:deadzone_node]
end

Instance Attribute Details

#deadzone_nodeObject (readonly)

Returns the value of attribute deadzone_node.



13
14
15
# File 'lib/contrast/agent/patching/policy/method_policy.rb', line 13

def deadzone_node
  @deadzone_node
end

#instance_methodObject

Returns the value of attribute instance_method.



14
15
16
# File 'lib/contrast/agent/patching/policy/method_policy.rb', line 14

def instance_method
  @instance_method
end

#inventory_nodeObject (readonly)

Returns the value of attribute inventory_node.



13
14
15
# File 'lib/contrast/agent/patching/policy/method_policy.rb', line 13

def inventory_node
  @inventory_node
end

#method_nameObject

Returns the value of attribute method_name.



14
15
16
# File 'lib/contrast/agent/patching/policy/method_policy.rb', line 14

def method_name
  @method_name
end

#method_visibilityObject

Returns the value of attribute method_visibility.



14
15
16
# File 'lib/contrast/agent/patching/policy/method_policy.rb', line 14

def method_visibility
  @method_visibility
end

#propagation_nodeObject (readonly)

Returns the value of attribute propagation_node.



13
14
15
# File 'lib/contrast/agent/patching/policy/method_policy.rb', line 13

def propagation_node
  @propagation_node
end

#protect_nodeObject (readonly)

Returns the value of attribute protect_node.



13
14
15
# File 'lib/contrast/agent/patching/policy/method_policy.rb', line 13

def protect_node
  @protect_node
end

#source_nodeObject

Returns the value of attribute source_node.



14
15
16
# File 'lib/contrast/agent/patching/policy/method_policy.rb', line 14

def source_node
  @source_node
end

#trigger_nodeObject (readonly)

Returns the value of attribute trigger_node.



13
14
15
# File 'lib/contrast/agent/patching/policy/method_policy.rb', line 13

def trigger_node
  @trigger_node
end

Instance Method Details

#empty?Boolean

Returns:

  • (Boolean)


49
50
51
# File 'lib/contrast/agent/patching/policy/method_policy.rb', line 49

def empty?
  nodes.none?
end

#private_method?Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/contrast/agent/patching/policy/method_policy.rb', line 45

def private_method?
  method_visibility == :private
end

#requires_custom_patch?Boolean

Returns:

  • (Boolean)


61
62
63
# File 'lib/contrast/agent/patching/policy/method_policy.rb', line 61

def requires_custom_patch?
  !!@trigger_node&.custom_patch?
end

#scopes_to_enterObject



53
54
55
# File 'lib/contrast/agent/patching/policy/method_policy.rb', line 53

def scopes_to_enter
  @_scopes_to_enter ||= method_scopes
end

#scopes_to_exitObject



57
58
59
# File 'lib/contrast/agent/patching/policy/method_policy.rb', line 57

def scopes_to_exit
  @_scopes_to_exit ||= method_scopes.reverse
end