class Praxis::Mapper::SelectorGeneratorNode::FieldDependenciesNode
FieldDependenciesNode
, attached to a SelectorGeneratorNode
, which will contain, for every field passed in (not properties, but fields), the list of property dependencies associated with them. If these property dependenceis are for the ‘local’ resource of the SelectorGeneratorNode
, they’d be just an array of property names If a field is a property that is an association to another resource, the reference field will point to which other node it depends on (this node fields does not need to be one of the immediate tracks, but it could be further down the tracks SelectorGeneratorNode’s tree) In the case of references, any further resolution of dependencies from fields need to be continued in that track’s SelectorGenerator’s FieldDependenciesNode
(recursively)
Attributes
Public Class Methods
# File lib/praxis/mapper/selector_generator.rb, line 19 def initialize(name:, selector_node:) @name = name @fields = Hash.new do |hash, key| hash[key] = FieldDependenciesNode.new(name: key, selector_node: selector_node) end @deps = Set.new @references = nil # Field path, currently being processed @current_field = [] @selector_node = selector_node end
Public Instance Methods
# File lib/praxis/mapper/selector_generator.rb, line 53 def [](*path) @fields.dig(*path) end
# File lib/praxis/mapper/selector_generator.rb, line 39 def add_local_dep(name) pointer = @current_field.empty? ? @fields[true] : @fields.dig(*@current_field) pointer.deps.add name end
# File lib/praxis/mapper/selector_generator.rb, line 49 def dig(...) @fields.dig(...) end
For spec/debugging purposes only
# File lib/praxis/mapper/selector_generator.rb, line 58 def dump hash = {} hash[:deps] = @deps.to_a unless @deps.empty? unless @references.nil? # Point, using a simple string, that it references another node (just print the resource name) # We don't know how deep in the tree this will be, or if there are other nodes of the same resource # type, but it seems good enough for checking things in specs hash[:references] = "Linked to resource: #{@references.resource}" end field_deps = @fields.each_with_object({}) do |(name, node), h| dumped = node.dump h[name] = dumped unless dumped.empty? end hash[:fields] = field_deps unless field_deps.empty? hash end
# File lib/praxis/mapper/selector_generator.rb, line 35 def end_field @current_field.pop end
# File lib/praxis/mapper/selector_generator.rb, line 44 def save_reference(selector_node) pointer = @current_field.empty? ? @fields[true] : @fields.dig(*@current_field) pointer.references = selector_node end
# File lib/praxis/mapper/selector_generator.rb, line 31 def start_field(field_name) @current_field.push field_name end