Sha256: 08649c3eae5d2deb8a82ea8481400735ba6848dee742af1d90c9d73b5d9262ac

Contents?: true

Size: 733 Bytes

Versions: 120

Compression:

Stored size: 733 Bytes

Contents

module Arel
  module Visitors
    class Visitor
      def accept object
        visit object
      end

      private

      DISPATCH = Hash.new do |hash, klass|
        hash[klass] = "visit_#{(klass.name || '').gsub('::', '_')}"
      end

      def dispatch
        DISPATCH
      end

      def visit object
        send dispatch[object.class], object
      rescue NoMethodError => e
        raise e if respond_to?(dispatch[object.class], true)
        superklass = object.class.ancestors.find { |klass|
          respond_to?(dispatch[klass], true)
        }
        raise(TypeError, "Cannot visit #{object.class}") unless superklass
        dispatch[object.class] = dispatch[superklass]
        retry
      end
    end
  end
end

Version data entries

120 entries across 102 versions & 14 rubygems

Version Path
mdg-1.0.1 vendor/bundle/ruby/2.3.0/gems/arel-3.0.3/lib/arel/visitors/visitor.rb
active_mailer-0.0.10 test/fixtures/dummyapp_rails_3.2/vendor/bundle/ruby/1.9.1/gems/arel-3.0.2/lib/arel/visitors/visitor.rb
judge-2.0.5 vendor/bundle/ruby/2.1.0/gems/arel-3.0.2/lib/arel/visitors/visitor.rb
apl-library-0.0.90 vendor/bundle/ruby/1.9.1/gems/arel-3.0.3/lib/arel/visitors/visitor.rb
apl-library-0.0.90 vendor/bundle/ruby/1.8/gems/arel-3.0.3/lib/arel/visitors/visitor.rb
apl-library-0.0.90 vendor/bundle/ruby/2.1.0/gems/apl-library-0.0.90/vendor/bundle/ruby/1.8/gems/arel-3.0.3/lib/arel/visitors/visitor.rb
apl-library-0.0.90 vendor/bundle/ruby/2.1.0/gems/apl-library-0.0.90/vendor/bundle/ruby/1.9.1/gems/arel-3.0.3/lib/arel/visitors/visitor.rb
apl-library-0.0.90 vendor/bundle/ruby/2.1.0/gems/apl-library-0.0.90/vendor/bundle/ruby/2.1.0/gems/arel-3.0.3/lib/arel/visitors/visitor.rb
apl-library-0.0.90 vendor/bundle/ruby/2.1.0/gems/arel-3.0.3/lib/arel/visitors/visitor.rb
arel-3.0.3 lib/arel/visitors/visitor.rb
challah-1.0.0 vendor/bundle/gems/arel-4.0.0/lib/arel/visitors/visitor.rb
swipe-rails-0.0.5 vendor/bundle/gems/arel-3.0.2/lib/arel/visitors/visitor.rb
active_mailer-0.0.9 test/fixtures/dummyapp_rails_3.2/vendor/bundle/ruby/1.9.1/gems/arel-3.0.2/lib/arel/visitors/visitor.rb
active_mailer-0.0.8 test/fixtures/dummyapp_rails_3.2/vendor/bundle/ruby/1.9.1/gems/arel-3.0.2/lib/arel/visitors/visitor.rb
active_mailer-0.0.7 test/fixtures/dummyapp_rails_3.2/vendor/bundle/ruby/1.9.1/gems/arel-3.0.2/lib/arel/visitors/visitor.rb
active_mailer-0.0.6 test/fixtures/dummyapp_rails_3.2/vendor/bundle/ruby/1.9.1/gems/arel-3.0.2/lib/arel/visitors/visitor.rb
challah-1.0.0.beta3 vendor/bundle/gems/arel-3.0.2/lib/arel/visitors/visitor.rb
arel-4.0.0 lib/arel/visitors/visitor.rb
fc-webicons-0.0.4 vendor/bundle/ruby/1.9.1/gems/arel-3.0.2/lib/arel/visitors/visitor.rb
challah-1.0.0.beta2 vendor/bundle/gems/arel-3.0.2/lib/arel/visitors/visitor.rb