module Upmin::DataMapper::Query
Public Instance Methods
results()
click to toggle source
# File lib/upmin/data_mapper/query.rb, line 4 def results return klass.model_class.all(prepared_search) end
Private Instance Methods
create_operator(key)
click to toggle source
# File lib/upmin/data_mapper/query.rb, line 27 def create_operator(key) if m = key.to_s.match(/(.*)_(#{valid_suffixes.join("|")})/) target = m.captures.first operator = operator_for(m.captures.second) return DataMapper::Query::Operator.new(target, operator) else return nil end end
operator_for(suffix)
click to toggle source
# File lib/upmin/data_mapper/query.rb, line 45 def operator_for(suffix) op_map = { gteq: :gte, lteq: :lte, cont: :like } return op_map[suffix.to_sym] end
prepared_search()
click to toggle source
# File lib/upmin/data_mapper/query.rb, line 10 def prepared_search return @prepared_search if defined?(@prepared_search) @prepared_search = {} if search_options search_options.each do |key, value| next if value.empty? if op = create_operator(key) @prepared_search[op] = value else raise InvalidSearchSuffix.new(key) end end end return @prepared_search end
valid_suffixes()
click to toggle source
# File lib/upmin/data_mapper/query.rb, line 37 def valid_suffixes return [ :gteq, :lteq, :cont ] end