Class: Neo4j::ActiveNode::Query::QueryProxyEagerLoading::AssociationTree

Inherits:
Hash
  • Object
show all
Defined in:
lib/neo4j/active_node/query/query_proxy_eager_loading.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(model, name = nil) ⇒ AssociationTree

Returns a new instance of AssociationTree.


14
15
16
17
18
19
# File 'lib/neo4j/active_node/query/query_proxy_eager_loading.rb', line 14

def initialize(model, name = nil)
  super()
  self.model = name ? target_class(model, name) : model
  self.name = name
  self.association = name ? model.associations[name] : nil
end

Instance Attribute Details

#associationObject

Returns the value of attribute association


12
13
14
# File 'lib/neo4j/active_node/query/query_proxy_eager_loading.rb', line 12

def association
  @association
end

#modelObject

Returns the value of attribute model


12
13
14
# File 'lib/neo4j/active_node/query/query_proxy_eager_loading.rb', line 12

def model
  @model
end

#nameObject

Returns the value of attribute name


12
13
14
# File 'lib/neo4j/active_node/query/query_proxy_eager_loading.rb', line 12

def name
  @name
end

#pathObject

Returns the value of attribute path


12
13
14
# File 'lib/neo4j/active_node/query/query_proxy_eager_loading.rb', line 12

def path
  @path
end

Instance Method Details

#add_spec(spec) ⇒ Object


25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/neo4j/active_node/query/query_proxy_eager_loading.rb', line 25

def add_spec(spec)
  unless model
    fail "Cannot eager load \"past\" a polymorphic association. \
    (Since the association can return multiple models, we don't how to handle the \"#{spec}\" association.)"
  end

  if spec.is_a?(Array)
    spec.each { |s| add_spec(s) }
  elsif spec.is_a?(Hash)
    process_hash(spec)
  else
    self[spec] ||= self.class.new(model, spec)
  end
end

#cloneObject


21
22
23
# File 'lib/neo4j/active_node/query/query_proxy_eager_loading.rb', line 21

def clone
  super.tap { |copy| copy.each { |key, value| copy[key] = value.clone } }
end

#paths(*prefix) ⇒ Object


40
41
42
# File 'lib/neo4j/active_node/query/query_proxy_eager_loading.rb', line 40

def paths(*prefix)
  values.flat_map { |v| [[*prefix, v]] + v.paths(*prefix, v) }
end

#process_hash(spec) ⇒ Object


44
45
46
# File 'lib/neo4j/active_node/query/query_proxy_eager_loading.rb', line 44

def process_hash(spec)
  spec.each { |k, v| (self[k] ||= self.class.new(model, k)).add_spec(v) }
end