Class: Hanami::Components::App::Routes Private

Inherits:
Object
  • Object
show all
Defined in:
lib/hanami/components/app/routes.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

hanami-router configuration for a sigle Hanami application in the project.

Since:

  • 0.9.0

Class Method Summary collapse

Class Method Details

.application_routes(app) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Since:

  • 0.9.0


35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/hanami/components/app/routes.rb', line 35

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

  options = {
    resolver:    resolver,
    default_app: default_app,
    scheme:      config.scheme,
    host:        config.host,
    port:        config.port,
    prefix:      config.path_prefix,
    force_ssl:   config.force_ssl
  }

  options[:parsers] = config.body_parsers if config.body_parsers.any?

  Hanami::Router.new(options, &config.routes)
end

.resolve(app) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Configure hanami-router for a single Hanami application in the project.

Since:

  • 0.9.0


22
23
24
25
26
27
28
29
30
31
# File 'lib/hanami/components/app/routes.rb', line 22

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