class Gimlet::Queryable::Query

Public Class Methods

new(model) click to toggle source
# File lib/gimlet/queryable.rb, line 29
def initialize(model)
  @model = model
  @where = []
end

Public Instance Methods

all() click to toggle source
# File lib/gimlet/queryable.rb, line 48
def all
  @model.select(:where => @where)
end
method_missing(method, *args, &block) click to toggle source
Calls superclass method
# File lib/gimlet/queryable.rb, line 52
def method_missing(method, *args, &block)
  if @model.respond_to?(method)
    scoping { @model.send(method, *args, &block) }
  else
    super
  end
end
scoping() { || ... } click to toggle source
# File lib/gimlet/queryable.rb, line 60
def scoping
  previous, @model.current_scope = @model.current_scope, self
  yield
ensure
  @model.current_scope = previous
end
where(hash) click to toggle source
# File lib/gimlet/queryable.rb, line 34
def where(hash)
  hash.each do |attribute, value|
    case value
    when Array
      @where.push([attribute, :in?, value]) # should be :== ?
    when Regexp
      @where.push([attribute, :=~, value])
    else
      @where.push([attribute, :==, value])
    end
  end
  self
end