class Minidusen::Syntax

Constants

NONE

Public Class Methods

new() click to toggle source
# File lib/minidusen/syntax.rb, line 4
def initialize
  @scopers = {}
end

Public Instance Methods

fields() click to toggle source
# File lib/minidusen/syntax.rb, line 23
def fields
  @scopers
end
learn_field(field, &scoper) click to toggle source
# File lib/minidusen/syntax.rb, line 8
def learn_field(field, &scoper)
  field = field.to_s
  @scopers[field] = scoper
end
parse(query) click to toggle source
# File lib/minidusen/syntax.rb, line 27
def parse(query)
  Parser.parse(query)
end

Private Instance Methods

append_excludes(instance, matches, exclude_query) click to toggle source
# File lib/minidusen/syntax.rb, line 46
def append_excludes(instance, matches, exclude_query)
  excluded_records = apply_query(instance, matches.origin_class, exclude_query)
  qualified_id_field = Util.qualify_column_name(excluded_records, excluded_records.primary_key)
  exclude_sql = "#{qualified_id_field} NOT IN (#{excluded_records.select(qualified_id_field).to_sql})"
  matches.where(exclude_sql)
end
apply_query(instance, root_scope, query) click to toggle source
# File lib/minidusen/syntax.rb, line 37
def apply_query(instance, root_scope, query)
  scope = root_scope
  query.each do |token|
    scoper = @scopers[token.field] || NONE
    scope = instance.instance_exec(scope, token.value, &scoper)
  end
  scope
end