Module: Card::Query::CardClass

Included in:
Card
Defined in:
lib/card/query/card_class.rb

Instance Method Summary collapse

Instance Method Details

#count_by_cql(spec) ⇒ Object



10
11
12
13
14
# File 'lib/card/query/card_class.rb', line 10

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

#find_each(**options, &block) ⇒ Object



16
17
18
19
20
21
22
# File 'lib/card/query/card_class.rb', line 16

def find_each **options, &block
  # 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(&block)
  end
end

#find_in_batches(**options) ⇒ Object



24
25
26
27
28
29
30
31
32
33
# File 'lib/card/query/card_class.rb', line 24

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

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



4
5
6
7
8
# File 'lib/card/query/card_class.rb', line 4

def search spec, comment=nil, &block
  results = ::Card::Query.run(spec, comment)
  results.each(&block) if block_given? && results.is_a?(Array)
  results
end