class Query::Base

Attributes

arel[R]
primary_table[R]

Public Class Methods

new(primary, *args) click to toggle source
# File lib/query/base.rb, line 7
def initialize(primary, *args)
  @primary_table = _make_table(primary)

  @arel = Arel::SelectManager.new(ActiveRecord::Base).
    from(@primary_table)

  _configure(*args)
end

Public Instance Methods

_configure(*args) click to toggle source
# File lib/query/base.rb, line 51
def _configure(*args)
  # overridden by subclasses for per-query configuration
end
_make_table(value) click to toggle source
# File lib/query/base.rb, line 43
def _make_table(value)
  case value
  when Arel::Table then value
  when Arel::Nodes::TableAlias then value
  else Arel::Table.new(value)
  end
end
all() click to toggle source
# File lib/query/base.rb, line 21
def all
  arel.project(primary_table[Arel.star])
  self
end
as(name) click to toggle source

ensures as returns an Arel node, and not the Query object (so that it plays nice with our custom with method, above).

# File lib/query/base.rb, line 28
def as(name)
  arel.as(name)
end
method_missing(sym, *args, &block) click to toggle source
# File lib/query/base.rb, line 38
def method_missing(sym, *args, &block)
  arel.send(sym, *args, &block)
  self
end
reproject(*projections) click to toggle source
# File lib/query/base.rb, line 16
def reproject(*projections)
  arel.projections = projections
  self
end
to_s()
Alias for: to_sql
to_sql() click to toggle source
# File lib/query/base.rb, line 32
def to_sql
  @arel.to_sql
end
Also aliased as: to_s