class SQLKnit::SQL::Join

Constants

TableAbbrSymbol

Attributes

head_table_name[R]
join_table_name[R]
on_conditions[R]
on_table_name[R]
statement_chains[R]
type[R]

Public Class Methods

new(head_table_name, table_name, opts = {}) click to toggle source
# File lib/sql/join.rb, line 12
def initialize head_table_name, table_name, opts = {}
  @head_table_name = head_table_name
  @join_table_name = table_name
  @on_conditions = []
  @type = opts[:type] || 'join'
  @statement_chains = []
end

Public Instance Methods

on(text = nil, &block) click to toggle source
# File lib/sql/join.rb, line 20
def on text = nil, &block

  if text.include? TableAbbrSymbol
    join_text = text.gsub(TableAbbrSymbol, join_table_name.to_s)
  else
    join_text = text
  end
  
  on_condition = OnCondition.new join_table_name
  on_condition.add_text join_text
  
  on_conditions << on_condition
  on_condition.instance_eval &block if block_given?
end
to_statement() click to toggle source
# File lib/sql/join.rb, line 35
def to_statement
  statement = on_conditions.map(&:to_statement).join("\n")
  [type, statement].join(" ")
end