Class: ParamsReady::Query::Join

Inherits:
Object
  • Object
show all
Defined in:
lib/params_ready/query/join_clause.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(table, type, &block) ⇒ Join

Returns a new instance of Join.



8
9
10
11
12
# File 'lib/params_ready/query/join_clause.rb', line 8

def initialize(table, type, &block)
  @arel_table = table
  @type = arel_type(type)
  @statement = JoinStatement.new(&block)
end

Instance Attribute Details

#arel_tableObject (readonly)

Returns the value of attribute arel_table.



6
7
8
# File 'lib/params_ready/query/join_clause.rb', line 6

def arel_table
  @arel_table
end

#statementObject (readonly)

Returns the value of attribute statement.



6
7
8
# File 'lib/params_ready/query/join_clause.rb', line 6

def statement
  @statement
end

#typeObject (readonly)

Returns the value of attribute type.



6
7
8
# File 'lib/params_ready/query/join_clause.rb', line 6

def type
  @type
end

Instance Method Details

#arel_type(type) ⇒ Object



14
15
16
17
18
19
20
# File 'lib/params_ready/query/join_clause.rb', line 14

def arel_type(type)
  case type
  when :inner then Arel::Nodes::InnerJoin
  when :outer then Arel::Nodes::OuterJoin
  else raise ParamsReadyError, "Unimplemented join type '#{type}'"
  end
end

#to_arel(base_table, context, parameter) ⇒ Object



22
23
24
25
# File 'lib/params_ready/query/join_clause.rb', line 22

def to_arel(base_table, context, parameter)
  join_statement = @statement.to_arel(base_table, @arel_table, context, parameter)
  base_table.join(@arel_table, @type).on(join_statement)
end