Class: ComputedModel::DepGraph::Node Private

Inherits:
Object
  • Object
show all
Defined in:
lib/computed_model/dep_graph.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

A node in the dependency graph. That is, a field in a computed model.

Examples:

computed node with plain dependencies

Node.new(:computed, :field1, { field2: [], field3: [] })

computed node with subfield selectors

Node.new(:computed, :field1, { field2: [:foo, bar: []], field3: [] })

loaded and primary dependencies

Node.new(:loaded, :field1, {})
Node.new(:primary, :field1, {})

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type, name, edges) ⇒ Node

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Node.

Parameters:

  • type (Symbol)

    the type of the node. One of :computed, :loaded and :primary.

  • name (Symbol)

    the name of the node.

  • edges (Array<(Symbol, Hash)>, Hash, Symbol)

    list of edges.

Raises:

  • (ArgumentError)


139
140
141
142
143
144
145
146
147
148
# File 'lib/computed_model/dep_graph.rb', line 139

def initialize(type, name, edges)
  raise ArgumentError, "invalid type: #{type.inspect}" unless ALLOWED_TYPES.include?(type)

  edges = ComputedModel.normalize_dependencies(edges)
  raise ArgumentError, "primary field cannot have dependency: #{name}" if type == :primary && edges.size > 0

  @type = type
  @name = name
  @edges = edges.map { |k, v| [k, Edge.new(k, v)] }.to_h.freeze
end

Instance Attribute Details

#edgesHash{Symbol => Edge} (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns edges indexed by its name.

Returns:

  • (Hash{Symbol => Edge})

    edges indexed by its name.



131
132
133
# File 'lib/computed_model/dep_graph.rb', line 131

def edges
  @edges
end

#nameSymbol (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns the name of the node.

Returns:

  • (Symbol)

    the name of the node.



129
130
131
# File 'lib/computed_model/dep_graph.rb', line 129

def name
  @name
end

#typeSymbol (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns the type of the node. One of :computed, :loaded and :primary.

Returns:

  • (Symbol)

    the type of the node. One of :computed, :loaded and :primary.



127
128
129
# File 'lib/computed_model/dep_graph.rb', line 127

def type
  @type
end