Class: Filemaker::Model::Criteria
Overview
Criteria encapsulates query arguments and options to represent a single query. It has convenient query DSL like where and in to represent both -find and -findquery FileMaker query. On top of that you can negate any query with the not clause to omit selection.
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods included from Pagination
#__page, #__per, #page, #per, #update_skip
Methods included from Optional
#limit, #order, #skip
Methods included from Selectable
#find, #in, #not_in, #or, #recid, #where
Constructor Details
#initialize(klass) ⇒ Criteria
30
31
32
33
34
35
|
# File 'lib/filemaker/model/criteria.rb', line 30
def initialize(klass)
@klass = klass
@options = {}
@chains = []
@_page = 1
end
|
Instance Attribute Details
#chains ⇒ Array
28
29
30
|
# File 'lib/filemaker/model/criteria.rb', line 28
def chains
@chains
end
|
19
20
21
|
# File 'lib/filemaker/model/criteria.rb', line 19
def klass
@klass
end
|
#options ⇒ Hash
25
26
27
|
# File 'lib/filemaker/model/criteria.rb', line 25
def options
@options
end
|
#selector ⇒ Hash. Array
22
23
24
|
# File 'lib/filemaker/model/criteria.rb', line 22
def selector
@selector
end
|
Instance Method Details
#all ⇒ Object
49
50
51
|
# File 'lib/filemaker/model/criteria.rb', line 49
def all
execute
end
|
#count ⇒ Integer
The count this criteria is capable of returning
60
61
62
63
64
65
66
67
68
69
|
# File 'lib/filemaker/model/criteria.rb', line 60
def count
limit(0)
if chains.include?(:where)
klass.api.find(selector, options).count
elsif chains.include?(:in)
klass.api.query(selector, options).count
else
klass.api.findall(options).count
end
end
|
#each ⇒ Object
41
42
43
|
# File 'lib/filemaker/model/criteria.rb', line 41
def each
execute.each { |record| yield record } if block_given?
end
|
#first ⇒ Object
45
46
47
|
# File 'lib/filemaker/model/criteria.rb', line 45
def first
limit(1).execute.first
end
|
#limit? ⇒ Boolean
53
54
55
|
# File 'lib/filemaker/model/criteria.rb', line 53
def limit?
!options[:max].nil?
end
|
#to_s ⇒ Object
37
38
39
|
# File 'lib/filemaker/model/criteria.rb', line 37
def to_s
"#{selector}, #{options}"
end
|