hanami 1.3.1 → 2.0.0.alpha2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (168) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +110 -6
  3. data/FEATURES.md +9 -1
  4. data/LICENSE.md +1 -1
  5. data/README.md +4 -5
  6. data/hanami.gemspec +26 -30
  7. data/lib/hanami.rb +40 -243
  8. data/lib/hanami/application.rb +338 -174
  9. data/lib/hanami/application/autoloader/inflector_adapter.rb +22 -0
  10. data/lib/hanami/application/container/boot/inflector.rb +7 -0
  11. data/lib/hanami/application/container/boot/logger.rb +8 -0
  12. data/lib/hanami/application/container/boot/rack_logger.rb +19 -0
  13. data/lib/hanami/application/container/boot/rack_monitor.rb +12 -0
  14. data/lib/hanami/application/container/boot/settings.rb +7 -0
  15. data/lib/hanami/application/router.rb +59 -0
  16. data/lib/hanami/application/routing/middleware/stack.rb +89 -0
  17. data/lib/hanami/application/routing/resolver.rb +82 -0
  18. data/lib/hanami/application/routing/resolver/node.rb +50 -0
  19. data/lib/hanami/application/routing/resolver/trie.rb +59 -0
  20. data/lib/hanami/application/settings.rb +23 -0
  21. data/lib/hanami/application/settings/definition.rb +26 -0
  22. data/lib/hanami/application/settings/loader.rb +97 -0
  23. data/lib/hanami/application/settings/struct.rb +65 -0
  24. data/lib/hanami/boot.rb +5 -0
  25. data/lib/hanami/cli/application/cli.rb +40 -0
  26. data/lib/hanami/cli/application/command.rb +47 -0
  27. data/lib/hanami/cli/application/commands.rb +16 -0
  28. data/lib/hanami/cli/application/commands/console.rb +81 -0
  29. data/lib/hanami/cli/base_command.rb +48 -0
  30. data/lib/hanami/cli/commands.rb +6 -42
  31. data/lib/hanami/cli/commands/command.rb +20 -30
  32. data/lib/hanami/cli/commands/server.rb +63 -14
  33. data/lib/hanami/configuration.rb +248 -190
  34. data/lib/hanami/configuration/middleware.rb +8 -28
  35. data/lib/hanami/configuration/router.rb +50 -0
  36. data/lib/hanami/configuration/sessions.rb +50 -0
  37. data/lib/hanami/init.rb +5 -0
  38. data/lib/hanami/server.rb +5 -69
  39. data/lib/hanami/setup.rb +8 -2
  40. data/lib/hanami/slice.rb +138 -0
  41. data/lib/hanami/version.rb +3 -1
  42. data/lib/hanami/web/rack_logger.rb +96 -0
  43. metadata +84 -228
  44. data/bin/hanami +0 -6
  45. data/lib/hanami/action/csrf_protection.rb +0 -211
  46. data/lib/hanami/action/routing_helpers.rb +0 -40
  47. data/lib/hanami/app.rb +0 -96
  48. data/lib/hanami/application_configuration.rb +0 -1495
  49. data/lib/hanami/application_name.rb +0 -108
  50. data/lib/hanami/application_namespace.rb +0 -14
  51. data/lib/hanami/assets/asset.rb +0 -72
  52. data/lib/hanami/assets/static.rb +0 -102
  53. data/lib/hanami/cli/commands/assets.rb +0 -16
  54. data/lib/hanami/cli/commands/assets/precompile.rb +0 -42
  55. data/lib/hanami/cli/commands/console.rb +0 -95
  56. data/lib/hanami/cli/commands/db.rb +0 -32
  57. data/lib/hanami/cli/commands/db/apply.rb +0 -32
  58. data/lib/hanami/cli/commands/db/console.rb +0 -44
  59. data/lib/hanami/cli/commands/db/create.rb +0 -32
  60. data/lib/hanami/cli/commands/db/drop.rb +0 -32
  61. data/lib/hanami/cli/commands/db/migrate.rb +0 -39
  62. data/lib/hanami/cli/commands/db/prepare.rb +0 -32
  63. data/lib/hanami/cli/commands/db/rollback.rb +0 -59
  64. data/lib/hanami/cli/commands/db/version.rb +0 -32
  65. data/lib/hanami/cli/commands/destroy.rb +0 -26
  66. data/lib/hanami/cli/commands/destroy/action.rb +0 -137
  67. data/lib/hanami/cli/commands/destroy/app.rb +0 -159
  68. data/lib/hanami/cli/commands/destroy/mailer.rb +0 -74
  69. data/lib/hanami/cli/commands/destroy/migration.rb +0 -51
  70. data/lib/hanami/cli/commands/destroy/model.rb +0 -84
  71. data/lib/hanami/cli/commands/generate.rb +0 -28
  72. data/lib/hanami/cli/commands/generate/action.rb +0 -321
  73. data/lib/hanami/cli/commands/generate/action/action.erb +0 -7
  74. data/lib/hanami/cli/commands/generate/action/action_spec.minitest.erb +0 -11
  75. data/lib/hanami/cli/commands/generate/action/action_spec.rspec.erb +0 -9
  76. data/lib/hanami/cli/commands/generate/action/action_without_view.erb +0 -7
  77. data/lib/hanami/cli/commands/generate/action/view.erb +0 -7
  78. data/lib/hanami/cli/commands/generate/action/view_spec.minitest.erb +0 -12
  79. data/lib/hanami/cli/commands/generate/action/view_spec.rspec.erb +0 -10
  80. data/lib/hanami/cli/commands/generate/app.rb +0 -243
  81. data/lib/hanami/cli/commands/generate/app/application.erb +0 -313
  82. data/lib/hanami/cli/commands/generate/app/favicon.ico +0 -0
  83. data/lib/hanami/cli/commands/generate/app/gitkeep.erb +0 -0
  84. data/lib/hanami/cli/commands/generate/app/layout.erb +0 -7
  85. data/lib/hanami/cli/commands/generate/app/layout_spec.minitest.erb +0 -10
  86. data/lib/hanami/cli/commands/generate/app/layout_spec.rspec.erb +0 -10
  87. data/lib/hanami/cli/commands/generate/app/routes.erb +0 -5
  88. data/lib/hanami/cli/commands/generate/app/template.erb.erb +0 -10
  89. data/lib/hanami/cli/commands/generate/app/template.haml.erb +0 -7
  90. data/lib/hanami/cli/commands/generate/app/template.slim.erb +0 -8
  91. data/lib/hanami/cli/commands/generate/mailer.rb +0 -104
  92. data/lib/hanami/cli/commands/generate/mailer/mailer.erb +0 -9
  93. data/lib/hanami/cli/commands/generate/mailer/mailer_spec.minitest.erb +0 -7
  94. data/lib/hanami/cli/commands/generate/mailer/mailer_spec.rspec.erb +0 -5
  95. data/lib/hanami/cli/commands/generate/migration.rb +0 -41
  96. data/lib/hanami/cli/commands/generate/migration/migration.erb +0 -4
  97. data/lib/hanami/cli/commands/generate/model.rb +0 -125
  98. data/lib/hanami/cli/commands/generate/model/entity.erb +0 -2
  99. data/lib/hanami/cli/commands/generate/model/entity_spec.minitest.erb +0 -5
  100. data/lib/hanami/cli/commands/generate/model/entity_spec.rspec.erb +0 -3
  101. data/lib/hanami/cli/commands/generate/model/migration.erb +0 -10
  102. data/lib/hanami/cli/commands/generate/model/repository.erb +0 -5
  103. data/lib/hanami/cli/commands/generate/model/repository_spec.minitest.erb +0 -5
  104. data/lib/hanami/cli/commands/generate/model/repository_spec.rspec.erb +0 -3
  105. data/lib/hanami/cli/commands/generate/secret.rb +0 -48
  106. data/lib/hanami/cli/commands/new.rb +0 -578
  107. data/lib/hanami/cli/commands/new/.env.development.erb +0 -3
  108. data/lib/hanami/cli/commands/new/.env.test.erb +0 -3
  109. data/lib/hanami/cli/commands/new/.gitkeep.erb +0 -0
  110. data/lib/hanami/cli/commands/new/Gemfile.erb +0 -58
  111. data/lib/hanami/cli/commands/new/README.md.erb +0 -33
  112. data/lib/hanami/cli/commands/new/config.ru.erb +0 -3
  113. data/lib/hanami/cli/commands/new/config/boot.erb +0 -2
  114. data/lib/hanami/cli/commands/new/config/environment.erb +0 -49
  115. data/lib/hanami/cli/commands/new/gitignore.erb +0 -2
  116. data/lib/hanami/cli/commands/new/gitignore_with_sqlite.erb +0 -3
  117. data/lib/hanami/cli/commands/new/hanamirc.erb +0 -3
  118. data/lib/hanami/cli/commands/new/lib/project.erb +0 -2
  119. data/lib/hanami/cli/commands/new/minitest/Rakefile.erb +0 -12
  120. data/lib/hanami/cli/commands/new/minitest/features_helper.erb +0 -11
  121. data/lib/hanami/cli/commands/new/minitest/spec_helper.erb +0 -7
  122. data/lib/hanami/cli/commands/new/rspec/Rakefile.erb +0 -9
  123. data/lib/hanami/cli/commands/new/rspec/capybara.erb +0 -8
  124. data/lib/hanami/cli/commands/new/rspec/features_helper.erb +0 -12
  125. data/lib/hanami/cli/commands/new/rspec/rspec.erb +0 -2
  126. data/lib/hanami/cli/commands/new/rspec/spec_helper.erb +0 -103
  127. data/lib/hanami/cli/commands/new/schema.sql.erb +0 -0
  128. data/lib/hanami/cli/commands/project.rb +0 -421
  129. data/lib/hanami/cli/commands/routes.rb +0 -21
  130. data/lib/hanami/cli/commands/templates.rb +0 -31
  131. data/lib/hanami/cli/commands/version.rb +0 -19
  132. data/lib/hanami/common_logger.rb +0 -93
  133. data/lib/hanami/components.rb +0 -156
  134. data/lib/hanami/components/app/assets.rb +0 -59
  135. data/lib/hanami/components/app/controller.rb +0 -74
  136. data/lib/hanami/components/app/routes.rb +0 -59
  137. data/lib/hanami/components/app/view.rb +0 -44
  138. data/lib/hanami/components/component.rb +0 -182
  139. data/lib/hanami/components/components.rb +0 -479
  140. data/lib/hanami/components/routes_inspector.rb +0 -72
  141. data/lib/hanami/config/cookies.rb +0 -69
  142. data/lib/hanami/config/framework_configuration.rb +0 -43
  143. data/lib/hanami/config/load_paths.rb +0 -46
  144. data/lib/hanami/config/mapper.rb +0 -47
  145. data/lib/hanami/config/routes.rb +0 -20
  146. data/lib/hanami/config/security.rb +0 -110
  147. data/lib/hanami/config/sessions.rb +0 -103
  148. data/lib/hanami/configuration/app.rb +0 -18
  149. data/lib/hanami/early_hints.rb +0 -129
  150. data/lib/hanami/env.rb +0 -69
  151. data/lib/hanami/environment.rb +0 -513
  152. data/lib/hanami/environment_application_configurations.rb +0 -37
  153. data/lib/hanami/frameworks.rb +0 -22
  154. data/lib/hanami/hanamirc.rb +0 -169
  155. data/lib/hanami/mailer/glue.rb +0 -27
  156. data/lib/hanami/middleware_stack.rb +0 -172
  157. data/lib/hanami/rake_helper.rb +0 -78
  158. data/lib/hanami/rake_tasks.rb +0 -2
  159. data/lib/hanami/rendering_policy.rb +0 -95
  160. data/lib/hanami/routes.rb +0 -219
  161. data/lib/hanami/routing/default.rb +0 -32
  162. data/lib/hanami/static.rb +0 -63
  163. data/lib/hanami/templates/default.html.erb +0 -30
  164. data/lib/hanami/templates/welcome.html.erb +0 -52
  165. data/lib/hanami/views/default.rb +0 -37
  166. data/lib/hanami/views/default_template_finder.rb +0 -22
  167. data/lib/hanami/views/null_view.rb +0 -15
  168. data/lib/hanami/welcome.rb +0 -36
@@ -1,21 +0,0 @@
1
- module Hanami
2
- class CLI
3
- module Commands
4
- # @since 1.1.0
5
- # @api private
6
- class Routes < Command
7
- requires "routes.inspector"
8
-
9
- desc "Prints routes"
10
-
11
- # @since 1.1.0
12
- # @api private
13
- def call(*)
14
- puts requirements['routes.inspector'].inspect
15
- end
16
- end
17
- end
18
-
19
- register "routes", Commands::Routes
20
- end
21
- end
@@ -1,31 +0,0 @@
1
- module Hanami
2
- class CLI
3
- module Commands
4
- # @since 1.1.0
5
- # @api private
6
- class Templates
7
- NAMESPACE = name.sub(Utils::String.demodulize(name), "").freeze
8
-
9
- # @since 1.1.0
10
- # @api private
11
- def initialize(klass)
12
- word = klass.name.sub(NAMESPACE, "").split("::").map(&:downcase)
13
- @root = Pathname.new(File.join(__dir__, *word))
14
- freeze
15
- end
16
-
17
- # @since 1.1.0
18
- # @api private
19
- def find(*names)
20
- @root.join(*names)
21
- end
22
-
23
- private
24
-
25
- # @since 1.1.0
26
- # @api private
27
- attr_reader :root
28
- end
29
- end
30
- end
31
- end
@@ -1,19 +0,0 @@
1
- module Hanami
2
- class CLI
3
- module Commands
4
- # @since 1.1.0
5
- # @api private
6
- class Version < Command
7
- desc "Print Hanami version"
8
-
9
- # @since 1.1.0
10
- # @api private
11
- def call(*)
12
- puts "v#{Hanami::VERSION}"
13
- end
14
- end
15
- end
16
-
17
- register "version", Commands::Version, aliases: ["v", "-v", "--version"]
18
- end
19
- end
@@ -1,93 +0,0 @@
1
- require 'rack/common_logger'
2
- require 'hanami/utils/hash'
3
-
4
- module Hanami
5
- # Rack logger for Hanami.app
6
- #
7
- # @since 1.0.0
8
- # @api private
9
- class CommonLogger < Rack::CommonLogger
10
- private
11
-
12
- # @since 1.0.0
13
- # @api private
14
- HTTP_VERSION = 'HTTP_VERSION'.freeze
15
-
16
- # @since 1.0.0
17
- # @api private
18
- REQUEST_METHOD = 'REQUEST_METHOD'.freeze
19
-
20
- # @since 1.0.0
21
- # @api private
22
- HTTP_X_FORWARDED_FOR = 'HTTP_X_FORWARDED_FOR'.freeze
23
-
24
- # @since 1.0.0
25
- # @api private
26
- REMOTE_ADDR = 'REMOTE_ADDR'.freeze
27
-
28
- # @since 1.0.0
29
- # @api private
30
- SCRIPT_NAME = 'SCRIPT_NAME'.freeze
31
-
32
- # @since 1.0.0
33
- # @api private
34
- PATH_INFO = 'PATH_INFO'.freeze
35
-
36
- # @since 1.0.0
37
- # @api private
38
- RACK_ERRORS = 'rack.errors'.freeze
39
-
40
- # @since 1.1.0
41
- # @api private
42
- QUERY_HASH = 'rack.request.query_hash'.freeze
43
-
44
- # @since 1.1.0
45
- # @api private
46
- FORM_HASH = 'rack.request.form_hash'.freeze
47
-
48
- # @since 1.3.0
49
- # @api private
50
- ROUTER_PARAMS = 'router.params'.freeze
51
-
52
- # @since 1.0.0
53
- # @api private
54
- #
55
- # rubocop:disable Metrics/AbcSize
56
- # rubocop:disable Metrics/MethodLength
57
- def log(env, status, header, began_at)
58
- now = Time.now
59
- length = extract_content_length(header)
60
-
61
- msg = Hash[
62
- http: env[HTTP_VERSION],
63
- verb: env[REQUEST_METHOD],
64
- status: status.to_s[0..3],
65
- ip: env[HTTP_X_FORWARDED_FOR] || env[REMOTE_ADDR],
66
- path: env[SCRIPT_NAME] + env[PATH_INFO].to_s,
67
- length: length,
68
- params: extract_params(env),
69
- elapsed: now - began_at
70
- ]
71
-
72
- logger = @logger || env[RACK_ERRORS]
73
- # Standard library logger doesn't support write but it supports << which actually
74
- # calls to write on the log device without formatting
75
- if logger.respond_to?(:write)
76
- logger.write(msg)
77
- else
78
- logger.info(msg)
79
- end
80
- end
81
- # rubocop:enable Metrics/MethodLength
82
- # rubocop:enable Metrics/AbcSize
83
-
84
- # @since 1.1.0
85
- # @api private
86
- def extract_params(env)
87
- result = env.fetch(QUERY_HASH, {})
88
- result.merge!(env.fetch(FORM_HASH, {}))
89
- result.merge!(Utils::Hash.deep_stringify(env.fetch(ROUTER_PARAMS, {})))
90
- result
91
- end
92
- end
93
- end
@@ -1,156 +0,0 @@
1
- require 'concurrent'
2
-
3
- module Hanami
4
- # Components API
5
- #
6
- # Components are an internal Hanami that provides precise loading mechanism
7
- # for a project. It is responsible to load frameworks, configurations, code, etc..
8
- #
9
- # The implementation is thread-safe
10
- #
11
- # @example
12
- # Hanami::Components.resolved('repo') { UserRepository.new }
13
- # Hanami::Components['repository.users'] # => #<UserRepository relations=[...]>
14
- #
15
- # Also you can use Hanami::Components with dry-auto_inject
16
- #
17
- # @example
18
- # Hanami::Components.resolved('repo') { UserRepository.new }
19
- # Hanami::Components['repository.users'] # => #<UserRepository relations=[...]>
20
- #
21
- # HanamiImport = Dry::AutoInject(Hanami::Components)
22
- #
23
- # class CreateUser
24
- # include HanamiImport['repository.users']
25
- #
26
- # def call(payload)
27
- # users.create(payload)
28
- # end
29
- # end
30
- #
31
- # CreateUser.new.call # => #<User:...>
32
- # CreateUser.new(users: MockRepository.new).call # => #<MockUser:...>
33
- #
34
- # @since 0.9.0
35
- # @api private
36
- module Components
37
- # Available components
38
- #
39
- # @since 0.9.0
40
- # @api private
41
- @_components = Concurrent::Hash.new
42
-
43
- # Resolved components
44
- #
45
- # @since 0.9.0
46
- # @api private
47
- @_resolved = Concurrent::Map.new
48
-
49
- # Register a component
50
- #
51
- # @param name [String] the unique component name
52
- # @param blk [Proc] the logic of the component
53
- #
54
- # @since 0.9.0
55
- # @api private
56
- #
57
- # @see Hanami::Components::Component
58
- def self.register(name, &blk)
59
- @_components[name] = Component.new(name, &blk)
60
- end
61
-
62
- # Return a registered component
63
- #
64
- # @param name [String] the name of the component
65
- #
66
- # @raise [ArgumentError] if the component is unknown
67
- #
68
- # @since 0.9.0
69
- # @api private
70
- def self.component(name)
71
- @_components.fetch(name) do
72
- raise ArgumentError.new("Component not found: `#{name}'.\nAvailable components are: #{@_components.keys.join(', ')}")
73
- end
74
- end
75
-
76
- # Mark a component as resolved by providing a value or a block.
77
- # In the latter case, the returning value of the block is associated with
78
- # the component.
79
- #
80
- # @param name [String] the name of the component to mark as resolved
81
- # @param value [Object] the optional value of the component
82
- # @param blk [Proc] the optional block which returning value is associated with the component.
83
- #
84
- # @since 0.9.0
85
- # @api private
86
- def self.resolved(name, value = nil, &blk)
87
- if block_given?
88
- @_resolved.fetch_or_store(name, &blk)
89
- else
90
- @_resolved.compute_if_absent(name) { value }
91
- end
92
- end
93
-
94
- # Ask to resolve a component.
95
- #
96
- # This is used as dependency mechanism.
97
- # For instance `model` component depends on `model.configuration`. Before to
98
- # resolve `model`, `Components` uses this method to resolve that dependency first.
99
- #
100
- # @param names [String,Array<String>] one or more components to be resolved
101
- #
102
- # @since 0.9.0
103
- # @api private
104
- def self.resolve(*names)
105
- Array(names).flatten.each do |name|
106
- @_resolved.fetch_or_store(name) do
107
- component = @_components.fetch(name)
108
- component.call(Hanami.configuration)
109
- end
110
- end
111
- end
112
-
113
- # Return the value of an already resolved component. Or raise error for not resolved component.
114
- #
115
- # @example
116
- # Hanami::Components.resolved('repository.users') { UserRepository.new }
117
- #
118
- # Hanami::Components['repository.users'] # => #<UserRepository relations=[...]>
119
- # Hanami::Components['repository.other'] # => error
120
- #
121
- # @param name [String] the component name
122
- #
123
- # @raise [ArgumentError] if the component is unknown or not resolved yet.
124
- #
125
- # @since 0.9.0
126
- # @api private
127
- def self.[](name)
128
- @_resolved.fetch(name) do
129
- raise ArgumentError.new("Component not resolved: `#{name}'.\nResolved components are: #{@_resolved.keys.join(', ')}")
130
- end
131
- end
132
-
133
- # Release all the resolved components.
134
- # This is used for code reloading.
135
- #
136
- # NOTE: this MUST NOT be used unless you know what you're doing.
137
- #
138
- # @example
139
- # Hanami::Components.resolved('repository.users') { UserRepository.new }
140
- # Hanami::Components['repository.users'] # => #<UserRepository relations=[...]>
141
- #
142
- # Hanami::Components.release
143
- # Hanami::Components['repository.users']
144
- # # => ArgumentError: Component not resolved: `repo'.
145
- # # => Resolved components are: ...
146
- #
147
- # @since 1.0.0
148
- # @api private
149
- def self.release
150
- @_resolved.clear
151
- end
152
-
153
- require 'hanami/components/component'
154
- require 'hanami/components/components'
155
- end
156
- end
@@ -1,59 +0,0 @@
1
- module Hanami
2
- # @since 0.9.0
3
- # @api private
4
- module Components
5
- # @since 0.9.0
6
- # @api private
7
- module App
8
- # hanami-assets configuration for a sigle Hanami application in the project.
9
- #
10
- # @since 0.9.0
11
- # @api private
12
- class Assets
13
- # Configure hanami-assets for a single Hanami application in the project.
14
- #
15
- # @param app [Hanami::Configuration::App] a Hanami application
16
- #
17
- # @since 0.9.0
18
- # @api private
19
- #
20
- # rubocop:disable Metrics/AbcSize
21
- # rubocop:disable Metrics/MethodLength
22
- def self.resolve(app)
23
- config = app.configuration
24
- namespace = app.namespace
25
-
26
- unless namespace.const_defined?('Assets', false)
27
- assets = Hanami::Assets.duplicate(namespace) do
28
- root config.root
29
-
30
- scheme config.scheme
31
- host config.host
32
- port config.port
33
-
34
- public_directory Hanami.public_directory
35
- prefix Utils::PathPrefix.new('/assets').join(config.path_prefix)
36
-
37
- manifest Hanami.public_directory.join('assets.json')
38
- compile true
39
-
40
- config.assets.__apply(self)
41
- end
42
-
43
- assets.configure do
44
- cdn host != config.host
45
- end
46
-
47
- namespace.const_set('Assets', assets)
48
- end
49
-
50
- name = "#{app.app_name}.assets"
51
- Components.resolved(name, namespace.const_get('Assets').configuration)
52
- Components[name]
53
- end
54
- end
55
- # rubocop:enable Metrics/MethodLength
56
- # rubocop:enable Metrics/AbcSize
57
- end
58
- end
59
- end
@@ -1,74 +0,0 @@
1
- require 'hanami/action/session'
2
- require 'hanami/action/routing_helpers'
3
-
4
- module Hanami
5
- # @since 0.9.0
6
- # @api private
7
- module Components
8
- # @since 0.9.0
9
- # @api private
10
- module App
11
- # hanami-controller configuration for a sigle Hanami application in the project.
12
- #
13
- # @since 0.9.0
14
- # @api private
15
- class Controller
16
- STRICT_TRANSPORT_SECURITY_HEADER = 'Strict-Transport-Security'.freeze
17
- STRICT_TRANSPORT_SECURITY_DEFAULT_VALUE = 'max-age=31536000'.freeze
18
-
19
- # Configure hanami-controller for a single Hanami application in the project.
20
- #
21
- # @param app [Hanami::Configuration::App] a Hanami application
22
- #
23
- # @since 0.9.0
24
- # @api private
25
- #
26
- # rubocop:disable Metrics/AbcSize
27
- # rubocop:disable Metrics/MethodLength
28
- def self.resolve(app)
29
- config = app.configuration
30
- namespace = app.namespace
31
-
32
- unless namespace.const_defined?('Controller', false)
33
- controller = Hanami::Controller.duplicate(namespace) do
34
- handle_exceptions config.handle_exceptions
35
- public_directory Hanami.public_directory
36
- default_request_format config.default_request_format
37
- default_response_format config.default_response_format
38
- default_headers(
39
- Hanami::Config::Security::X_FRAME_OPTIONS_HEADER => config.security.x_frame_options,
40
- Hanami::Config::Security::X_CONTENT_TYPE_OPTIONS_HEADER => config.security.x_content_type_options,
41
- Hanami::Config::Security::X_XSS_PROTECTION_HEADER => config.security.x_xss_protection,
42
- Hanami::Config::Security::CONTENT_SECURITY_POLICY_HEADER => config.security.content_security_policy
43
- )
44
- default_headers[STRICT_TRANSPORT_SECURITY_HEADER] = STRICT_TRANSPORT_SECURITY_DEFAULT_VALUE if config.force_ssl
45
-
46
- if config.cookies.enabled?
47
- require 'hanami/action/cookies'
48
- prepare { include Hanami::Action::Cookies }
49
- cookies config.cookies.default_options
50
- end
51
-
52
- if config.sessions.enabled?
53
- prepare do
54
- include Hanami::Action::Session
55
- include Hanami::Action::CSRFProtection
56
- end
57
- end
58
-
59
- prepare { include Hanami::Action::RoutingHelpers }
60
-
61
- config.controller.__apply(self)
62
- end
63
-
64
- namespace.const_set('Controller', controller)
65
- end
66
-
67
- Components.resolved "#{app.app_name}.controller", namespace.const_get('Controller').configuration
68
- end
69
- end
70
- # rubocop:enable Metrics/MethodLength
71
- # rubocop:enable Metrics/AbcSize
72
- end
73
- end
74
- end