Module: Card::Set::All::Collection::ClassMethods

Defined in:
tmpsets/set/mod001-01_core/all/collection.rb

Overview

~~~~~~~~~~~ above autogenerated; below pulled from /Users/ethan/dev/wagn/gem/card/mod/01_core/set/all/collection.rb ~~~~~~~~~~~

Instance Method Summary collapse

Instance Method Details

#count_by_wql(spec) ⇒ Object



14
15
16
17
18
# File 'tmpsets/set/mod001-01_core/all/collection.rb', line 14

def count_by_wql(spec)
  spec = spec.clone
  spec.delete(:offset)
  search spec.merge(return: 'count')
end

#find_each(options = {}) ⇒ Object



20
21
22
23
24
25
# File 'tmpsets/set/mod001-01_core/all/collection.rb', line 20

def find_each(options = {})
  #this is a copy from rails (3.2.16) and is needed because this is performed by a relation (ActiveRecord::Relation)
  find_in_batches(options) do |records|
    records.each { |record| yield record }
  end
end

#find_in_batches(options = {}) ⇒ Object



27
28
29
30
31
32
33
34
35
36
# File 'tmpsets/set/mod001-01_core/all/collection.rb', line 27

def find_in_batches(options = {})
  if block_given?
    super(options) do |records|
      yield(records)
      Card::Cache.reset_global
    end
  else
    super(options)
  end
end

#search(spec) ⇒ Object



6
7
8
9
10
11
12
# File 'tmpsets/set/mod001-01_core/all/collection.rb', line 6

def search spec
  results = ::Card::Query.run(spec)
  if block_given? and Array===results
    results.each { |result| yield result }
  end
  results
end