Class: SPNet::Link
- Inherits:
-
Object
- Object
- SPNet::Link
- Includes:
- Hashmake::HashMakeable
- Defined in:
- lib/spnet/core/link.rb
Overview
Form a connection between an OutPort and an InPort.
Constant Summary collapse
- ARG_SPECS =
Define arg specs to use in processing hashed arguments during #initialize.
{ :from => arg_spec(:reqd => true, :type => OutPort), :to => arg_spec(:reqd => true, :type => InPort) }
Instance Attribute Summary collapse
-
#from ⇒ Object
readonly
Returns the value of attribute from.
-
#to ⇒ Object
readonly
Returns the value of attribute to.
Instance Method Summary collapse
-
#activate ⇒ Object
Make the link active by setting from.link and to.link to self.
-
#active? ⇒ Boolean
Return true if the link is active (from.link and to.link are set to to self).
-
#deactivate ⇒ Object
Make the link inactive by setting from.link and to.link to nil.
-
#initialize(args = {}) ⇒ Link
constructor
A new instance of Link.
-
#save_state(blocks) ⇒ Object
Produce a LinkState object from the current Link object.
Constructor Details
#initialize(args = {}) ⇒ Link
A new instance of Link. Link is not active by default (does not set from.link and to.link to self).
21 22 23 24 25 26 |
# File 'lib/spnet/core/link.rb', line 21 def initialize args = {} hash_make args, Link::ARG_SPECS raise ArgumentError, "from port class #{@from.class} is not a #{@to.matching_class}" unless @from.is_a?(@to.matching_class) raise ArgumentError, "to port class #{@to.class} is not a #{@from.matching_class}" unless @to.is_a?(@from.matching_class) end |
Instance Attribute Details
#from ⇒ Object (readonly)
Returns the value of attribute from.
15 16 17 |
# File 'lib/spnet/core/link.rb', line 15 def from @from end |
#to ⇒ Object (readonly)
Returns the value of attribute to.
15 16 17 |
# File 'lib/spnet/core/link.rb', line 15 def to @to end |
Instance Method Details
#activate ⇒ Object
Make the link active by setting from.link and to.link to self.
29 30 31 32 |
# File 'lib/spnet/core/link.rb', line 29 def activate @from.set_link self @to.set_link self end |
#active? ⇒ Boolean
Return true if the link is active (from.link and to.link are set to to self).
41 42 43 |
# File 'lib/spnet/core/link.rb', line 41 def active? (@from.link == self) && (@to.link == self) end |
#deactivate ⇒ Object
Make the link inactive by setting from.link and to.link to nil.
35 36 37 38 |
# File 'lib/spnet/core/link.rb', line 35 def deactivate @from.clear_link @to.clear_link end |
#save_state(blocks) ⇒ Object
Produce a LinkState object from the current Link object.
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/spnet/core/link.rb', line 46 def save_state blocks from, to = nil, nil blocks.each do |block_name, block| block.out_ports.each do |port_name, port| if port == @from from = PortLocater.new(:block_name => block_name, :port_name => port_name) break end end block.in_ports.each do |port_name, port| if port == @to to = PortLocater.new(:block_name => block_name, :port_name => port_name) break end end end raise "could not find from port" if from.nil? raise "could not find to port" if to.nil? return LinkState.new(:from => from, :to => to) end |