class Mashery::QueryBuilder

Public Class Methods

new(klass = nil, options = {}) click to toggle source
# File lib/mashery/query_builder.rb, line 3
def initialize(klass = nil, options = {})
  @klass      = klass
  @options    = options
  @conditions = Where.new
  @select     = Select.new
end

Public Instance Methods

all() click to toggle source
# File lib/mashery/query_builder.rb, line 57
def all
  Mashery::RpcClient::Response.new(self)
end
find_each(&block) click to toggle source
# File lib/mashery/query_builder.rb, line 61
def find_each(&block)
  Mashery::RpcClient::Response.new(self).find_each(&block)
end
first() click to toggle source
# File lib/mashery/query_builder.rb, line 65
def first
  Mashery::RpcClient::Response.new(items(1)).to_objects.first
end
from(argument) click to toggle source
# File lib/mashery/query_builder.rb, line 15
def from(argument)
  @from = From.new(argument)
  clone
end
items(argument) click to toggle source
# File lib/mashery/query_builder.rb, line 30
def items(argument)
  @items = Items.new(argument)
  clone
end
order(column, order) click to toggle source
# File lib/mashery/query_builder.rb, line 25
def order(column, order)
  @order = Order.new(column, order)
  clone
end
page(argument) click to toggle source
# File lib/mashery/query_builder.rb, line 35
def page(argument)
  @page = Page.new(argument)
  clone
end
query() click to toggle source
# File lib/mashery/query_builder.rb, line 40
def query
  [@select, @from, @order, @conditions, @page, @items].map(&:to_s).reject {|s|
    s.blank?
  }.compact.join(" ").strip
end
Also aliased as: to_s
reify(*args) click to toggle source
# File lib/mashery/query_builder.rb, line 46
def reify(*args)
  raise NoClassGiven.new if @klass.blank?
  @klass.new(*args)
end
select(argument) click to toggle source
# File lib/mashery/query_builder.rb, line 10
def select(argument)
  @select = Select.new(argument)
  clone
end
to_json() click to toggle source
# File lib/mashery/query_builder.rb, line 53
def to_json
  Mashery.rpc.query(query)
end
to_s()
Alias for: query
where(argument) click to toggle source
# File lib/mashery/query_builder.rb, line 20
def where(argument)
  @conditions.add argument
  clone
end