Method: Brief::DocumentMapper::Query#run_query

Defined in:
lib/brief/document_mapper.rb

#run_queryObject



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
# File 'lib/brief/document_mapper.rb', line 72

def run_query
  if query_is_empty?
    model.to_a
  else
    model.select do |obj|
      match = true

      @where.each do |selector, value|
        obj = obj.symbolize_keys if obj.is_a?(Hash)

        if obj.respond_to?(selector.attribute)
          test_value = obj.send(selector.attribute)
          operator   = OPERATOR_MAPPING[selector.operator]
          match      = false unless test_value.send(operator, value)
        elsif obj.key?(selector.attribute.to_sym)
          test_value = obj.send(:[], selector.attribute.to_sym)
          operator   = OPERATOR_MAPPING[selector.operator]
          match      = false unless test_value.send(operator, value)
        else
          match      = false
        end
      end

      match
    end
  end
end