class Bizside::QueryBuilder
Attributes
params[R]
sql[R]
Public Class Methods
new()
click to toggle source
# File lib/bizside/query_builder.rb, line 6 def initialize @sql = '' @params = [] @indent = 0 end
Public Instance Methods
and(*args) { |self| ... }
click to toggle source
# File lib/bizside/query_builder.rb, line 34 def and(*args) append_sql('and (') if block_given? @indent += 1 yield self @indent -= 1 else append(*args) end append_sql(')') end
append(*args)
click to toggle source
# File lib/bizside/query_builder.rb, line 12 def append(*args) if args.size == 1 if args[0].is_a?(Array) append(*args[0]) elsif args[0].is_a?(QueryBuilder) append(args[0].to_array) else append_sql(args[0]) end else args.each_with_index do |arg, i| if i == 0 append_sql(arg) else @params << arg end end end self end
or(*args) { |self| ... }
click to toggle source
# File lib/bizside/query_builder.rb, line 48 def or(*args) append_sql('or (') if block_given? @indent += 1 yield self @indent -= 1 else append(*args) end append_sql(')') end
to_a()
click to toggle source
# File lib/bizside/query_builder.rb, line 66 def to_a to_array end
to_array()
click to toggle source
# File lib/bizside/query_builder.rb, line 62 def to_array [@sql] + @params end
Private Instance Methods
append_sql(sql)
click to toggle source
# File lib/bizside/query_builder.rb, line 72 def append_sql(sql) @indent.times { @sql << ' ' } @sql << sql @sql << "\n" end