class Patch::Node::Map

A map of connections between nodes for a given patch

Attributes

from[R]
to[R]

Public Class Methods

new(from, to) click to toggle source

@param [Array<Object>, NodeContainer, Object] from @param [Array<Object>, NodeContainer, Object] to

# File lib/patch/node/map.rb, line 12
def initialize(from, to)
  @from = to_node_container(from)
  @to = to_node_container(to)
end

Public Instance Methods

disable(patch) click to toggle source

Disable the map for the given patch context @return [Boolean]

# File lib/patch/node/map.rb, line 19
def disable(patch)
  result = @to.map do |to_node|
    disabled = @from.map do |from_node|
      from_node.disable(patch)
      true
    end
    disabled.any?
  end
  result.any?
end
enable(patch) click to toggle source

Enable this map for the given nodes @param [::Patch::Patch] patch The patch context to enable the map in @return [Boolean] Whether nodes were enabled

# File lib/patch/node/map.rb, line 33
def enable(patch)
  result = @to.map do |to_node|
    to_node.puts(patch, patch.default_messages)
    enabled = @from.map do |from_node|
      from_node.listen(patch) do |messages|
        to_node.puts(patch, messages)
      end
      true
    end
    enabled.any?
  end
  result.flatten.any?
end
nodes() click to toggle source

The nodes for this map, collected @return [NodeContainer]

# File lib/patch/node/map.rb, line 49
def nodes
  @from | @to
end

Private Instance Methods

to_node_container(object) click to toggle source

Convert the given arg to a node container @param [Object] object @return [NodeContainer]

# File lib/patch/node/map.rb, line 58
def to_node_container(object)
  if !object.kind_of?(Array) || !object.kind_of?(Node::Container)
    object = [object].flatten.compact
  end
  if object.kind_of?(Array)
    object = Node::Container.new(object)
  end
  object
end