module Rethinker::Selection::Core

Attributes

context[RW]
criteria[RW]

Public Class Methods

new(criteria = [], context = {}) click to toggle source
# File lib/rethinker/selection/core.rb, line 9
def initialize(criteria = [], context = {})
  # We are saving klass as a context
  # so that the table_on_demand middleware can do its job
  # TODO FIXME Sadly it gets funny with associations
  self.context = context
  self.criteria = [criteria].flatten
  self
end

Public Instance Methods

chain(criterion) click to toggle source
# File lib/rethinker/selection/core.rb, line 22
def chain(criterion)
  self.criteria.concat([criterion]).flatten! unless criterion.blank?
  self
end
klass() click to toggle source
# File lib/rethinker/selection/core.rb, line 18
def klass
  context[:klass]
end
query() click to toggle source
# File lib/rethinker/selection/core.rb, line 31
def query
  chained_query = nil
  self.criteria.each do |criterion|
    chained_query = criterion.execute(chained_query, self.context)
  end
  chained_query
end
run() click to toggle source
# File lib/rethinker/selection/core.rb, line 27
def run
  Rethinker.run { self.query }
end