123456789_123456789_123456789_123456789_123456789_

Class: Arel::Visitors::Dot

Do not use. This class is for internal use only.
Relationships & Source Files
Namespace Children
Classes:
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
self, Visitor
Instance Chain:
self, Visitor
Inherits: Arel::Visitors::Visitor
Defined in: activerecord/lib/arel/visitors/dot.rb

Class Method Summary

Visitor - Inherited

Instance Attribute Summary

Visitor - Inherited

Instance Method Summary

Visitor - Inherited

Constructor Details

.newDot

[ GitHub ]

  
# File 'activerecord/lib/arel/visitors/dot.rb', line 19

def initialize
  super()
  @nodes      = []
  @edges      = []
  @node_stack = []
  @edge_stack = []
  @seen       = {}
end

Instance Method Details

#accept(object, collector)

[ GitHub ]

  
# File 'activerecord/lib/arel/visitors/dot.rb', line 28

def accept(object, collector)
  visit object
  collector << to_dot
end

#edge(name) (private)

[ GitHub ]

  
# File 'activerecord/lib/arel/visitors/dot.rb', line 261

def edge(name)
  edge = Edge.new(name, @node_stack.last)
  @edge_stack.push edge
  @edges << edge
  yield
  @edge_stack.pop
end

#quote(string) (private)

[ GitHub ]

  
# File 'activerecord/lib/arel/visitors/dot.rb', line 279

def quote(string)
  string.to_s.gsub('"', '\"')
end

#to_dot (private)

[ GitHub ]

  
# File 'activerecord/lib/arel/visitors/dot.rb', line 283

def to_dot
  "digraph \"Arel\" {\nnode [width=0.375,height=0.25,shape=record];\n" +
    @nodes.map { |node|
      label = "<f0>#{node.name}"

      node.fields.each_with_index do |field, i|
        label += "|<f#{i + 1}>#{quote field}"
      end

      "#{node.id} [label=\"#{label}\"];"
    }.join("\n") + "\n" + @edges.map { |edge|
      "#{edge.from.id} -> #{edge.to.id} [label=\"#{edge.name}\"];"
    }.join("\n") + "\n}"
end

#visit(o) (private)

[ GitHub ]

  
# File 'activerecord/lib/arel/visitors/dot.rb', line 247

def visit(o)
  if node = @seen[o.object_id]
    @edge_stack.last.to = node
    return
  end

  node = Node.new(o.class.name, o.object_id)
  @seen[node.id] = node
  @nodes << node
  with_node node do
    super
  end
end

#visit__children(o) (private) Also known as: #visit_Arel_Nodes_And, #visit_Arel_Nodes_Or, #visit_Arel_Nodes_With

[ GitHub ]

  
# File 'activerecord/lib/arel/visitors/dot.rb', line 188

def visit__children(o)
  o.children.each_with_index do |child, i|
    edge(i) { visit child }
  end
end

#visit__no_edges(o) (private) Also known as: #visit_Arel_Nodes_CurrentRow, #visit_Arel_Nodes_Distinct

[ GitHub ]

  
# File 'activerecord/lib/arel/visitors/dot.rb', line 103

def visit__no_edges(o)
  # intentionally left blank
end

#visit__regexp(o) (private) Also known as: #visit_Arel_Nodes_Regexp, #visit_Arel_Nodes_NotRegexp

[ GitHub ]

  
# File 'activerecord/lib/arel/visitors/dot.rb', line 60

def visit__regexp(o)
  visit_edge o, "left"
  visit_edge o, "right"
  visit_edge o, "case_sensitive"
end

#visit_ActiveModel_Attribute(o) (private)

[ GitHub ]

  
# File 'activerecord/lib/arel/visitors/dot.rb', line 216

def visit_ActiveModel_Attribute(o)
  visit_edge(o, "value_before_type_cast")
end

#visit_Arel_Attributes_Attribute(o) (private)

[ GitHub ]

  
# File 'activerecord/lib/arel/visitors/dot.rb', line 183

def visit_Arel_Attributes_Attribute(o)
  visit_edge o, "relation"
  visit_edge o, "name"
end

#visit_Arel_Nodes_And(o) (private)

Alias for #visit__children.

[ GitHub ]

  
# File 'activerecord/lib/arel/visitors/dot.rb', line 193

alias :visit_Arel_Nodes_And :visit__children

#visit_Arel_Nodes_Binary(o) (private)

[ GitHub ]

  
# File 'activerecord/lib/arel/visitors/dot.rb', line 44

def visit_Arel_Nodes_Binary(o)
  visit_edge o, "left"
  visit_edge o, "right"
end

#visit_Arel_Nodes_BindParam(o) (private)

[ GitHub ]

  
# File 'activerecord/lib/arel/visitors/dot.rb', line 212

def visit_Arel_Nodes_BindParam(o)
  visit_edge(o, "value")
end

#visit_Arel_Nodes_Case(o) (private)

[ GitHub ]

  
# File 'activerecord/lib/arel/visitors/dot.rb', line 237

def visit_Arel_Nodes_Case(o)
  visit_edge(o, "case")
  visit_edge(o, "conditions")
  visit_edge(o, "default")
end

#visit_Arel_Nodes_Casted(o) (private)

[ GitHub ]

  
# File 'activerecord/lib/arel/visitors/dot.rb', line 172

def visit_Arel_Nodes_Casted(o)
  visit_edge o, "value"
  visit_edge o, "attribute"
end

#visit_Arel_Nodes_Comment(o) (private)

[ GitHub ]

  
# File 'activerecord/lib/arel/visitors/dot.rb', line 233

def visit_Arel_Nodes_Comment(o)
  visit_edge(o, "values")
end

#visit_Arel_Nodes_Count(o) (private)

[ GitHub ]

  
# File 'activerecord/lib/arel/visitors/dot.rb', line 77

def visit_Arel_Nodes_Count(o)
  visit_edge o, "expressions"
  visit_edge o, "distinct"
end

#visit_Arel_Nodes_CurrentRow(o) (private)

Alias for #visit__no_edges.

[ GitHub ]

  
# File 'activerecord/lib/arel/visitors/dot.rb', line 106

alias :visit_Arel_Nodes_CurrentRow :visit__no_edges

#visit_Arel_Nodes_DeleteStatement(o) (private)

[ GitHub ]

  
# File 'activerecord/lib/arel/visitors/dot.rb', line 159

def visit_Arel_Nodes_DeleteStatement(o)
  visit_edge o, "relation"
  visit_edge o, "wheres"
  visit_edge o, "orders"
  visit_edge o, "limit"
  visit_edge o, "offset"
  visit_edge o, "key"
end

#visit_Arel_Nodes_Distinct(o) (private)

Alias for #visit__no_edges.

[ GitHub ]

  
# File 'activerecord/lib/arel/visitors/dot.rb', line 107

alias :visit_Arel_Nodes_Distinct :visit__no_edges

#visit_Arel_Nodes_Extract(o) (private)

[ GitHub ]

  
# File 'activerecord/lib/arel/visitors/dot.rb', line 109

def visit_Arel_Nodes_Extract(o)
  visit_edge o, "expressions"
  visit_edge o, "alias"
end

#visit_Arel_Nodes_Function(o) (private)

[ GitHub ]

  
# File 'activerecord/lib/arel/visitors/dot.rb', line 34

def visit_Arel_Nodes_Function(o)
  visit_edge o, "expressions"
  visit_edge o, "distinct"
  visit_edge o, "alias"
end

#visit_Arel_Nodes_HomogeneousIn(o) (private)

[ GitHub ]

  
# File 'activerecord/lib/arel/visitors/dot.rb', line 177

def visit_Arel_Nodes_HomogeneousIn(o)
  visit_edge o, "values"
  visit_edge o, "type"
  visit_edge o, "attribute"
end

#visit_Arel_Nodes_InfixOperation(o) (private)

[ GitHub ]

  
# File 'activerecord/lib/arel/visitors/dot.rb', line 54

def visit_Arel_Nodes_InfixOperation(o)
  visit_edge o, "operator"
  visit_edge o, "left"
  visit_edge o, "right"
end

#visit_Arel_Nodes_InsertStatement(o) (private)

[ GitHub ]

  
# File 'activerecord/lib/arel/visitors/dot.rb', line 121

def visit_Arel_Nodes_InsertStatement(o)
  visit_edge o, "relation"
  visit_edge o, "columns"
  visit_edge o, "values"
  visit_edge o, "select"
end

#visit_Arel_Nodes_NamedFunction(o) (private)

[ GitHub ]

  
# File 'activerecord/lib/arel/visitors/dot.rb', line 114

def visit_Arel_Nodes_NamedFunction(o)
  visit_edge o, "name"
  visit_edge o, "expressions"
  visit_edge o, "distinct"
  visit_edge o, "alias"
end

#visit_Arel_Nodes_NamedWindow(o) (private)

[ GitHub ]

  
# File 'activerecord/lib/arel/visitors/dot.rb', line 96

def visit_Arel_Nodes_NamedWindow(o)
  visit_edge o, "partitions"
  visit_edge o, "orders"
  visit_edge o, "framing"
  visit_edge o, "name"
end

#visit_Arel_Nodes_NotRegexp(o) (private)

Alias for #visit__regexp.

[ GitHub ]

  
# File 'activerecord/lib/arel/visitors/dot.rb', line 66

alias :visit_Arel_Nodes_NotRegexp :visit__regexp

#visit_Arel_Nodes_Or(o) (private)

Alias for #visit__children.

[ GitHub ]

  
# File 'activerecord/lib/arel/visitors/dot.rb', line 194

alias :visit_Arel_Nodes_Or :visit__children

#visit_Arel_Nodes_Ordering(o) (private)

[ GitHub ]

  
# File 'activerecord/lib/arel/visitors/dot.rb', line 68

def visit_Arel_Nodes_Ordering(o)
  visit_edge o, "expr"
end

#visit_Arel_Nodes_Regexp(o) (private)

Alias for #visit__regexp.

[ GitHub ]

  
# File 'activerecord/lib/arel/visitors/dot.rb', line 65

alias :visit_Arel_Nodes_Regexp :visit__regexp

#visit_Arel_Nodes_SelectCore(o) (private)

[ GitHub ]

  
# File 'activerecord/lib/arel/visitors/dot.rb', line 128

def visit_Arel_Nodes_SelectCore(o)
  visit_edge o, "source"
  visit_edge o, "projections"
  visit_edge o, "wheres"
  visit_edge o, "windows"
  visit_edge o, "groups"
  visit_edge o, "comment"
  visit_edge o, "havings"
  visit_edge o, "set_quantifier"
  visit_edge o, "optimizer_hints"
end

#visit_Arel_Nodes_SelectStatement(o) (private)

[ GitHub ]

  
# File 'activerecord/lib/arel/visitors/dot.rb', line 140

def visit_Arel_Nodes_SelectStatement(o)
  visit_edge o, "cores"
  visit_edge o, "limit"
  visit_edge o, "orders"
  visit_edge o, "offset"
  visit_edge o, "lock"
  visit_edge o, "with"
end

#visit_Arel_Nodes_SqlLiteral(o) (private)

Alias for #visit_String.

[ GitHub ]

  
# File 'activerecord/lib/arel/visitors/dot.rb', line 210

alias :visit_Arel_Nodes_SqlLiteral :visit_String

#visit_Arel_Nodes_StringJoin(o) (private)

[ GitHub ]

  
# File 'activerecord/lib/arel/visitors/dot.rb', line 86

def visit_Arel_Nodes_StringJoin(o)
  visit_edge o, "left"
end

#visit_Arel_Nodes_TableAlias(o) (private)

[ GitHub ]

  
# File 'activerecord/lib/arel/visitors/dot.rb', line 72

def visit_Arel_Nodes_TableAlias(o)
  visit_edge o, "name"
  visit_edge o, "relation"
end

#visit_Arel_Nodes_Unary(o) (private)

[ GitHub ]

  
# File 'activerecord/lib/arel/visitors/dot.rb', line 40

def visit_Arel_Nodes_Unary(o)
  visit_edge o, "expr"
end

#visit_Arel_Nodes_UnaryOperation(o) (private)

[ GitHub ]

  
# File 'activerecord/lib/arel/visitors/dot.rb', line 49

def visit_Arel_Nodes_UnaryOperation(o)
  visit_edge o, "operator"
  visit_edge o, "expr"
end

#visit_Arel_Nodes_UpdateStatement(o) (private)

[ GitHub ]

  
# File 'activerecord/lib/arel/visitors/dot.rb', line 149

def visit_Arel_Nodes_UpdateStatement(o)
  visit_edge o, "relation"
  visit_edge o, "wheres"
  visit_edge o, "values"
  visit_edge o, "orders"
  visit_edge o, "limit"
  visit_edge o, "offset"
  visit_edge o, "key"
end

#visit_Arel_Nodes_ValuesList(o) (private)

[ GitHub ]

  
# File 'activerecord/lib/arel/visitors/dot.rb', line 82

def visit_Arel_Nodes_ValuesList(o)
  visit_edge o, "rows"
end

#visit_Arel_Nodes_Window(o) (private)

[ GitHub ]

  
# File 'activerecord/lib/arel/visitors/dot.rb', line 90

def visit_Arel_Nodes_Window(o)
  visit_edge o, "partitions"
  visit_edge o, "orders"
  visit_edge o, "framing"
end

#visit_Arel_Nodes_With(o) (private)

Alias for #visit__children.

[ GitHub ]

  
# File 'activerecord/lib/arel/visitors/dot.rb', line 195

alias :visit_Arel_Nodes_With :visit__children

#visit_Arel_Table(o) (private)

[ GitHub ]

  
# File 'activerecord/lib/arel/visitors/dot.rb', line 168

def visit_Arel_Table(o)
  visit_edge o, "name"
end

#visit_Array(o) (private) Also known as: #visit_Set

[ GitHub ]

  
# File 'activerecord/lib/arel/visitors/dot.rb', line 226

def visit_Array(o)
  o.each_with_index do |member, i|
    edge(i) { visit member }
  end
end

#visit_BigDecimal(o) (private)

Alias for #visit_String.

[ GitHub ]

  
# File 'activerecord/lib/arel/visitors/dot.rb', line 207

alias :visit_BigDecimal :visit_String

#visit_Date(o) (private)

Alias for #visit_String.

[ GitHub ]

  
# File 'activerecord/lib/arel/visitors/dot.rb', line 201

alias :visit_Date :visit_String

#visit_DateTime(o) (private)

Alias for #visit_String.

[ GitHub ]

  
# File 'activerecord/lib/arel/visitors/dot.rb', line 202

alias :visit_DateTime :visit_String

#visit_edge(o, method) (private)

[ GitHub ]

  
# File 'activerecord/lib/arel/visitors/dot.rb', line 243

def visit_edge(o, method)
  edge(method) { visit o.send(method) }
end

#visit_FalseClass(o) (private)

Alias for #visit_String.

[ GitHub ]

  
# File 'activerecord/lib/arel/visitors/dot.rb', line 205

alias :visit_FalseClass :visit_String

#visit_Float(o) (private)

Alias for #visit_String.

[ GitHub ]

  
# File 'activerecord/lib/arel/visitors/dot.rb', line 208

alias :visit_Float :visit_String

#visit_Hash(o) (private)

[ GitHub ]

  
# File 'activerecord/lib/arel/visitors/dot.rb', line 220

def visit_Hash(o)
  o.each_with_index do |pair, i|
    edge("pair_#{i}") { visit pair }
  end
end

#visit_Integer(o) (private)

Alias for #visit_String.

[ GitHub ]

  
# File 'activerecord/lib/arel/visitors/dot.rb', line 206

alias :visit_Integer :visit_String

#visit_NilClass(o) (private)

Alias for #visit_String.

[ GitHub ]

  
# File 'activerecord/lib/arel/visitors/dot.rb', line 203

alias :visit_NilClass :visit_String

#visit_Set(o) (private)

Alias for #visit_Array.

[ GitHub ]

  
# File 'activerecord/lib/arel/visitors/dot.rb', line 231

alias :visit_Set :visit_Array

#visit_String(o) (private) Also known as: #visit_Time, #visit_Date, #visit_DateTime, #visit_NilClass, #visit_TrueClass, #visit_FalseClass, #visit_Integer, #visit_BigDecimal, #visit_Float, #visit_Symbol, #visit_Arel_Nodes_SqlLiteral

[ GitHub ]

  
# File 'activerecord/lib/arel/visitors/dot.rb', line 197

def visit_String(o)
  @node_stack.last.fields << o
end

#visit_Symbol(o) (private)

Alias for #visit_String.

[ GitHub ]

  
# File 'activerecord/lib/arel/visitors/dot.rb', line 209

alias :visit_Symbol :visit_String

#visit_Time(o) (private)

Alias for #visit_String.

[ GitHub ]

  
# File 'activerecord/lib/arel/visitors/dot.rb', line 200

alias :visit_Time :visit_String

#visit_TrueClass(o) (private)

Alias for #visit_String.

[ GitHub ]

  
# File 'activerecord/lib/arel/visitors/dot.rb', line 204

alias :visit_TrueClass :visit_String

#with_node(node) (private)

[ GitHub ]

  
# File 'activerecord/lib/arel/visitors/dot.rb', line 269

def with_node(node)
  if edge = @edge_stack.last
    edge.to = node
  end

  @node_stack.push node
  yield
  @node_stack.pop
end