def query_term(term)
      # rubocop:disable Style/GuardClause
      if term.is_a?(Symbol)
        return term.to_s
      elsif term.is_a?(Integer)
        return term
      elsif term.is_a?(TrueClass)
        return term
      elsif !term.is_a?(Term)
        return "'#{term}'"
      end
      # rubocop:enable Style/GuardClause
      terms = term.args.map { |t| query_term(t) }
      case term.operator.symbol
      when :_and
        { :$and => terms }
      when :_or
        { :$or => terms }
      when :_not
        # $not currently (<=2.5.1) only supports negating equality operators.
        # so you can do { field: { $not : { [$eq,$gt,$lt,...] } }
        # but there is no way to negate an entire expression.
        # see https://jira.mongodb.org/browse/SERVER-10708
        { :$nor => terms }
      when :_equal
        { term.args[0] => stringify(term.args[1]) }
      when :_not_equal
        { term.args[0] => { :$ne => stringify(term.args[1]) } }
      when :_match
        { term.args[0] => { :$regex => term.args[1].to_s } }
      when :_in
        { term.args[0] => { :$in => term.args[1] } }
      when :_greater
        { term.args[0] => { :$gt => term.args[1] } }
      when :_greater_or_equal
        { term.args[0] => { :$gte => term.args[1] } }
      when :_less
        { term.args[0] => { :$lt => term.args[1] } }
      when :_less_or_equal
        { term.args[0] => { :$lte => term.args[1] } }
      else
        raise "can't handle operator '#{term.operator}' yet"
      end
    end
def query_term(term)
      # rubocop:disable Style/GuardClause
      if term.is_a?(Symbol)
        return term.to_s
      elsif term.is_a?(Integer)
        return term
      elsif term.is_a?(TrueClass)
        return term
      elsif !term.is_a?(Term)
        return "'#{term}'"
      end
      # rubocop:enable Style/GuardClause
      terms = term.args.map { |t| query_term(t) }
      case term.operator.symbol
      when :_and
        { :$and => terms }
      when :_or
        { :$or => terms }
      when :_not
        # $not currently (<=2.5.1) only supports negating equality operators.
        # so you can do { field: { $not : { [$eq,$gt,$lt,...] } }
        # but there is no way to negate an entire expression.
        # see https://jira.mongodb.org/browse/SERVER-10708
        { :$nor => terms }
      when :_equal
        { term.args[0] => stringify(term.args[1]) }
      when :_not_equal
        { term.args[0] => { :$ne => stringify(term.args[1]) } }
      when :_match
        { term.args[0] => { :$regex => term.args[1].to_s } }
      when :_in
        { term.args[0] => { :$in => term.args[1] } }
      when :_greater
        { term.args[0] => { :$gt => term.args[1] } }
      when :_greater_or_equal
        { term.args[0] => { :$gte => term.args[1] } }
      when :_less
        { term.args[0] => { :$lt => term.args[1] } }
      when :_less_or_equal
        { term.args[0] => { :$lte => term.args[1] } }
      else
        raise "can't handle operator '#{term.operator}' yet"
      end
    end
rubocop:disable Metrics/PerceivedComplexity,Metrics/CyclomaticComplexity,Metrics/AbcSize
 rubocop:disable Metrics/MethodLength