Module: Cardiac::Model::Querying::ClassMethods

Defined in:
lib/cardiac/model/querying.rb

Instance Method Summary collapse

Instance Method Details

#allObject

This is a basic implementation that just delegates to find_all.



12
13
14
# File 'lib/cardiac/model/querying.rb', line 12

def all
  find_all
end

#find(criteria = :all, *args, &evaluator) ⇒ Object

Simple pattern for delegating find operations to the resource. This is pretty similar to earlier AR versions that did not proxy to Relation.

The biggest difference is that all finder methods accept an evaluator block allowing bulk operations to be performed on returned results.



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/cardiac/model/querying.rb', line 21

def find(criteria=:all,*args,&evaluator)
  case criteria
  when :all, :first, :some, :one
    send(:"find_#{criteria}", *args, &evaluator)
  when Hash
    find_all(*args.unshift(criteria), &evaluator)
  when Array
    find_with_ids(criteria, &evaluator)
  when self, Numeric, String
    find_one(criteria, &evaluator)
  when Model::Base
    find_one(criteria.id, &evaluator)
  else
    raise ArgumentError, "unsupported finder criteria: #{criteria}:#{criteria.class}"
  end
end