Class: Card::Query::Join
Instance Attribute Summary collapse
-
#conditions ⇒ Object
Returns the value of attribute conditions.
-
#from ⇒ Object
Returns the value of attribute from.
-
#from_alias ⇒ Object
Returns the value of attribute from_alias.
-
#from_field ⇒ Object
Returns the value of attribute from_field.
-
#from_table ⇒ Object
Returns the value of attribute from_table.
-
#side ⇒ Object
Returns the value of attribute side.
-
#subjoins ⇒ Object
Returns the value of attribute subjoins.
-
#superjoin ⇒ Object
Returns the value of attribute superjoin.
-
#to ⇒ Object
Returns the value of attribute to.
-
#to_alias ⇒ Object
Returns the value of attribute to_alias.
-
#to_field ⇒ Object
Returns the value of attribute to_field.
-
#to_table ⇒ Object
Returns the value of attribute to_table.
Instance Method Summary collapse
- #from_and_to(opts) ⇒ Object
- #in_left? ⇒ Boolean
-
#initialize(opts = {}) ⇒ Join
constructor
A new instance of Join.
- #left? ⇒ Boolean
Constructor Details
#initialize(opts = {}) ⇒ Join
Returns a new instance of Join.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/card/query/join.rb', line 11 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 = [] @subjoins = [] if @from.is_a? Join @superjoin = @from @superjoin.subjoins << self end self end |
Instance Attribute Details
#conditions ⇒ Object
Returns the value of attribute conditions.
4 5 6 |
# File 'lib/card/query/join.rb', line 4 def conditions @conditions end |
#from ⇒ Object
Returns the value of attribute from.
4 5 6 |
# File 'lib/card/query/join.rb', line 4 def from @from end |
#from_alias ⇒ Object
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_field ⇒ Object
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_table ⇒ Object
Returns the value of attribute from_table.
4 5 6 |
# File 'lib/card/query/join.rb', line 4 def from_table @from_table end |
#side ⇒ Object
Returns the value of attribute side.
4 5 6 |
# File 'lib/card/query/join.rb', line 4 def side @side end |
#subjoins ⇒ Object
Returns the value of attribute subjoins.
4 5 6 |
# File 'lib/card/query/join.rb', line 4 def subjoins @subjoins end |
#superjoin ⇒ Object
Returns the value of attribute superjoin.
4 5 6 |
# File 'lib/card/query/join.rb', line 4 def superjoin @superjoin end |
#to ⇒ Object
Returns the value of attribute to.
4 5 6 |
# File 'lib/card/query/join.rb', line 4 def to @to end |
#to_alias ⇒ Object
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_field ⇒ Object
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_table ⇒ Object
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
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/card/query/join.rb', line 27 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
62 63 64 65 66 67 68 |
# File 'lib/card/query/join.rb', line 62 def in_left? if !@in_left.nil? @in_left else @in_left = left? || (!@superjoin.nil? && @superjoin.in_left?) end end |
#left? ⇒ Boolean
58 59 60 |
# File 'lib/card/query/join.rb', line 58 def left? side == 'LEFT' end |