Class: Squeel::Visitors::PreloadVisitor

Inherits:
Visitor
  • Object
show all
Defined in:
lib/squeel/visitors/preload_visitor.rb

Constant Summary

Constants inherited from Visitor

Visitor::DISPATCH

Instance Attribute Summary

Attributes inherited from Visitor

#context

Instance Method Summary collapse

Methods inherited from Visitor

#can_visit?, can_visit?, #hash_context_shifted?, #implies_hash_context_shift?, #quote, #quoted?, #symbolify, #visit, #visit!, #visit_ActiveRecord_Base, #visit_ActiveRecord_Relation, #visit_Arel_Nodes_Node, #visit_Array, #visit_Array!, #visit_Squeel_Nodes_And, #visit_Squeel_Nodes_As, #visit_Squeel_Nodes_Function, #visit_Squeel_Nodes_Grouping, #visit_Squeel_Nodes_KeyPath!, #visit_Squeel_Nodes_Literal, #visit_Squeel_Nodes_Not, #visit_Squeel_Nodes_Operation, #visit_Squeel_Nodes_Or, #visit_passthrough, #visit_with_hash_context_shift, #visit_with_hash_context_shift!, #visit_without_hash_context_shift

Constructor Details

#initialize(_ = nil) ⇒ PreloadVisitor

Returns a new instance of PreloadVisitor


5
6
7
8
# File 'lib/squeel/visitors/preload_visitor.rb', line 5

def initialize(_ = nil)
  # Unused. Just here to provide consistency in method signature
  # among subclasses of Visitor
end

Instance Method Details

#accept(object, parent = nil) ⇒ Object


10
11
12
# File 'lib/squeel/visitors/preload_visitor.rb', line 10

def accept(object, parent = nil)
  visit(object, parent)
end

#accept!(object, parent = nil) ⇒ Object


14
15
16
# File 'lib/squeel/visitors/preload_visitor.rb', line 14

def accept!(object, parent = nil)
  visit!(object, parent)
end

#visit_Hash(o, parent) ⇒ Object (private)


20
21
22
23
24
25
26
# File 'lib/squeel/visitors/preload_visitor.rb', line 20

def visit_Hash(o, parent)
  {}.tap do |hash|
    o.each do |key, value|
      hash[visit(key, parent)] = visit(value, parent)
    end
  end
end

#visit_Hash!(o, parent) ⇒ Object (private)


28
29
30
31
32
33
34
# File 'lib/squeel/visitors/preload_visitor.rb', line 28

def visit_Hash!(o, parent)
  {}.tap do |hash|
    o.each do |key, value|
      hash[visit!(key, parent)] = visit!(value, parent)
    end
  end
end

#visit_Squeel_Nodes_Join(o, parent) ⇒ Object (private)


50
51
52
# File 'lib/squeel/visitors/preload_visitor.rb', line 50

def visit_Squeel_Nodes_Join(o, parent)
  o._name
end

#visit_Squeel_Nodes_KeyPath(o, parent) ⇒ Object (private)


44
45
46
47
48
# File 'lib/squeel/visitors/preload_visitor.rb', line 44

def visit_Squeel_Nodes_KeyPath(o, parent)
  o.path.reverse.map(&:to_sym).inject do |hash, key|
    {key => hash}
  end
end

#visit_Squeel_Nodes_Stub(o, parent) ⇒ Object (private)


40
41
42
# File 'lib/squeel/visitors/preload_visitor.rb', line 40

def visit_Squeel_Nodes_Stub(o, parent)
  o.symbol
end

#visit_Symbol(o, parent) ⇒ Object (private)


36
37
38
# File 'lib/squeel/visitors/preload_visitor.rb', line 36

def visit_Symbol(o, parent)
  o
end