Class: Praxis::Mapper::SelectorGeneratorNode::FieldDependenciesNode
- Inherits:
-
Object
- Object
- Praxis::Mapper::SelectorGeneratorNode::FieldDependenciesNode
- Defined in:
- lib/praxis/mapper/selector_generator.rb
Overview
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)
Instance Attribute Summary collapse
-
#deps ⇒ Object
readonly
Returns the value of attribute deps.
-
#fields ⇒ Object
readonly
Returns the value of attribute fields.
-
#references ⇒ Object
Returns the value of attribute references.
-
#selector_node ⇒ Object
readonly
Returns the value of attribute selector_node.
Instance Method Summary collapse
- #[](*path) ⇒ Object
- #add_local_dep(name) ⇒ Object
- #dig ⇒ Object
-
#dump ⇒ Object
For spec/debugging purposes only.
- #end_field ⇒ Object
-
#initialize(name:, selector_node:) ⇒ FieldDependenciesNode
constructor
A new instance of FieldDependenciesNode.
- #save_reference(selector_node) ⇒ Object
- #start_field(field_name) ⇒ Object
Constructor Details
#initialize(name:, selector_node:) ⇒ FieldDependenciesNode
Returns a new instance of FieldDependenciesNode.
19 20 21 22 23 24 25 26 27 28 29 |
# 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 |
Instance Attribute Details
#deps ⇒ Object (readonly)
Returns the value of attribute deps.
16 17 18 |
# File 'lib/praxis/mapper/selector_generator.rb', line 16 def deps @deps end |
#fields ⇒ Object (readonly)
Returns the value of attribute fields.
16 17 18 |
# File 'lib/praxis/mapper/selector_generator.rb', line 16 def fields @fields end |
#references ⇒ Object
Returns the value of attribute references.
17 18 19 |
# File 'lib/praxis/mapper/selector_generator.rb', line 17 def references @references end |
#selector_node ⇒ Object (readonly)
Returns the value of attribute selector_node.
16 17 18 |
# File 'lib/praxis/mapper/selector_generator.rb', line 16 def selector_node @selector_node end |
Instance Method Details
#[](*path) ⇒ Object
53 54 55 |
# File 'lib/praxis/mapper/selector_generator.rb', line 53 def [](*path) @fields.dig(*path) end |
#add_local_dep(name) ⇒ Object
39 40 41 42 |
# 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 |
#dig ⇒ Object
49 50 51 |
# File 'lib/praxis/mapper/selector_generator.rb', line 49 def dig(...) @fields.dig(...) end |
#dump ⇒ Object
For spec/debugging purposes only
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# 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 |
#end_field ⇒ Object
35 36 37 |
# File 'lib/praxis/mapper/selector_generator.rb', line 35 def end_field @current_field.pop end |
#save_reference(selector_node) ⇒ Object
44 45 46 47 |
# 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 |
#start_field(field_name) ⇒ Object
31 32 33 |
# File 'lib/praxis/mapper/selector_generator.rb', line 31 def start_field(field_name) @current_field.push field_name end |