Module: Contrast::CommonAgentConfiguration::IsANode

Included in:
Contrast::CommonAgentConfiguration, Node
Defined in:
lib/contrast/common_agent_configuration.rb

Overview

Used to indicate those sections of the configuration which have references to other nodes or properties, allowing for the parsing of and access to the nested configuration structure.

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object



46
47
48
49
50
51
52
53
54
# File 'lib/contrast/common_agent_configuration.rb', line 46

def method_missing method, *args, &block
  if args.any?
    lookup(method.to_s).public_send(args, block)
  else
    lookup(method.to_s)
  end
rescue IndexError
  super(method, args, block)
end

Instance Method Details

#childrenObject



23
24
25
# File 'lib/contrast/common_agent_configuration.rb', line 23

def children
  hsh[NODES]&.map { |raw_node| Node.new(raw_node) } || []
end

#lookup(*path) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/contrast/common_agent_configuration.rb', line 31

def lookup *path
  # Path will be N args, representing a path of nodes.
  path.reduce(self) do |node, next_arg|
    # If we can travel to a node by that name, do that.
    candidate_node = node.children.find { |n| n.name == next_arg }
    next candidate_node if candidate_node

    # If there's a property, dereference that.
    candidate_property = node.properties.find { |n| n.name == next_arg }
    next candidate_property if candidate_property

    raise IndexError, "couldn't traverse path:\t#{ path.join(Contrast::Utils::ObjectShare::PERIOD) }"
  end
end

#propertiesObject



27
28
29
# File 'lib/contrast/common_agent_configuration.rb', line 27

def properties
  hsh[PROPERTIES].map { |raw_property| Property.new(raw_property) }
end