module NoBrainer::Criteria::Core

Attributes

options[RW]

Public Class Methods

new(options={}) click to toggle source
# File lib/no_brainer/criteria/core.rb, line 13
def initialize(options={})
  @options = options
end

Public Instance Methods

==(other) click to toggle source
Calls superclass method
# File lib/no_brainer/criteria/core.rb, line 48
def ==(other)
  return to_a == other if other.is_a?(Array)
  super
end
dup() click to toggle source
# File lib/no_brainer/criteria/core.rb, line 17
def dup
  # We don't keep any of the instance variables except options.
  self.class.new(@options.dup)
end
inspect() click to toggle source
# File lib/no_brainer/criteria/core.rb, line 30
def inspect
  # rescue super because sometimes model is not set.
  to_rql.inspect rescue super
end
merge(criteria, options={}) click to toggle source
# File lib/no_brainer/criteria/core.rb, line 44
def merge(criteria, options={})
  dup.merge!(criteria, options)
end
merge!(criteria, options={}) click to toggle source
# File lib/no_brainer/criteria/core.rb, line 35
def merge!(criteria, options={})
  criteria.options.each do |k,v|
    merge_proc = self.class.options_definitions[k]
    raise "Non declared option: #{k}" unless merge_proc
    @options[k] = merge_proc.call(@options[k], v)
  end
  self
end
model() click to toggle source
# File lib/no_brainer/criteria/core.rb, line 22
def model
  @options[:model]
end
to_rql() click to toggle source
# File lib/no_brainer/criteria/core.rb, line 26
def to_rql
  finalized_criteria.__send__(:compile_rql_pass2)
end

Private Instance Methods

chain(options={}, merge_options={}) click to toggle source
# File lib/no_brainer/criteria/core.rb, line 55
def chain(options={}, merge_options={})
  merge(self.class.new(options), merge_options)
end
compile_rql_pass1() click to toggle source
# File lib/no_brainer/criteria/core.rb, line 59
def compile_rql_pass1
  # This method is overriden by other modules.
  raise "Criteria not bound to a model" unless model
  model.rql_table
end
compile_rql_pass2() click to toggle source
# File lib/no_brainer/criteria/core.rb, line 65
def compile_rql_pass2
  # This method is overriden by other modules.
  compile_rql_pass1
end
finalized?() click to toggle source
# File lib/no_brainer/criteria/core.rb, line 70
def finalized?
  !!@options[:finalized]
end
finalized_criteria() click to toggle source
# File lib/no_brainer/criteria/core.rb, line 74
def finalized_criteria
  @finalized_criteria ||= finalized? ? self : self.class._finalize_criteria(self)
end