Class: DataMapper::Query
- Inherits:
-
Object
- Object
- DataMapper::Query
- Defined in:
- lib/dm-filemaker-adapter/core_patches.rb
Overview
Model
Instance Method Summary collapse
-
#fmp_operator(operation) ⇒ Object
Convert operation class to operator string.
-
#fmp_options(query = self) ⇒ Object
Get fmp options hash from query.
-
#to_fmp_query(input = self.conditions) ⇒ Object
Convert dm query conditions to fmp query params (hash).
Instance Method Details
#fmp_operator(operation) ⇒ Object
Convert operation class to operator string
109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/dm-filemaker-adapter/core_patches.rb', line 109 def fmp_operator(operation) case when operation[/GreaterThanOrEqualTo/]; '>=' when operation[/LessThanOrEqualTo/]; '<=' when operation[/GreaterThan/]; '>' when operation[/LessThan/]; '<' when operation[/EqualTo/]; '==' when operation[/Like/]; when operation[/Null/]; else nil end end |
#fmp_options(query = self) ⇒ Object
Get fmp options hash from query
123 124 125 126 127 128 129 130 131 132 133 134 135 136 |
# File 'lib/dm-filemaker-adapter/core_patches.rb', line 123 def (query=self) = {} [:skip_records] = query.offset if query.offset [:max_records] = query.limit if query.limit if query.order [:sort_field] = query.order.collect do |ord| ord.target.field end [:sort_order] = query.order.collect do |ord| ord.operator.to_s + 'end' end end end |
#to_fmp_query(input = self.conditions) ⇒ Object
Convert dm query conditions to fmp query params (hash)
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/dm-filemaker-adapter/core_patches.rb', line 58 def to_fmp_query(input=self.conditions) #puts "FMP_QUERY input #{input.class.name}" rslt = if input.class.name[/OrOperation/] #puts "FMP_QUERY OrOperation #{input.class}" input.operands.collect do |o| r = to_fmp_query o #puts "FMP_QUERY or-operation operand #{r}" r end elsif input.class.name[/AndOperation/] #puts "FMP_QUERY AndOperation input class #{input.class}" #puts "FMP_QUERY AndOperation input value #{input.inspect}" out = {} input.operands.each do |k,v| #puts "FMP_QUERY and-operation pre-process operand key:val #{k}:#{v}" r = to_fmp_query(k).to_hash #puts "FMP_QUERY and-operation post-process operand #{r}" if r.is_a?(Hash) #puts "FMP_QUERY and-operation operand is a hash" # Filemaker can't have the same field twice in a single find request, # but we can mash the two conditions together in a way that FMP can use. out.merge!(r){|k, oldv, newv| "#{oldv} #{newv}"} else #puts "FMP_QUERY and-operation operand is NOT a hash" out = r break end end out elsif input.class.name[/NullOperation/] || input.nil? #puts "FMP_QUERY NullOperation #{input.class}" {} else #puts "FMP_QUERY else input class #{input.class}" #puts "FMP_QUERY else input value #{input.inspect}" #puts "FMP_QUERY else-options #{self.options.inspect}" #prepare_fmp_attributes({input.subject=>input.value}, :prepend=>fmp_operator(input.class.name)) value = ( self.[input.keys[0]] || self.[input.subject.name] || self..find{|o,v| o.respond_to?(:target) && o.target.to_s == input.subject.name.to_s}[1] || input.value ) rescue input.value #(puts "ERROR #{$!}"; input.value) #puts "FMP_QUERY else-value #{value}" repository.adapter.prepare_fmp_attributes({input.subject=>value}, :prepend=>fmp_operator(input.class.name)) end #puts "FMP_QUERY output #{rslt.inspect}" rslt end |