Module: NoBrainer::Document::Criteria::ClassMethods

Defined in:
lib/no_brainer/document/criteria.rb

Instance Method Summary collapse

Instance Method Details

#allObject



38
39
40
41
# File 'lib/no_brainer/document/criteria.rb', line 38

def all
  NoBrainer::Criteria.new(:initial_run_options => NoBrainer.current_run_options,
                          :model => self)
end

#default_scope(criteria = nil, &block) ⇒ Object



51
52
53
54
55
56
57
58
# File 'lib/no_brainer/document/criteria.rb', line 51

def default_scope(criteria=nil, &block)
  criteria_proc = block || (criteria.is_a?(Proc) ? criteria : proc { criteria })
  raise "default_scope only accepts a criteria or a proc that returns criteria" unless criteria_proc.is_a?(Proc)

  subclass_tree.each do |subclass|
    subclass.default_scopes << criteria_proc
  end
end

#disable_perf_warningsObject



65
66
67
# File 'lib/no_brainer/document/criteria.rb', line 65

def disable_perf_warnings
  self.perf_warnings_disabled = true
end

#inherited(subclass) ⇒ Object



60
61
62
63
# File 'lib/no_brainer/document/criteria.rb', line 60

def inherited(subclass)
  subclass.default_scopes = self.default_scopes.dup
  super
end

#scope(name, criteria = nil, &block) ⇒ Object



43
44
45
46
47
48
49
# File 'lib/no_brainer/document/criteria.rb', line 43

def scope(name, criteria=nil, &block)
  criteria ||= block
  criteria_proc = criteria.is_a?(Proc) ? criteria : proc { criteria }
  singleton_class.class_eval do
    define_method(name) { |*args| criteria_proc.call(*args) }
  end
end