Module: ActiveRecord::Futures::FinderMethods

Extended by:
ActiveSupport::Concern
Included in:
ActiveRecord::Futures
Defined in:
lib/active_record/futures/finder_methods.rb

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#future_all(*args, &block) ⇒ Object



32
33
34
# File 'lib/active_record/futures/finder_methods.rb', line 32

def future_all(*args, &block)
  FutureArray.new(record_future(:all, *args, &block))
end

#future_find(*args, &block) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/active_record/futures/finder_methods.rb', line 6

def future_find(*args, &block)
  exec = -> { find(*args, &block) }
  query, binds = record_query do
    begin
      exec.call
    rescue RecordNotFound
      nil
    end
  end

  args = args.dup
  args.extract_options!

  # Only expect an array if a block is given, finding :all,
  # finding by id passing an array or passing multiple ids
  expects_array = block_given? || args.first == :all ||
                  args.first.kind_of?(Array) || args.size > 1

  future = Future.new(self, query, binds, exec)
  if expects_array
    FutureArray.new(future)
  else
    FutureValue.new(future)
  end
end