Class: Hanami::Components::App::Controller Private

Inherits:
Object
  • Object
show all
Defined in:
lib/hanami/components/app/controller.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-controller configuration for a sigle Hanami application in the project.

Since:

  • 0.9.0

Constant Summary collapse

STRICT_TRANSPORT_SECURITY_HEADER =

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

Since:

  • 0.9.0

'Strict-Transport-Security'.freeze
STRICT_TRANSPORT_SECURITY_DEFAULT_VALUE =

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

Since:

  • 0.9.0

'max-age=31536000'.freeze

Class Method Summary collapse

Class Method Details

.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-controller for a single Hanami application in the project.

rubocop:disable Metrics/AbcSize rubocop:disable Metrics/MethodLength

Parameters:

Since:

  • 0.9.0


28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/hanami/components/app/controller.rb', line 28

def self.resolve(app)
  config    = app.configuration
  namespace = app.namespace

  unless namespace.const_defined?('Controller', false)
    controller = Hanami::Controller.duplicate(namespace) do
      handle_exceptions config.handle_exceptions
      public_directory  Hanami.public_directory
      default_request_format config.default_request_format
      default_response_format config.default_response_format
      default_headers(
        Hanami::Config::Security::X_FRAME_OPTIONS_HEADER         => config.security.x_frame_options,
        Hanami::Config::Security::X_CONTENT_TYPE_OPTIONS_HEADER  => config.security.x_content_type_options,
        Hanami::Config::Security::X_XSS_PROTECTION_HEADER        => config.security.x_xss_protection,
        Hanami::Config::Security::CONTENT_SECURITY_POLICY_HEADER => config.security.content_security_policy
      )
      default_headers[STRICT_TRANSPORT_SECURITY_HEADER] = STRICT_TRANSPORT_SECURITY_DEFAULT_VALUE if config.force_ssl

      if config.cookies.enabled?
        require 'hanami/action/cookies'
        prepare { include Hanami::Action::Cookies }
        cookies config.cookies.default_options
      end

      if config.sessions.enabled?
        prepare do
          include Hanami::Action::Session
          include Hanami::Action::CSRFProtection
        end
      end

      prepare { include Hanami::Action::RoutingHelpers }

      config.controller.__apply(self)
    end

    namespace.const_set('Controller', controller)
  end

  Components.resolved "#{app.app_name}.controller", namespace.const_get('Controller').configuration
end