Class: Card::Query::Join

Inherits:
Object
  • Object
show all
Defined in:
lib/card/query/join.rb

Overview

object representation of Card::Query joins

Constant Summary collapse

JOIN_OPT_KEYS =
%i[side conditions
from from_table from_alias from_field
to to_table to_alias to_field].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Join

This example join clause:

cards c LEFT JOIN card_actions ca on c.id = ca.card_id and ca.draft is null

…would translate into the following instance variables on the Join object:

@side = "left"
@from_table = "cards"
@from_alias = "c"
@from_field = "id"
@to_table = "card_actions"
@to_alias = "ca"
@to_field = "card_id"
@conditions = "ca.draft is null"

all of the above can be set directly via opts using the keys with the same name.

Join.new side: "left", from_table: "cards"...

The from and to fields can also be set via :from and :to keys. (see #interpret_from_and_to)

You can generally use Symbols in place of Strings where applicable.



37
38
39
40
41
42
43
44
# File 'lib/card/query/join.rb', line 37

def initialize opts={}
  interpret_from_and_to opts
  convert_opts_to_instance_variables opts

  @conditions = Array(@conditions).compact
  @subjoins = []
  register_superjoin
end

Instance Attribute Details

#subjoinsObject

These two manage hierarchy of nested joins



11
12
13
# File 'lib/card/query/join.rb', line 11

def subjoins
  @subjoins
end

#superjoinObject

These two manage hierarchy of nested joins



11
12
13
# File 'lib/card/query/join.rb', line 11

def superjoin
  @superjoin
end

Instance Method Details

#left?Boolean

Returns:

  • (Boolean)


54
55
56
# File 'lib/card/query/join.rb', line 54

def left?
  side == "LEFT"
end

#sideObject



46
47
48
49
50
51
52
# File 'lib/card/query/join.rb', line 46

def side
  if !@side.nil?
    @side.to_s.upcase
  else
    @side = inside_or? ? "LEFT" : nil
  end
end