Sha256: 2c3c1e2ee480546e9a055d734bf224b6c8d73d0746090c6873fd0a6da61ce7a0

Contents?: true

Size: 1.32 KB

Versions: 15

Compression:

Stored size: 1.32 KB

Contents

# frozen-string-literal: true
module Mobility
  module Arel
    class Visitor < ::Arel::Visitors::Visitor
      INNER_JOIN = ::Arel::Nodes::InnerJoin
      OUTER_JOIN = ::Arel::Nodes::OuterJoin

      attr_reader :backend_class, :locale

      def initialize(backend_class, locale)
        super()
        @backend_class, @locale = backend_class, locale
      end

      private

      def visit(object)
        super
      rescue TypeError
        visit_default(object)
      end

      def visit_collection(_objects)
        raise NotImplementedError
      end
      alias :visit_Array :visit_collection

      def visit_Arel_Nodes_Unary(object)
        visit(object.expr)
      end

      def visit_Arel_Nodes_Binary(object)
        visit_collection([object.left, object.right])
      end

      def visit_Arel_Nodes_Function(object)
        visit_collection(object.expressions)
      end

      def visit_Arel_Nodes_Case(object)
        visit_collection([object.case, object.conditions, object.default])
      end

      def visit_Arel_Nodes_And(object)
        visit_Array(object.children)
      end

      def visit_Arel_Nodes_Node(object)
        visit_default(object)
      end

      def visit_Arel_Attributes_Attribute(object)
        visit_default(object)
      end

      def visit_default(_object)
        nil
      end
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
mobility-0.8.7 lib/mobility/arel/visitor.rb
mobility-0.8.6 lib/mobility/arel/visitor.rb
mobility-0.8.5 lib/mobility/arel/visitor.rb
mobility-0.8.4 lib/mobility/arel/visitor.rb
mobility-0.8.3 lib/mobility/arel/visitor.rb
mobility-0.8.2 lib/mobility/arel/visitor.rb
mobility-0.8.1 lib/mobility/arel/visitor.rb
mobility-0.8.0 lib/mobility/arel/visitor.rb
mobility-0.7.6 lib/mobility/arel/visitor.rb
mobility-0.7.5 lib/mobility/arel/visitor.rb
mobility-0.7.4 lib/mobility/arel/visitor.rb
mobility-0.7.3 lib/mobility/arel/visitor.rb
mobility-0.7.2 lib/mobility/arel/visitor.rb
mobility-0.7.1 lib/mobility/arel/visitor.rb
mobility-0.7.0 lib/mobility/arel/visitor.rb