Class: ParamsReady::Query::Join::Builder

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

Instance Method Summary collapse

Constructor Details

#initialize(&block) ⇒ Builder

Returns a new instance of Builder.



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

def initialize(&block)
  @block = block
  @statement_builder = nil
  @only_if = nil
end

Instance Method Details

#buildObject

Raises:



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

def build
  instance_eval(&@block)
  @block = nil
  raise ParamsReadyError, 'Join statement must be present' if @statement_builder.nil?
  [@statement_builder.build, @only_if]
end

#on(expression, arel_table: nil) ⇒ Object



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

def on(expression, arel_table: nil)
  @statement_builder ||= JoinStatement::Builder.new
  @statement_builder.on(expression, arel_table: arel_table)
end

#only_if(&block) ⇒ Object



26
27
28
29
# File 'lib/params_ready/query/join_clause.rb', line 26

def only_if(&block)
  @only_if = block
  nil
end