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_ActiveRecord_Base, #visit_ActiveRecord_Relation, #visit_Array, #visit_Squeel_Nodes_And, #visit_Squeel_Nodes_As, #visit_Squeel_Nodes_Function, #visit_Squeel_Nodes_Grouping, #visit_Squeel_Nodes_Literal, #visit_Squeel_Nodes_Not, #visit_Squeel_Nodes_Operation, #visit_Squeel_Nodes_Or, #visit_passthrough, #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

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



16
17
18
19
20
21
22
# File 'lib/squeel/visitors/preload_visitor.rb', line 16

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)



38
39
40
# File 'lib/squeel/visitors/preload_visitor.rb', line 38

def visit_Squeel_Nodes_Join(o, parent)
  o._name
end

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



32
33
34
35
36
# File 'lib/squeel/visitors/preload_visitor.rb', line 32

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)



28
29
30
# File 'lib/squeel/visitors/preload_visitor.rb', line 28

def visit_Squeel_Nodes_Stub(o, parent)
  o.symbol
end

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



24
25
26
# File 'lib/squeel/visitors/preload_visitor.rb', line 24

def visit_Symbol(o, parent)
  o
end