Sha256: f1f477d23f92c6ccdcde8f2a40ac7abace15624addd43bbb7b7e503afdcbcd88

Contents?: true

Size: 913 Bytes

Versions: 5

Compression:

Stored size: 913 Bytes

Contents

module Ransack
  class Visitor
    def visit_and(object)
      nodes = object.values.map { |o| accept(o) }.compact
      return nil unless nodes.size > 0

      if nodes.size > 1
        Arel::Nodes::Grouping.new(Arel::Nodes::And.new(nodes))
      else
        nodes.first
      end
    end

    def quoted?(object)
      case object
      when Arel::Nodes::SqlLiteral, Bignum, Fixnum
        false
      else
        true
      end
    end

    def visit_Ransack_Nodes_Sort(object)
      return unless object.valid?
      if object.attr.is_a?(Arel::Attributes::Attribute)
        object.attr.send(object.dir)
      else
        ordered(object)
      end
    end

    private

      def ordered(object)
        case object.dir
        when 'asc'.freeze
          Arel::Nodes::Ascending.new(object.attr)
        when 'desc'.freeze
          Arel::Nodes::Descending.new(object.attr)
        end
      end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
ransack-1.8.10 lib/ransack/adapters/active_record/ransack/visitor.rb
ransack-2.0.1 lib/ransack/adapters/active_record/ransack/visitor.rb
ransack-2.0.0 lib/ransack/adapters/active_record/ransack/visitor.rb
ransack-1.8.9 lib/ransack/adapters/active_record/ransack/visitor.rb
ransack-1.8.8 lib/ransack/adapters/active_record/ransack/visitor.rb