Class: RedShift::Component::Port

Inherits:
Object
  • Object
show all
Defined in:
lib/redshift/port.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(component, variable, connectable) ⇒ Port

Returns a new instance of Port.



5
6
7
# File 'lib/redshift/port.rb', line 5

def initialize component, variable, connectable
  @component, @variable, @connectable = component, variable, connectable
end

Instance Attribute Details

#componentObject (readonly)

Returns the value of attribute component.



3
4
5
# File 'lib/redshift/port.rb', line 3

def component
  @component
end

#connectableObject (readonly)

Returns the value of attribute connectable.



3
4
5
# File 'lib/redshift/port.rb', line 3

def connectable
  @connectable
end

#variableObject (readonly)

Returns the value of attribute variable.



3
4
5
# File 'lib/redshift/port.rb', line 3

def variable
  @variable
end

Instance Method Details

#<<(other) ⇒ Object



29
30
31
32
# File 'lib/redshift/port.rb', line 29

def <<(other)
  connect(other)
  return other
end

#>>(other) ⇒ Object



34
35
36
37
# File 'lib/redshift/port.rb', line 34

def >>(other)
  other.connect(self)
  return other
end

#_connect(port) ⇒ Object



25
26
27
# File 'lib/redshift/port.rb', line 25

def _connect port
  component.connect(variable, port && port.component, port && port.variable, false)
end

#check_connectableObject



14
15
16
17
18
# File 'lib/redshift/port.rb', line 14

def check_connectable
  unless connectable
    raise TypeError, "Not an input: #{variable} in #{component.class}"
  end
end

#connect(port) ⇒ Object



20
21
22
23
# File 'lib/redshift/port.rb', line 20

def connect port
  check_connectable
  component.connect(variable, port && port.component, port && port.variable)
end

#disconnectObject



39
40
41
# File 'lib/redshift/port.rb', line 39

def disconnect
  connect nil
end

#sourceObject

Convenience method to get source port rather than component/var pair.



10
11
12
# File 'lib/redshift/port.rb', line 10

def source
  source_component && source_component.port(source_variable)
end

#source_componentObject



43
44
45
46
# File 'lib/redshift/port.rb', line 43

def source_component
  check_connectable
  component.source_component_for(variable)
end

#source_variableObject



48
49
50
51
# File 'lib/redshift/port.rb', line 48

def source_variable
  check_connectable
  component.source_variable_for(variable)
end

#valueObject



53
54
55
# File 'lib/redshift/port.rb', line 53

def value
  component.send variable
end