Class: Filemaker::Model::Criteria

Inherits:
Object
  • Object
show all
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

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

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
  @options  = {}
  @chains   = []
  @_page    = 1
end

Instance Attribute Details

#chainsArray (readonly)

Returns keep track of where clause and in clause to not mix them.

Returns:

  • (Array)

    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

#klassFilemaker::Model (readonly)

Returns the class of the model.

Returns:



19
20
21
# File 'lib/filemaker/model/criteria.rb', line 19

def klass
  @klass
end

#optionsHash (readonly)

Returns options like skip, limit and order.

Returns:

  • (Hash)

    options like skip, limit and order



25
26
27
# File 'lib/filemaker/model/criteria.rb', line 25

def options
  @options
end

#selectorHash. Array (readonly)

Returns represents the query arguments.

Returns:

  • (Hash. Array)

    represents the query arguments



22
23
24
# File 'lib/filemaker/model/criteria.rb', line 22

def selector
  @selector
end

Instance Method Details

#allObject



49
50
51
# File 'lib/filemaker/model/criteria.rb', line 49

def all
  execute
end

#countInteger

The count this criteria is capable of returning

Returns:

  • (Integer)

    the count



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

#eachObject



41
42
43
# File 'lib/filemaker/model/criteria.rb', line 41

def each
  execute.each { |record| yield record } if block_given?
end

#firstObject



45
46
47
# File 'lib/filemaker/model/criteria.rb', line 45

def first
  limit(1).execute.first
end

#limit?Boolean

Returns:

  • (Boolean)


53
54
55
# File 'lib/filemaker/model/criteria.rb', line 53

def limit?
  !options[:max].nil?
end

#to_sObject



37
38
39
# File 'lib/filemaker/model/criteria.rb', line 37

def to_s
  "#{selector}, #{options}"
end