Sha256: 44a44afc4a229a4865a03a9c74ec4556714d467a18c4880957a5677e42e4d671

Contents?: true

Size: 1.46 KB

Versions: 122

Compression:

Stored size: 1.46 KB

Contents

module Spree
  module Core
    class Engine < ::Rails::Engine
      def self.add_routes(&block)
        @spree_routes ||= []

        # Anything that causes the application's routes to be reloaded,
        # will cause this method to be called more than once
        # i.e. https://github.com/plataformatec/devise/blob/31971e69e6a1bcf6c7f01eaaa44f227c4af5d4d2/lib/devise/rails.rb#L14
        # In the case of Devise, this *only* happens in the production env
        # This coupled with Rails 4's insistence that routes are not drawn twice,
        # poses quite a serious problem.
        #
        # This is mainly why this whole file exists in the first place.
        #
        # Thus we need to make sure that the routes aren't drawn twice.
        @spree_routes << block unless @spree_routes.include?(block)
      end

      def self.append_routes(&block)
        @append_routes ||= []
        # See comment in add_routes.
        @append_routes << block unless @append_routes.include?(block)
      end

      def self.draw_routes(&block)
        @spree_routes ||= []
        @append_routes ||= []
        eval_block(block) if block_given?
        @spree_routes.each { |r| eval_block(&r) }
        @append_routes.each { |r| eval_block(&r) }
        # # Clear out routes so that they aren't drawn twice.
        @spree_routes = []
        @append_routes = []
      end

      def eval_block(&block)
        Spree::Core::Engine.routes.send :eval_block, block
      end
    end
  end
end

Version data entries

122 entries across 122 versions & 1 rubygems

Version Path
spree_core-4.10.1 lib/spree/core/routes.rb
spree_core-4.10.0 lib/spree/core/routes.rb
spree_core-4.9.0 lib/spree/core/routes.rb
spree_core-4.8.3 lib/spree/core/routes.rb
spree_core-4.8.2 lib/spree/core/routes.rb
spree_core-4.7.3 lib/spree/core/routes.rb
spree_core-4.6.6 lib/spree/core/routes.rb
spree_core-4.5.5 lib/spree/core/routes.rb
spree_core-4.0.9 lib/spree/core/routes.rb
spree_core-4.1.15 lib/spree/core/routes.rb
spree_core-4.2.7 lib/spree/core/routes.rb
spree_core-4.3.3 lib/spree/core/routes.rb
spree_core-4.4.1 lib/spree/core/routes.rb
spree_core-4.5.4 lib/spree/core/routes.rb
spree_core-4.6.5 lib/spree/core/routes.rb
spree_core-4.7.2 lib/spree/core/routes.rb
spree_core-4.7.1 lib/spree/core/routes.rb
spree_core-4.6.4 lib/spree/core/routes.rb
spree_core-4.7.0 lib/spree/core/routes.rb
spree_core-4.6.3 lib/spree/core/routes.rb