Class: Pangea::Magma::Chain::Builder

Inherits:
Object
  • Object
show all
Defined in:
lib/pangea/magma/chain.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeBuilder

Returns a new instance of Builder.



37
38
39
40
# File 'lib/pangea/magma/chain.rb', line 37

def initialize
  @workspaces = {}
  @edges      = []
end

Instance Attribute Details

#edgesObject (readonly)

Returns the value of attribute edges.



36
37
38
# File 'lib/pangea/magma/chain.rb', line 36

def edges
  @edges
end

#workspacesObject (readonly)

Returns the value of attribute workspaces.



36
37
38
# File 'lib/pangea/magma/chain.rb', line 36

def workspaces
  @workspaces
end

Instance Method Details

#edge(from:, output:, to:, input:) ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/pangea/magma/chain.rb', line 51

def edge(from:, output:, to:, input:)
  from_name = from.respond_to?(:name) ? from.name : from
  to_name   = to.respond_to?(:name)   ? to.name   : to
  unless @workspaces.key?(from_name)
    raise ArgumentError, "edge.from references unknown workspace: #{from_name}"
  end
  unless @workspaces.key?(to_name)
    raise ArgumentError, "edge.to references unknown workspace: #{to_name}"
  end
  @edges << ChainEdge.new(
    from: from_name, from_output: output,
    to:   to_name,   to_input:    input,
  )
  self
end

#workspace(ws) ⇒ Object



42
43
44
45
46
47
48
49
# File 'lib/pangea/magma/chain.rb', line 42

def workspace(ws)
  unless ws.is_a?(Workspace)
    raise ArgumentError,
          "expected Pangea::Magma::Workspace, got #{ws.class}"
  end
  @workspaces[ws.name] = ws
  self
end