Class: Card::Query::Join

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Join

documentation??? -pk



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/card/query/join.rb', line 12

def initialize opts={}
  from_and_to opts
  opts.each do |key, value|
    send "#{key}=", value if value.present?
  end
  @from_field ||= :id
  @to_field   ||= :id

  @conditions = Array @conditions
  @subjoins = Array @subjoins
  if @from.is_a? Join
    @superjoin = @from
    @superjoin.subjoins << self
  end
  self
end

Instance Attribute Details

#conditionsObject

Returns the value of attribute conditions.



4
5
6
# File 'lib/card/query/join.rb', line 4

def conditions
  @conditions
end

#fromObject

Returns the value of attribute from.



4
5
6
# File 'lib/card/query/join.rb', line 4

def from
  @from
end

#from_aliasObject

Returns the value of attribute from_alias.



4
5
6
# File 'lib/card/query/join.rb', line 4

def from_alias
  @from_alias
end

#from_fieldObject

Returns the value of attribute from_field.



4
5
6
# File 'lib/card/query/join.rb', line 4

def from_field
  @from_field
end

#from_tableObject

Returns the value of attribute from_table.



4
5
6
# File 'lib/card/query/join.rb', line 4

def from_table
  @from_table
end

#sideObject

Returns the value of attribute side.



4
5
6
# File 'lib/card/query/join.rb', line 4

def side
  @side
end

#subjoinsObject

Returns the value of attribute subjoins.



4
5
6
# File 'lib/card/query/join.rb', line 4

def subjoins
  @subjoins
end

#superjoinObject

Returns the value of attribute superjoin.



4
5
6
# File 'lib/card/query/join.rb', line 4

def superjoin
  @superjoin
end

#toObject

Returns the value of attribute to.



4
5
6
# File 'lib/card/query/join.rb', line 4

def to
  @to
end

#to_aliasObject

Returns the value of attribute to_alias.



4
5
6
# File 'lib/card/query/join.rb', line 4

def to_alias
  @to_alias
end

#to_fieldObject

Returns the value of attribute to_field.



4
5
6
# File 'lib/card/query/join.rb', line 4

def to_field
  @to_field
end

#to_tableObject

Returns the value of attribute to_table.



4
5
6
# File 'lib/card/query/join.rb', line 4

def to_table
  @to_table
end

Instance Method Details

#from_and_to(opts) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/card/query/join.rb', line 29

def from_and_to opts
  [:from, :to].each do |side|
    object = opts[side]
    case object
    when nil then next
    when Array
      { table: object.shift, alias: object.shift, field: object.shift }
    when Card::Query
      { table: "cards", alias: object.table_alias }
    when Card::Query::Reference
      { table: "card_references", alias: object.table_alias }
    when Card::Query::Join
      raise "to: cannot be Join" if side == :to
      { table: object.to_table, alias: object.to_alias }
    else
      raise "invalid #{side} option: #{object}"
    end.map do |key, value|
      opts[:"#{side}_#{key}"] ||= value
    end
  end
end

#in_left?Boolean

Returns:

  • (Boolean)


64
65
66
67
68
69
70
# File 'lib/card/query/join.rb', line 64

def in_left?
  if !@in_left.nil?
    @in_left
  else
    @in_left = left? || (!@superjoin.nil? && @superjoin.in_left?)
  end
end

#left?Boolean

Returns:

  • (Boolean)


60
61
62
# File 'lib/card/query/join.rb', line 60

def left?
  side == "LEFT"
end