Module: Dataflow::Node

Included in:
Dataflow::Nodes::ComputeNode, Dataflow::Nodes::DataNode
Defined in:
lib/dataflow/node.rb

Overview

Define (default) common interface for nodes. These may be overriden with their specific implementations.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.find(id) ⇒ Object

Returns either a DataNode or a ComputeNode that match the id



7
8
9
10
11
12
13
14
15
# File 'lib/dataflow/node.rb', line 7

def self.find(id)
  begin
    return Dataflow::Nodes::DataNode.find(id)
  rescue Mongoid::Errors::DocumentNotFound
    # try again against a computed node
  end

  Dataflow::Nodes::ComputeNode.find(id)
end

Instance Method Details

#recompute(*args) ⇒ Object



17
18
19
# File 'lib/dataflow/node.rb', line 17

def recompute(*args)
  # Interface only, for recursion purposes
end

#required_byObject



33
34
35
36
37
# File 'lib/dataflow/node.rb', line 33

def required_by
  Dataflow::Nodes::ComputeNode.where(dependency_ids: _id).map { |node|
    { node: node, type: 'dependency' }
  }
end

#valid_for_computation?Boolean

Overriden in computed node

Returns:

  • (Boolean)


22
23
24
# File 'lib/dataflow/node.rb', line 22

def valid_for_computation?
  true
end

#validate!Object



26
27
28
29
30
31
# File 'lib/dataflow/node.rb', line 26

def validate!
  # throw if normal model validation do not pass.
  valid = valid_for_computation?
  raise Dataflow::Errors::InvalidConfigurationError, errors.messages unless valid
  true
end