Sha256: c6c2c8756f6534256031157f15584679785e648b237b2d4365c7ed6812cf3935

Contents?: true

Size: 1.55 KB

Versions: 5

Compression:

Stored size: 1.55 KB

Contents

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

module Hanami
  module Components
    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

        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

5 entries across 5 versions & 1 rubygems

Version Path
hanami-1.0.0.beta2 lib/hanami/components/app/routes.rb
hanami-1.0.0.beta1 lib/hanami/components/app/routes.rb
hanami-0.9.2 lib/hanami/components/app/routes.rb
hanami-0.9.1 lib/hanami/components/app/routes.rb
hanami-0.9.0 lib/hanami/components/app/routes.rb