Sha256: d08e99287e00d578adebf5180e458e2b6ade7394abdb3f98e8a906152116aaa3

Contents?: true

Size: 1.5 KB

Versions: 95

Compression:

Stored size: 1.5 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.
        unless @spree_routes.include?(block)
          @spree_routes << block
        end
      end

      def self.append_routes(&block)
        @append_routes ||= []
        # See comment in add_routes.
        unless @append_routes.include?(block)
          @append_routes << block
        end
      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

95 entries across 95 versions & 3 rubygems

Version Path
goca-spree-core-3.1.14.rails.5.0 lib/spree/core/routes.rb
goca-spree-core-3.1.15.rails.5.0 lib/spree/core/routes.rb
goca-spree-core-3.1.15.pre.rails.pre.5.0 lib/spree/core/routes.rb
spree_core-3.2.9 lib/spree/core/routes.rb
spree_core-3.1.14 lib/spree/core/routes.rb
spree_core-3.3.6 lib/spree/core/routes.rb
spree_core-3.2.8 lib/spree/core/routes.rb
spree_core-3.1.13 lib/spree/core/routes.rb
spree_core-3.3.5 lib/spree/core/routes.rb
spree_core-3.3.4 lib/spree/core/routes.rb
spree_core-3.2.7 lib/spree/core/routes.rb
spree_core-3.1.12 lib/spree/core/routes.rb
solidus_core-1.3.2 lib/spree/core/routes.rb
solidus_core-1.2.3 lib/spree/core/routes.rb
solidus_core-1.1.4 lib/spree/core/routes.rb
solidus_core-1.0.7 lib/spree/core/routes.rb
spree_core-3.3.3 lib/spree/core/routes.rb
spree_core-3.2.6 lib/spree/core/routes.rb
spree_core-3.1.11 lib/spree/core/routes.rb
spree_core-3.1.10 lib/spree/core/routes.rb