Sha256: 1e867bfa51d3cbd9358be694bdca9c673f13b7cb48bb9a32ba0c7c6b7ce2b4d9

Contents?: true

Size: 1.05 KB

Versions: 12

Compression:

Stored size: 1.05 KB

Contents

# frozen_string_literal: true

module Hanami
  # @api private
  module Providers
    # Provider source to register routes helper component in Hanami slices.
    #
    # @see Hanami::Slice::RoutesHelper
    #
    # @api private
    # @since 2.0.0
    class Routes < Dry::System::Provider::Source
      # @api private
      def self.for_slice(slice)
        Class.new(self) do |klass|
          klass.instance_variable_set(:@slice, slice)
        end
      end

      # @api private
      def self.slice
        @slice || Hanami.app
      end

      # @api private
      def prepare
        require "hanami/slice/routes_helper"
      end

      # @api private
      def start
        # Register a lazy instance of RoutesHelper to ensure we don't load prematurely load the
        # router during the process of booting. This ensures the router's resolver can run strict
        # action key checks once when it runs on a fully booted slice.
        register :routes do
          Hanami::Slice::RoutesHelper.new(self.class.slice.router)
        end
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
hanami-2.1.0 lib/hanami/providers/routes.rb
hanami-2.1.0.rc3 lib/hanami/providers/routes.rb
hanami-2.1.0.rc2 lib/hanami/providers/routes.rb
hanami-2.1.0.rc1 lib/hanami/providers/routes.rb
hanami-2.1.0.beta2.1 lib/hanami/providers/routes.rb
hanami-2.1.0.beta2 lib/hanami/providers/routes.rb
hanami-2.1.0.beta1 lib/hanami/providers/routes.rb
hanami-2.0.3 lib/hanami/providers/routes.rb
hanami-2.0.2 lib/hanami/providers/routes.rb
hanami-2.0.1 lib/hanami/providers/routes.rb
hanami-2.0.0 lib/hanami/providers/routes.rb
hanami-2.0.0.rc1 lib/hanami/providers/routes.rb