class Neo4j::ActiveNode::Query::QueryProxyEagerLoading::AssociationTree

Attributes

association[RW]
model[RW]
name[RW]
path[RW]
rel_length[RW]

Public Class Methods

new(model, name = nil, rel_length = nil) click to toggle source
Calls superclass method
   # File lib/neo4j/active_node/query/query_proxy_eager_loading/association_tree.rb
 8 def initialize(model, name = nil, rel_length = nil)
 9   super()
10   self.model = name ? target_class(model, name) : model
11   self.name = name
12   self.association = name ? model.associations[name] : nil
13   self.rel_length = rel_length
14 end

Public Instance Methods

add_key(key, length = nil) click to toggle source
   # File lib/neo4j/active_node/query/query_proxy_eager_loading/association_tree.rb
50 def add_key(key, length = nil)
51   self[key] ||= self.class.new(model, key, length)
52 end
add_nested(key, value, length = nil) click to toggle source
   # File lib/neo4j/active_node/query/query_proxy_eager_loading/association_tree.rb
54 def add_nested(key, value, length = nil)
55   add_key(key, length).add_spec(value)
56 end
add_spec(spec) click to toggle source
   # File lib/neo4j/active_node/query/query_proxy_eager_loading/association_tree.rb
20 def add_spec(spec)
21   fail_spec(spec) unless model
22 
23   case spec
24   when nil
25     nil
26   when Array
27     spec.each(&method(:add_spec))
28   when Hash
29     process_hash(spec)
30   when String
31     process_string(spec)
32   else
33     add_key(spec)
34   end
35 end
clone() click to toggle source
Calls superclass method
   # File lib/neo4j/active_node/query/query_proxy_eager_loading/association_tree.rb
16 def clone
17   super.tap { |copy| copy.each { |key, value| copy[key] = value.clone } }
18 end
fail_spec(spec) click to toggle source
   # File lib/neo4j/active_node/query/query_proxy_eager_loading/association_tree.rb
37 def fail_spec(spec)
38   fail "Cannot eager load \"past\" a polymorphic association. \
39     (Since the association can return multiple models, we don't how to handle the \"#{spec}\" association.)"
40 end
paths(*prefix) click to toggle source
   # File lib/neo4j/active_node/query/query_proxy_eager_loading/association_tree.rb
42 def paths(*prefix)
43   values.flat_map { |v| [[*prefix, v]] + v.paths(*prefix, v) }
44 end
process_hash(spec) click to toggle source
   # File lib/neo4j/active_node/query/query_proxy_eager_loading/association_tree.rb
46 def process_hash(spec)
47   spec.each { |key, value| add_nested(key, value) }
48 end
process_string(str) click to toggle source
   # File lib/neo4j/active_node/query/query_proxy_eager_loading/association_tree.rb
58 def process_string(str)
59   head, rest = str.split('.', 2)
60   k, length = head.split('*', -2)
61   add_nested(k.to_sym, rest, length)
62 end

Private Instance Methods

target_class(model, key) click to toggle source
   # File lib/neo4j/active_node/query/query_proxy_eager_loading/association_tree.rb
66 def target_class(model, key)
67   association = model.associations[key]
68   fail "Invalid association: #{[*path, key].join('.')}" unless association
69   model.associations[key].target_class
70 end