Module: Filemaker::Model::Optional

Included in:
Criteria
Defined in:
lib/filemaker/model/optional.rb

Instance Method Summary collapse

Instance Method Details

#limit(value) {|options| ... } ⇒ Filemaker::Model::Criteria

Limit the number of records returned.

Parameters:

  • value (Integer)

    The number of records to return.

Yields:

  • (options)

Returns:



21
22
23
24
25
26
# File 'lib/filemaker/model/optional.rb', line 21

def limit(value)
  return self if value.nil?
  options[:max] = value.to_i
  yield options if block_given?
  self
end

#order(value) {|options| ... } ⇒ Filemaker::Model::Criteria

Order the records. Model field name will be converted to real FileMaker field name.

Examples:

Sort is position aware!

criteria.order('name desc, email')

Parameters:

  • value (String)

    The sorting string

Yields:

  • (options)

Returns:



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/filemaker/model/optional.rb', line 37

def order(value)
  return self if value.nil?
  sortfield = []
  sortorder = []
  sort_spec = value.split(',').map(&:strip)

  sort_spec.each do |spec|
    fieldname, direction = spec.split(' ')
    direction ||= 'asc'

    field = klass.find_field_by_name(fieldname)

    next unless field

    direction = 'ascend' if direction.casecmp('ASC').zero?
    direction = 'descend' if direction.casecmp('DESC').zero?

    sortfield << field.fm_name
    sortorder << direction
  end

  unless sortfield.empty?
    options[:sortfield] = sortfield
    options[:sortorder] = sortorder
  end

  yield options if block_given?

  self
end

#skip(value) {|options| ... } ⇒ Filemaker::Model::Criteria

Number of records to skip. For pagination.

Parameters:

  • value (Integer)

    The number to skip.

Yields:

  • (options)

Returns:



9
10
11
12
13
14
# File 'lib/filemaker/model/optional.rb', line 9

def skip(value)
  return self if value.nil?
  options[:skip] = value.to_i
  yield options if block_given?
  self
end