Class: Ronin::Code::SQL::JoinClause

Inherits:
Clause
  • Object
show all
Defined in:
lib/ronin/code/sql/join_clause.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(table, options = {}) ⇒ JoinClause

Returns a new instance of JoinClause.



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/ronin/code/sql/join_clause.rb', line 41

def initialize(table,options={})
  @table = table
  @natural = options[:natural]

  if options[:left]
    @direction = :left
  elsif options[:right]
    @direction = :right
  elsif options[:full]
    @direction = :full
  end

  if options[:inner]
    @side = :inner
  elsif options[:outer]
    @side = :outer
  elsif options[:cross]
    @side = :cross
  end
end

Instance Attribute Details

#directionObject

Direction of the join



36
37
38
# File 'lib/ronin/code/sql/join_clause.rb', line 36

def direction
  @direction
end

#naturalObject

Whether the join is natural or not



33
34
35
# File 'lib/ronin/code/sql/join_clause.rb', line 33

def natural
  @natural
end

#sideObject

Side of the join



39
40
41
# File 'lib/ronin/code/sql/join_clause.rb', line 39

def side
  @side
end

#tableObject

Table to join with



30
31
32
# File 'lib/ronin/code/sql/join_clause.rb', line 30

def table
  @table
end

Instance Method Details

#crossObject



87
88
89
90
# File 'lib/ronin/code/sql/join_clause.rb', line 87

def cross
  @side = :cross
  return self
end

#emitObject



92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/ronin/code/sql/join_clause.rb', line 92

def emit
  tokens = []

  tokens += emit_token('NATURAL') if @natural

  case @direction
  when :left, 'left'
    tokens += emit_token('LEFT')
  when :right, 'right'
    tokens += emit_token('RIGHT')
  when :full, 'full'
    tokens += emit_token('FULL')
  end

  case @side
  when :inner, 'inner'
    tokens += emit_token('INNER')
  when :outer, 'outer'
    tokens += emit_token('OUTER')
  when :cross, 'cross'
    tokens += emit_token('CROSS')
  end

  tokens += emit_token('JOIN')
  
  return tokens + emit_value(@table)
end

#fullObject



72
73
74
75
# File 'lib/ronin/code/sql/join_clause.rb', line 72

def full
  @direction = :full
  return self
end

#innerObject



77
78
79
80
# File 'lib/ronin/code/sql/join_clause.rb', line 77

def inner
  @side = :inner
  return self
end

#leftObject



62
63
64
65
# File 'lib/ronin/code/sql/join_clause.rb', line 62

def left
  @direction = :left
  return self
end

#outerObject



82
83
84
85
# File 'lib/ronin/code/sql/join_clause.rb', line 82

def outer
  @side = :outer
  return self
end

#rightObject



67
68
69
70
# File 'lib/ronin/code/sql/join_clause.rb', line 67

def right
  @direction = :right
  return self
end