Class: BB::Builder

Inherits:
Object
  • Object
show all
Defined in:
lib/b_b/builder.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeBuilder

Returns a new instance of Builder.



8
9
10
11
# File 'lib/b_b/builder.rb', line 8

def initialize
  @joins   = []
  @options = {}
end

Instance Attribute Details

#fromObject (readonly)

Returns the value of attribute from.



3
4
5
# File 'lib/b_b/builder.rb', line 3

def from
  @from
end

#groupObject (readonly)

Returns the value of attribute group.



3
4
5
# File 'lib/b_b/builder.rb', line 3

def group
  @group
end

#group_eachObject (readonly)

Returns the value of attribute group_each.



3
4
5
# File 'lib/b_b/builder.rb', line 3

def group_each
  @group_each
end

#havingObject (readonly)

Returns the value of attribute having.



3
4
5
# File 'lib/b_b/builder.rb', line 3

def having
  @having
end

#joinsObject (readonly)

Returns the value of attribute joins.



3
4
5
# File 'lib/b_b/builder.rb', line 3

def joins
  @joins
end

#limitObject (readonly)

Returns the value of attribute limit.



3
4
5
# File 'lib/b_b/builder.rb', line 3

def limit
  @limit
end

#omit_record_ifObject (readonly)

Returns the value of attribute omit_record_if.



3
4
5
# File 'lib/b_b/builder.rb', line 3

def omit_record_if
  @omit_record_if
end

#optionsObject

Returns the value of attribute options.



6
7
8
# File 'lib/b_b/builder.rb', line 6

def options
  @options
end

#orderObject (readonly)

Returns the value of attribute order.



3
4
5
# File 'lib/b_b/builder.rb', line 3

def order
  @order
end

#selectObject (readonly)

Returns the value of attribute select.



3
4
5
# File 'lib/b_b/builder.rb', line 3

def select
  @select
end

#whereObject (readonly)

Returns the value of attribute where.



3
4
5
# File 'lib/b_b/builder.rb', line 3

def where
  @where
end

Instance Method Details

#add_offset_to_limit(offset) ⇒ Object



36
37
38
39
40
# File 'lib/b_b/builder.rb', line 36

def add_offset_to_limit(offset)
  return if limit.nil?

  limit.options[:offset] = offset
end

#add_option_to_just_before_join(rel) ⇒ Object



30
31
32
33
34
# File 'lib/b_b/builder.rb', line 30

def add_option_to_just_before_join(rel)
  return if joins.empty?

  joins.last.options[:rel] = rel
end

#append_joins(name) ⇒ Object



23
24
25
26
27
28
# File 'lib/b_b/builder.rb', line 23

def append_joins(name)
  register_factory(name).tap do |factory|
    append_options!(factory)
    joins << factory
  end
end

#assign(name) ⇒ Object



17
18
19
20
21
# File 'lib/b_b/builder.rb', line 17

def assign(name)
  get_factory_ivar(name).tap do |factory|
    append_options!(factory)
  end
end

#buildObject



13
14
15
# File 'lib/b_b/builder.rb', line 13

def build
  structure.flatten.compact.map(&:build).join(" ")
end