Module: OFlow::HasLinks

Included in:
Flow, Task
Defined in:
lib/oflow/haslinks.rb

Overview

Adds support for Links. Used by Flow and Env.

Instance Method Summary (collapse)

Instance Method Details

Attempts to find the Link identified by the label.

Parameters:

  • label (Symbol|String)

    identifer of the Link

Returns:

  • (Link)

    returns the Link for the label



52
53
54
55
# File 'lib/oflow/haslinks.rb', line 52

def find_link(label)
  label = label.to_sym unless label.nil?
  @links[label] || @links[nil]
end

Sets up the links attribute.



8
9
10
# File 'lib/oflow/haslinks.rb', line 8

def init_links()
  @links = {}
end

Creates a Link identified by the label that has a target Task or Flow and operation.

Parameters:

  • label (Symbol|String)

    identifer of the Link

  • target (Symbol|String)

    identifer of the target Task

  • op (Symbol|String)

    operation to perform on the target Task

Raises:



17
18
19
20
21
22
23
# File 'lib/oflow/haslinks.rb', line 17

def link(label, target, op)
  label = label.to_sym unless label.nil?
  op = op.to_sym unless op.nil?
  raise ConfigError.new("Link #{label} already exists.") unless @links[label].nil?
  label = label.to_sym unless label.nil?
  @links[label] = Link.new(target.to_sym, op)
end

Returns the Links.

Returns:

  • (Hash)

    Hash of Links with the keys as Symbols that are the labels of the Links.



59
60
61
# File 'lib/oflow/haslinks.rb', line 59

def links()
  @links
end

Attempts to find and resolve the Link identified by the label. Resolving a Link uses the target identifier to find the target Task and save that in the Link.

Parameters:

  • label (Symbol|String)

    identifer of the Link

Returns:

  • (Link)

    returns the Link for the label



30
31
32
33
34
35
36
# File 'lib/oflow/haslinks.rb', line 30

def resolve_link(label)
  label = label.to_sym unless label.nil?
  lnk = @links[label] || @links[nil]
  return nil if lnk.nil?
  set_link_target(lnk) if lnk.target.nil?
  lnk
end

Sets the target Task for a Link.

Parameters:

  • lnk (Link)

    Link to find the target Task for.



40
41
42
43
44
45
46
47
# File 'lib/oflow/haslinks.rb', line 40

def set_link_target(lnk)
    if lnk.ingress
      task = find_task(lnk.target_name)
    else
      task = @flow.find_task(lnk.target_name)
    end
    lnk.instance_variable_set(:@target, task)
end