Class: OFlow::Link

Inherits:
Object
  • Object
show all
Defined in:
lib/oflow/link.rb

Overview

A Link is the data needed to link one Task with another so that when the ship() method is called the data can be delivered to the destination Task.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(target_name, op, ingress = false) ⇒ Link

Creates a new Link. This is called from link() and route() methods on Tasks and Flows.

Parameters:

  • target_name (Symbol)

    target Task base name

  • op (Symbol)

    operation to use on the target

  • ingress (true|false) (defaults to: false)

    indicates the Link is internal



23
24
25
26
27
28
# File 'lib/oflow/link.rb', line 23

def initialize(target_name, op, ingress=false)
  @target_name = target_name
  @op = op
  @target = nil
  @ingress = ingress
end

Instance Attribute Details

#ingressObject (readonly)

Flag indicating the Link is from a Flow to a Task contained in the Flow.



15
16
17
# File 'lib/oflow/link.rb', line 15

def ingress
  @ingress
end

#opObject (readonly)

Operation to provide the target.



11
12
13
# File 'lib/oflow/link.rb', line 11

def op
  @op
end

#targetObject (readonly)

The actual target Task or Flow.



13
14
15
# File 'lib/oflow/link.rb', line 13

def target
  @target
end

#target_nameObject (readonly)

Name of the target.



9
10
11
# File 'lib/oflow/link.rb', line 9

def target_name
  @target_name
end

Instance Method Details

#ship(box) ⇒ Object

Delivers a package (Box) to the target.

Parameters:

  • box (Box)

    package to deliver



32
33
34
# File 'lib/oflow/link.rb', line 32

def ship(box)
  @target.receive(@op, box)
end

#to_sObject Also known as: inspect

Returns a string representation of the Link.



37
38
39
# File 'lib/oflow/link.rb', line 37

def to_s()
  "Link{ingress: #{@ingress}, target_name: #{@target_name}, op: #{op}, target: #{@target}}"
end