Module: Card::Query::CardClass

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

Overview

query-related methods with which to extend Card class

Instance Method Summary collapse

Instance Method Details

#count_by_cql(spec) ⇒ Object



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

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

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



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

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



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

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

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



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

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