class ComputedModel::DepGraph::Node

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

@example computed node with plain dependencies

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

@example computed node with subfield selectors

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

@example loaded and primary dependencies

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

Constants

ALLOWED_TYPES

Attributes

edges[R]

@return [Hash{Symbol => Edge}] edges indexed by its name.

name[R]

@return [Symbol] the name of the node.

type[R]

@return [Symbol] the type of the node. One of :computed, :loaded and :primary.

Public Class Methods

new(type, name, edges) click to toggle source

@param type [Symbol] the type of the node. One of :computed, :loaded and :primary. @param name [Symbol] the name of the node. @param edges [Array<(Symbol, Hash)>, Hash, Symbol] list of edges.

# 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