ruby search_params.rb

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ruby search_params.rb相关的知识,希望对你有一定的参考价值。

    def search_param_datetime(query: nil, attribute_key: nil, attribute_array: [])
      fail 'Must have a valid query' if query.nil?
      fail 'Must have a valid attribute key' if attribute_key.nil?

      logger.debug "[Search param DateTime] Searching #{attribute_key} -> #{attribute_array.to_json}"

      if attribute_array.nil? || attribute_array.empty?
        logger.debug "[Search param DateTime] Backing out of filter - no values exist for #{attribute_key}"
        return query
      end

      attribute_array.each do |attrs|
        attrs.each do |attr|
          attr = attr.to_a.flatten
          logger.debug "[Search param DateTime] Filtering by #{attribute_key} #{attr.first} #{attr.last}"
          case attr.first
          when 'before'
            query = query.where(query.model.arel_table[attribute_key.to_sym].lt(attr.last))
          when 'after'
            query = query.where(query.model.arel_table[attribute_key.to_sym].gt(attr.last))
          when 'on'
            query = query.where(attribute_key => (attr.last..attr.last.end_of_day))
          end
        end
      end

      @queries += 1
      query
    end

以上是关于ruby search_params.rb的主要内容,如果未能解决你的问题,请参考以下文章

Ruby运算符

Ruby 25 岁了!Ruby 之父说 Ruby 3 有望 3 倍提速

如何学习ruby?Ruby学习技巧分享

ruby Ruby脚本,看看是否用openssl编译了ruby

什么是ruby?

ruby和ruby ee