Class: Patch::Node::Map

Inherits:
Object
  • Object
show all
Defined in:
lib/patch/node/map.rb

Overview

A map of connections between nodes for a given patch

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(from, to) ⇒ Map

Returns a new instance of Map.

Parameters:

  • from (Array<Object>, NodeContainer, Object)
  • to (Array<Object>, NodeContainer, Object)


12
13
14
15
# File 'lib/patch/node/map.rb', line 12

def initialize(from, to)
  @from = to_node_container(from)
  @to = to_node_container(to)
end

Instance Attribute Details

#fromObject (readonly)

Returns the value of attribute from.



8
9
10
# File 'lib/patch/node/map.rb', line 8

def from
  @from
end

#toObject (readonly)

Returns the value of attribute to.



8
9
10
# File 'lib/patch/node/map.rb', line 8

def to
  @to
end

Instance Method Details

#disable(patch) ⇒ Boolean

Disable the map for the given patch context

Returns:

  • (Boolean)


19
20
21
22
23
24
25
26
27
28
# 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) ⇒ Boolean

Enable this map for the given nodes

Parameters:

Returns:

  • (Boolean)

    Whether nodes were enabled



33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/patch/node/map.rb', line 33

def enable(patch)
  result = @to.map do |to_node|
    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

#nodesNodeContainer

The nodes for this map, collected

Returns:

  • (NodeContainer)


48
49
50
# File 'lib/patch/node/map.rb', line 48

def nodes
  @from | @to
end