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

Defined in:
card/tmpsets/set/mod002-core/all/collection.rb

Instance Method Summary collapse

Instance Method Details

#count_by_cql(spec) ⇒ Object



18
19
20
21
22
# File 'card/tmpsets/set/mod002-core/all/collection.rb', line 18

def count_by_cql spec
  spec = spec.clone
  spec.delete(:offset)
  search spec.merge(return: "count")
end

#find_each(options = {}, &block) ⇒ Object



24
25
26
27
28
29
30
# File 'card/tmpsets/set/mod002-core/all/collection.rb', line 24

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



32
33
34
35
36
37
38
39
40
41
# File 'card/tmpsets/set/mod002-core/all/collection.rb', line 32

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

#search(spec, comment = nil, &block) ⇒ Object



10
11
12
13
14
15
16
# File 'card/tmpsets/set/mod002-core/all/collection.rb', line 10

def search spec, comment=nil
  results = ::Card::Query.run(spec, comment)
  if block_given? && results.is_a?(Array)
    results.each { |result| yield result }
  end
  results
end