Sha256: 1fbfa45fa9a76ec083b9b23c727e12012e60cb629669172fd3e354767d5b3053

Contents?: true

Size: 1.04 KB

Versions: 17

Compression:

Stored size: 1.04 KB

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)
      if object.valid?
        if object.attr.is_a?(Arel::Attributes::Attribute)
          object.attr.send(object.dir)
        else
          ordered(object)
        end
      else
        scope_name = :"sort_by_#{object.name}_#{object.dir}"
        scope_name if object.context.object.respond_to?(scope_name)
      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

17 entries across 17 versions & 2 rubygems

Version Path
ransack-3.2.1 lib/ransack/adapters/active_record/ransack/visitor.rb
ransack-3.2.0 lib/ransack/adapters/active_record/ransack/visitor.rb
ransack-3.1.0 lib/ransack/adapters/active_record/ransack/visitor.rb
ransack-3.0.1 lib/ransack/adapters/active_record/ransack/visitor.rb
ransack-3.0.0 lib/ransack/adapters/active_record/ransack/visitor.rb
ransack-2.6.0 lib/ransack/adapters/active_record/ransack/visitor.rb
ransack-2.5.0 lib/ransack/adapters/active_record/ransack/visitor.rb
date_n_time_picker_activeadmin-0.1.2 vendor/bundle/ruby/2.6.0/gems/ransack-2.4.2/lib/ransack/adapters/active_record/ransack/visitor.rb
date_n_time_picker_activeadmin-0.1.1 vendor/bundle/ruby/2.6.0/gems/ransack-2.4.2/lib/ransack/adapters/active_record/ransack/visitor.rb
ransack-2.4.2 lib/ransack/adapters/active_record/ransack/visitor.rb
ransack-2.4.1 lib/ransack/adapters/active_record/ransack/visitor.rb
ransack-2.4.0 lib/ransack/adapters/active_record/ransack/visitor.rb
ransack-2.3.2 lib/ransack/adapters/active_record/ransack/visitor.rb
ransack-2.3.1 lib/ransack/adapters/active_record/ransack/visitor.rb
ransack-2.3.0 lib/ransack/adapters/active_record/ransack/visitor.rb
ransack-2.1.1 lib/ransack/adapters/active_record/ransack/visitor.rb
ransack-2.1.0 lib/ransack/adapters/active_record/ransack/visitor.rb