Sha256: 58d91596b5e503d8270c365cacf168ad3d2b4ec845324a8b78d52ed8842192b7

Contents?: true

Size: 1.66 KB

Versions: 15

Compression:

Stored size: 1.66 KB

Contents

require 'hanami/routes'
require 'hanami/routing/default'

module Hanami
  # @since 0.9.0
  # @api private
  module Components
    # @since 0.9.0
    # @api private
    module App
      # hanami-router configuration for a sigle Hanami application in the project.
      #
      # @since 0.9.0
      # @api private
      class Routes
        # Configure hanami-router for a single Hanami application in the project.
        #
        # @param app [Hanami::Configuration::App] a Hanami application
        #
        # @since 0.9.0
        # @api private
        def self.resolve(app)
          namespace = app.namespace
          routes    = application_routes(app)

          if namespace.routes.nil? # rubocop:disable Style/IfUnlessModifier
            namespace.routes = Hanami::Routes.new(routes)
          end

          Components.resolved("#{app.app_name}.routes", routes)
        end

        # @since 0.9.0
        # @api private
        def self.application_routes(app) # rubocop:disable Metrics/MethodLength
          config      = app.configuration
          namespace   = app.namespace

          resolver    = Hanami::Routing::EndpointResolver.new(pattern: config.controller_pattern, namespace: namespace)
          default_app = Hanami::Routing::Default.new

          Hanami::Router.new(
            resolver:    resolver,
            default_app: default_app,
            parsers:     config.body_parsers,
            scheme:      config.scheme,
            host:        config.host,
            port:        config.port,
            prefix:      config.path_prefix,
            force_ssl:   config.force_ssl,
            &config.routes
          )
        end
      end
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
hanami-1.3.0.beta1 lib/hanami/components/app/routes.rb
hanami-1.2.0 lib/hanami/components/app/routes.rb
hanami-1.2.0.rc2 lib/hanami/components/app/routes.rb
hanami-1.2.0.rc1 lib/hanami/components/app/routes.rb
hanami-1.2.0.beta2 lib/hanami/components/app/routes.rb
hanami-1.2.0.beta1 lib/hanami/components/app/routes.rb
hanami-1.1.1 lib/hanami/components/app/routes.rb
hanami-1.1.0 lib/hanami/components/app/routes.rb
hanami-1.1.0.rc1 lib/hanami/components/app/routes.rb
hanami-1.1.0.beta3 lib/hanami/components/app/routes.rb
hanami-1.1.0.beta2 lib/hanami/components/app/routes.rb
hanami-1.1.0.beta1 lib/hanami/components/app/routes.rb
hanami-1.0.0 lib/hanami/components/app/routes.rb
hanami-1.0.0.rc1 lib/hanami/components/app/routes.rb
hanami-1.0.0.beta3 lib/hanami/components/app/routes.rb