class Rectify::Query

Public Class Methods

merge(*queries) click to toggle source
# File lib/rectify/query.rb, line 5
def self.merge(*queries)
  queries.reduce(NullQuery.new) { |a, e| a.merge(e) }
end
new(scope = ActiveRecord::NullRelation) click to toggle source
# File lib/rectify/query.rb, line 9
def initialize(scope = ActiveRecord::NullRelation)
  @scope = scope
end

Public Instance Methods

cached_query() click to toggle source
# File lib/rectify/query.rb, line 65
def cached_query
  @cached_query ||= query
end
count() click to toggle source
# File lib/rectify/query.rb, line 29
def count
  cached_query.count
end
each(&block) click to toggle source
# File lib/rectify/query.rb, line 37
def each(&block)
  cached_query.each(&block)
end
eager?() click to toggle source
# File lib/rectify/query.rb, line 61
def eager?
  cached_query.is_a?(Array)
end
exists?() click to toggle source
# File lib/rectify/query.rb, line 41
def exists?
  return cached_query.exists? if relation?

  cached_query.present?
end
first() click to toggle source
# File lib/rectify/query.rb, line 33
def first
  cached_query.first
end
merge(other)
Alias for: |
none?() click to toggle source
# File lib/rectify/query.rb, line 47
def none?
  !exists?
end
query() click to toggle source
# File lib/rectify/query.rb, line 13
def query
  @scope
end
relation?() click to toggle source
# File lib/rectify/query.rb, line 57
def relation?
  cached_query.is_a?(ActiveRecord::Relation)
end
to_a() click to toggle source
# File lib/rectify/query.rb, line 51
def to_a
  cached_query.to_a
end
Also aliased as: to_ary
to_ary()
Alias for: to_a
|(other) click to toggle source
# File lib/rectify/query.rb, line 17
def |(other)
  if relation? && other.relation?
    Rectify::Query.new(cached_query.merge(other.cached_query))
  elsif eager? && other.eager?
    Rectify::Query.new(cached_query | other.cached_query)
  else
    raise UnableToComposeQueries.new(self, other)
  end
end
Also aliased as: merge