Class: Filemaker::Model::Criteria
- Inherits:
-
Object
- Object
- Filemaker::Model::Criteria
- Includes:
- Enumerable, Optional, Pagination, Selectable
- Defined in:
- lib/filemaker/model/criteria.rb
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
-
#chains ⇒ Array
readonly
Keep track of where clause and in clause to not mix them.
-
#klass ⇒ Filemaker::Model
readonly
The class of the model.
-
#options ⇒ Hash
readonly
Options like skip, limit and order.
-
#selector ⇒ Hash. Array
readonly
Represents the query arguments.
Instance Method Summary collapse
- #all ⇒ Object
-
#count ⇒ Integer
The count this criteria is capable of returning.
- #each ⇒ Object
- #first ⇒ Object
-
#initialize(klass) ⇒ Criteria
constructor
A new instance of Criteria.
- #limit? ⇒ Boolean
- #to_s ⇒ Object
Methods included from Pagination
#__page, #__per, #page, #per, #update_skip
Methods included from Optional
Methods included from Selectable
#find, #in, #not_in, #or, #recid, #where
Constructor Details
#initialize(klass) ⇒ Criteria
Returns a new instance of Criteria.
30 31 32 33 34 35 |
# File 'lib/filemaker/model/criteria.rb', line 30 def initialize(klass) @klass = klass = {} @chains = [] @_page = 1 end |
Instance Attribute Details
#chains ⇒ Array (readonly)
Returns keep track of where clause and in clause to not mix them.
28 29 30 |
# File 'lib/filemaker/model/criteria.rb', line 28 def chains @chains end |
#klass ⇒ Filemaker::Model (readonly)
Returns the class of the model.
19 20 21 |
# File 'lib/filemaker/model/criteria.rb', line 19 def klass @klass end |
#options ⇒ Hash (readonly)
Returns options like skip, limit and order.
25 26 27 |
# File 'lib/filemaker/model/criteria.rb', line 25 def end |
#selector ⇒ Hash. Array (readonly)
Returns represents the query arguments.
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, ).count elsif chains.include?(:in) klass.api.query(selector, ).count else klass.api.findall().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? ![:max].nil? end |
#to_s ⇒ Object
37 38 39 |
# File 'lib/filemaker/model/criteria.rb', line 37 def to_s "#{selector}, #{options}" end |