hanami 0.8.0 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +23 -0
- data/FEATURES.md +13 -0
- data/README.md +28 -1
- data/hanami.gemspec +20 -17
- data/lib/hanami.rb +106 -7
- data/lib/hanami/action/routing_helpers.rb +2 -2
- data/lib/hanami/app.rb +72 -0
- data/lib/hanami/application.rb +144 -183
- data/lib/hanami/application_configuration.rb +1541 -0
- data/lib/hanami/application_name.rb +2 -2
- data/lib/hanami/application_namespace.rb +12 -0
- data/lib/hanami/assets/asset.rb +3 -1
- data/lib/hanami/assets/static.rb +3 -9
- data/lib/hanami/cli.rb +10 -7
- data/lib/hanami/cli_sub_commands/assets.rb +1 -9
- data/lib/hanami/cli_sub_commands/generate.rb +16 -0
- data/lib/hanami/commands/apps.rb +4 -0
- data/lib/hanami/commands/assets/precompile.rb +6 -19
- data/lib/hanami/commands/command.rb +64 -0
- data/lib/hanami/commands/console.rb +37 -26
- data/lib/hanami/commands/db/apply.rb +4 -2
- data/lib/hanami/commands/db/console.rb +11 -27
- data/lib/hanami/commands/db/create.rb +4 -2
- data/lib/hanami/commands/db/drop.rb +4 -2
- data/lib/hanami/commands/db/migrate.rb +11 -5
- data/lib/hanami/commands/db/prepare.rb +4 -2
- data/lib/hanami/commands/db/version.rb +4 -2
- data/lib/hanami/commands/generate/abstract.rb +5 -7
- data/lib/hanami/commands/generate/action.rb +18 -6
- data/lib/hanami/commands/generate/app.rb +15 -2
- data/lib/hanami/commands/generate/migration.rb +3 -2
- data/lib/hanami/commands/generate/model.rb +4 -3
- data/lib/hanami/commands/generate/secret_token.rb +31 -0
- data/lib/hanami/commands/new/abstract.rb +14 -5
- data/lib/hanami/commands/new/container.rb +1 -0
- data/lib/hanami/commands/routes.rb +5 -22
- data/lib/hanami/commands/server.rb +14 -142
- data/lib/hanami/components.rb +107 -0
- data/lib/hanami/components/app/assets.rb +55 -0
- data/lib/hanami/components/app/controller.rb +69 -0
- data/lib/hanami/components/app/logger.rb +30 -0
- data/lib/hanami/components/app/routes.rb +51 -0
- data/lib/hanami/components/app/view.rb +40 -0
- data/lib/hanami/components/component.rb +166 -0
- data/lib/hanami/components/components.rb +366 -0
- data/lib/hanami/components/routes_inspector.rb +70 -0
- data/lib/hanami/config/load_paths.rb +7 -6
- data/lib/hanami/config/mapper.rb +1 -1
- data/lib/hanami/config/security.rb +0 -8
- data/lib/hanami/configuration.rb +27 -1697
- data/lib/hanami/env.rb +67 -0
- data/lib/hanami/environment.rb +31 -21
- data/lib/hanami/environment_application_configurations.rb +30 -0
- data/lib/hanami/frameworks.rb +1 -0
- data/lib/hanami/generators/app/application.rb.tt +2 -2
- data/lib/hanami/generators/application/app/Gemfile.tt +3 -1
- data/lib/hanami/generators/application/app/config/application.rb.tt +2 -2
- data/lib/hanami/generators/application/app/gitignore_with_sqlite.tt +3 -0
- data/lib/hanami/generators/application/app/lib/app_name.rb.tt +4 -25
- data/lib/hanami/generators/application/app/spec_helper.rb.minitest.tt +1 -1
- data/lib/hanami/generators/application/app/spec_helper.rb.rspec.tt +1 -1
- data/lib/hanami/generators/application/container/Gemfile.tt +3 -1
- data/lib/hanami/generators/application/container/capybara.rb.rspec.tt +1 -1
- data/lib/hanami/generators/application/container/config.ru.tt +1 -1
- data/lib/hanami/generators/application/container/config/environment.rb.tt +35 -1
- data/lib/hanami/generators/application/container/features_helper.rb.minitest.tt +1 -1
- data/lib/hanami/generators/application/container/gitignore_with_sqlite.tt +3 -0
- data/lib/hanami/generators/application/container/lib/project.rb.tt +1 -57
- data/lib/hanami/generators/application/container/spec_helper.rb.minitest.tt +1 -1
- data/lib/hanami/generators/application/container/spec_helper.rb.rspec.tt +2 -3
- data/lib/hanami/generators/database_config.rb +8 -11
- data/lib/hanami/generators/model/entity.rb.tt +1 -2
- data/lib/hanami/generators/model/repository.rb.tt +1 -2
- data/lib/hanami/generators/template_engine.rb +8 -3
- data/lib/hanami/generators/test_framework.rb +4 -3
- data/lib/hanami/middleware.rb +41 -21
- data/lib/hanami/rake_helper.rb +6 -8
- data/lib/hanami/server.rb +43 -33
- data/lib/hanami/static.rb +2 -2
- data/lib/hanami/version.rb +35 -1
- data/lib/hanami/welcome.rb +4 -5
- metadata +68 -42
- data/lib/hanami/commands/db/abstract.rb +0 -19
- data/lib/hanami/config/configure.rb +0 -17
- data/lib/hanami/config/mapping.rb +0 -12
- data/lib/hanami/container.rb +0 -71
- data/lib/hanami/generators/application/container/gitignore_with_db.tt +0 -4
- data/lib/hanami/loader.rb +0 -257
- data/lib/hanami/repositories/car_repository.rb +0 -3
- data/lib/hanami/repositories/name_repository.rb +0 -3
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
require 'hanami/config/mapper'
|
|
2
|
-
|
|
3
|
-
module Hanami
|
|
4
|
-
module Config
|
|
5
|
-
# Define configuration of application of
|
|
6
|
-
# a specific environment
|
|
7
|
-
#
|
|
8
|
-
# @since 0.2.0
|
|
9
|
-
# @api private
|
|
10
|
-
class Configure < Mapper
|
|
11
|
-
private
|
|
12
|
-
def error_message
|
|
13
|
-
'You must specify a block or a file for configuration definition'
|
|
14
|
-
end
|
|
15
|
-
end
|
|
16
|
-
end
|
|
17
|
-
end
|
data/lib/hanami/container.rb
DELETED
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
require 'thread'
|
|
2
|
-
require 'rack/builder'
|
|
3
|
-
require 'hanami/router'
|
|
4
|
-
|
|
5
|
-
module Hanami
|
|
6
|
-
class Container
|
|
7
|
-
class Mounting
|
|
8
|
-
def self.load!(&blk)
|
|
9
|
-
new.instance_exec(&blk)
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
def mount(app, options)
|
|
13
|
-
app.configuration.path_prefix options.fetch(:at) if hanami_app?(app)
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
private
|
|
17
|
-
|
|
18
|
-
def hanami_app?(app)
|
|
19
|
-
app.ancestors.include? Hanami::Application
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
def method_missing(m, *args)
|
|
23
|
-
end
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
LOCK = Mutex.new
|
|
27
|
-
|
|
28
|
-
attr_reader :routes
|
|
29
|
-
|
|
30
|
-
def self.configure(options = {}, &blk)
|
|
31
|
-
LOCK.synchronize do
|
|
32
|
-
@@options = options
|
|
33
|
-
@@configuration = blk
|
|
34
|
-
|
|
35
|
-
Mounting.load!(&blk)
|
|
36
|
-
end
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
def initialize
|
|
40
|
-
LOCK.synchronize do
|
|
41
|
-
assert_configuration_presence!
|
|
42
|
-
prepare_middleware_stack!
|
|
43
|
-
end
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
def call(env)
|
|
47
|
-
@builder.call(env)
|
|
48
|
-
end
|
|
49
|
-
|
|
50
|
-
private
|
|
51
|
-
|
|
52
|
-
def assert_configuration_presence!
|
|
53
|
-
unless self.class.class_variable_defined?(:@@configuration)
|
|
54
|
-
raise ArgumentError.new("#{ self.class } doesn't have any application mounted.")
|
|
55
|
-
end
|
|
56
|
-
end
|
|
57
|
-
|
|
58
|
-
def prepare_middleware_stack!
|
|
59
|
-
@builder = ::Rack::Builder.new
|
|
60
|
-
@routes = Router.new(&@@configuration)
|
|
61
|
-
|
|
62
|
-
if middleware = Hanami.environment.static_assets_middleware
|
|
63
|
-
@builder.use middleware
|
|
64
|
-
end
|
|
65
|
-
|
|
66
|
-
@builder.use Rack::MethodOverride
|
|
67
|
-
|
|
68
|
-
@builder.run @routes
|
|
69
|
-
end
|
|
70
|
-
end
|
|
71
|
-
end
|
data/lib/hanami/loader.rb
DELETED
|
@@ -1,257 +0,0 @@
|
|
|
1
|
-
require 'hanami/utils/class'
|
|
2
|
-
require 'hanami/utils/kernel'
|
|
3
|
-
require 'hanami/utils/string'
|
|
4
|
-
require 'hanami/routes'
|
|
5
|
-
require 'hanami/routing/default'
|
|
6
|
-
require 'hanami/action/session'
|
|
7
|
-
require 'hanami/config/security'
|
|
8
|
-
require 'hanami/action/routing_helpers'
|
|
9
|
-
|
|
10
|
-
module Hanami
|
|
11
|
-
# Load an application
|
|
12
|
-
#
|
|
13
|
-
# @since 0.1.0
|
|
14
|
-
# @api private
|
|
15
|
-
class Loader
|
|
16
|
-
LOCK = Mutex.new
|
|
17
|
-
|
|
18
|
-
STRICT_TRANSPORT_SECURITY_HEADER = 'Strict-Transport-Security'.freeze
|
|
19
|
-
STRICT_TRANSPORT_SECURITY_DEFAULT_VALUE = 'max-age=31536000'.freeze
|
|
20
|
-
|
|
21
|
-
def initialize(application)
|
|
22
|
-
@application = application
|
|
23
|
-
@configuration = @application.configuration
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
def load!
|
|
27
|
-
LOCK.synchronize do
|
|
28
|
-
load_configuration!
|
|
29
|
-
configure_frameworks!
|
|
30
|
-
load_configuration_load_paths!
|
|
31
|
-
load_rack!
|
|
32
|
-
load_frameworks!
|
|
33
|
-
load_initializers!
|
|
34
|
-
end
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
private
|
|
38
|
-
attr_reader :application, :configuration
|
|
39
|
-
|
|
40
|
-
def load_configuration!
|
|
41
|
-
configuration.load!(application_module)
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
def configure_frameworks!
|
|
45
|
-
_configure_model_framework! if defined?(Hanami::Model)
|
|
46
|
-
_configure_controller_framework!
|
|
47
|
-
_configure_view_framework!
|
|
48
|
-
_configure_assets_framework!
|
|
49
|
-
_configure_logger!
|
|
50
|
-
end
|
|
51
|
-
|
|
52
|
-
def _configure_controller_framework!
|
|
53
|
-
config = configuration
|
|
54
|
-
unless namespace.const_defined?('Controller')
|
|
55
|
-
controller = Hanami::Controller.duplicate(namespace) do
|
|
56
|
-
handle_exceptions config.handle_exceptions
|
|
57
|
-
default_request_format config.default_request_format
|
|
58
|
-
default_response_format config.default_response_format
|
|
59
|
-
default_headers({
|
|
60
|
-
Hanami::Config::Security::X_FRAME_OPTIONS_HEADER => config.security.x_frame_options,
|
|
61
|
-
Hanami::Config::Security::X_CONTENT_TYPE_OPTIONS_HEADER => config.security.x_content_type_options,
|
|
62
|
-
Hanami::Config::Security::X_XSS_PROTECTION_HEADER => config.security.x_xss_protection,
|
|
63
|
-
Hanami::Config::Security::CONTENT_SECURITY_POLICY_HEADER => config.security.content_security_policy,
|
|
64
|
-
})
|
|
65
|
-
default_headers.merge!(STRICT_TRANSPORT_SECURITY_HEADER => STRICT_TRANSPORT_SECURITY_DEFAULT_VALUE) if config.force_ssl
|
|
66
|
-
|
|
67
|
-
if config.cookies.enabled?
|
|
68
|
-
require 'hanami/action/cookies'
|
|
69
|
-
prepare { include Hanami::Action::Cookies }
|
|
70
|
-
cookies config.cookies.default_options
|
|
71
|
-
end
|
|
72
|
-
|
|
73
|
-
if config.sessions.enabled?
|
|
74
|
-
prepare do
|
|
75
|
-
include Hanami::Action::Session
|
|
76
|
-
include Hanami::Action::CSRFProtection
|
|
77
|
-
end
|
|
78
|
-
end
|
|
79
|
-
|
|
80
|
-
prepare { include Hanami::Action::RoutingHelpers }
|
|
81
|
-
|
|
82
|
-
config.controller.__apply(self)
|
|
83
|
-
end
|
|
84
|
-
|
|
85
|
-
namespace.const_set('Controller', controller)
|
|
86
|
-
end
|
|
87
|
-
end
|
|
88
|
-
|
|
89
|
-
def _configure_view_framework!
|
|
90
|
-
config = configuration
|
|
91
|
-
unless namespace.const_defined?('View')
|
|
92
|
-
view = Hanami::View.duplicate(namespace) do
|
|
93
|
-
root config.templates
|
|
94
|
-
layout config.layout
|
|
95
|
-
|
|
96
|
-
config.view.__apply(self)
|
|
97
|
-
end
|
|
98
|
-
|
|
99
|
-
namespace.const_set('View', view)
|
|
100
|
-
end
|
|
101
|
-
end
|
|
102
|
-
|
|
103
|
-
def _configure_assets_framework!
|
|
104
|
-
config = configuration
|
|
105
|
-
|
|
106
|
-
unless application_module.const_defined?('Assets')
|
|
107
|
-
assets = Hanami::Assets.duplicate(namespace) do
|
|
108
|
-
root config.root
|
|
109
|
-
|
|
110
|
-
scheme config.scheme
|
|
111
|
-
host config.host
|
|
112
|
-
port config.port
|
|
113
|
-
|
|
114
|
-
public_directory Hanami.public_directory
|
|
115
|
-
prefix Utils::PathPrefix.new('/assets').join(config.path_prefix)
|
|
116
|
-
|
|
117
|
-
manifest Hanami.public_directory.join('assets.json')
|
|
118
|
-
compile true
|
|
119
|
-
|
|
120
|
-
config.assets.__apply(self)
|
|
121
|
-
end
|
|
122
|
-
|
|
123
|
-
assets.configure do
|
|
124
|
-
cdn host != config.host
|
|
125
|
-
end
|
|
126
|
-
|
|
127
|
-
application_module.const_set('Assets', assets)
|
|
128
|
-
end
|
|
129
|
-
end
|
|
130
|
-
|
|
131
|
-
def _configure_model_framework!
|
|
132
|
-
config = configuration
|
|
133
|
-
if _hanami_model_loaded? && !application_module.const_defined?('Model')
|
|
134
|
-
model = Hanami::Model.duplicate(application_module) do
|
|
135
|
-
adapter(config.adapter) if config.adapter
|
|
136
|
-
mapping(&config.mapping) if config.mapping
|
|
137
|
-
|
|
138
|
-
config.model.__apply(self)
|
|
139
|
-
end
|
|
140
|
-
|
|
141
|
-
application_module.const_set('Model', model)
|
|
142
|
-
end
|
|
143
|
-
end
|
|
144
|
-
|
|
145
|
-
def _configure_logger!
|
|
146
|
-
unless application_module.const_defined?('Logger', false)
|
|
147
|
-
configuration.logger.app_name(application_module.to_s)
|
|
148
|
-
application_module.const_set('Logger', configuration.logger.build)
|
|
149
|
-
end
|
|
150
|
-
end
|
|
151
|
-
|
|
152
|
-
def load_frameworks!
|
|
153
|
-
_load_view_framework!
|
|
154
|
-
_load_assets_framework!
|
|
155
|
-
_load_model_framework!
|
|
156
|
-
end
|
|
157
|
-
|
|
158
|
-
def _load_view_framework!
|
|
159
|
-
namespace.module_eval %{
|
|
160
|
-
#{ namespace }::View.load!
|
|
161
|
-
}
|
|
162
|
-
end
|
|
163
|
-
|
|
164
|
-
def _load_assets_framework!
|
|
165
|
-
application_module.module_eval %{
|
|
166
|
-
#{ application_module }::Assets.load!
|
|
167
|
-
}
|
|
168
|
-
end
|
|
169
|
-
|
|
170
|
-
def _load_model_framework!
|
|
171
|
-
return unless _load_model_framework?
|
|
172
|
-
|
|
173
|
-
application_module.module_eval %{
|
|
174
|
-
#{ application_module }::Model.load!
|
|
175
|
-
}
|
|
176
|
-
end
|
|
177
|
-
|
|
178
|
-
def _load_model_framework?
|
|
179
|
-
if _hanami_model_loaded? && application_module.const_defined?('Model')
|
|
180
|
-
model = application_module.const_get('Model')
|
|
181
|
-
model.configuration.adapter
|
|
182
|
-
end
|
|
183
|
-
end
|
|
184
|
-
|
|
185
|
-
def _hanami_model_loaded?
|
|
186
|
-
defined?(Hanami::Model)
|
|
187
|
-
end
|
|
188
|
-
|
|
189
|
-
def _hanami_mailer_loaded?
|
|
190
|
-
defined?(Hanami::Mailer)
|
|
191
|
-
end
|
|
192
|
-
|
|
193
|
-
def load_configuration_load_paths!
|
|
194
|
-
configuration.load_paths.load!(configuration.root)
|
|
195
|
-
end
|
|
196
|
-
|
|
197
|
-
def load_rack!
|
|
198
|
-
_assign_routes_to_application_module!
|
|
199
|
-
|
|
200
|
-
return if application.is_a?(Class)
|
|
201
|
-
_assign_rendering_policy!
|
|
202
|
-
_assign_rack_routes!
|
|
203
|
-
_load_rack_middleware!
|
|
204
|
-
end
|
|
205
|
-
|
|
206
|
-
def _assign_rendering_policy!
|
|
207
|
-
application.renderer = RenderingPolicy.new(configuration)
|
|
208
|
-
end
|
|
209
|
-
|
|
210
|
-
def _assign_rack_routes!
|
|
211
|
-
application.routes = application_routes
|
|
212
|
-
end
|
|
213
|
-
|
|
214
|
-
def _load_rack_middleware!
|
|
215
|
-
configuration.middleware.load!(application, namespace)
|
|
216
|
-
end
|
|
217
|
-
|
|
218
|
-
def _assign_routes_to_application_module!
|
|
219
|
-
unless application_module.const_defined?('Routes')
|
|
220
|
-
routes = Hanami::Routes.new(application_routes)
|
|
221
|
-
application_module.const_set('Routes', routes)
|
|
222
|
-
end
|
|
223
|
-
end
|
|
224
|
-
|
|
225
|
-
def application_module
|
|
226
|
-
@application_module ||= Utils::Class.load!(
|
|
227
|
-
Utils::String.new(application.name).namespace
|
|
228
|
-
)
|
|
229
|
-
end
|
|
230
|
-
|
|
231
|
-
def application_routes
|
|
232
|
-
resolver = Hanami::Routing::EndpointResolver.new(pattern: configuration.controller_pattern, namespace: namespace)
|
|
233
|
-
default_app = Hanami::Routing::Default.new
|
|
234
|
-
Hanami::Router.new(
|
|
235
|
-
parsers: configuration.body_parsers,
|
|
236
|
-
resolver: resolver,
|
|
237
|
-
default_app: default_app,
|
|
238
|
-
scheme: configuration.scheme,
|
|
239
|
-
host: configuration.host,
|
|
240
|
-
port: configuration.port,
|
|
241
|
-
prefix: configuration.path_prefix,
|
|
242
|
-
force_ssl: configuration.force_ssl,
|
|
243
|
-
&configuration.routes
|
|
244
|
-
)
|
|
245
|
-
end
|
|
246
|
-
|
|
247
|
-
def namespace
|
|
248
|
-
configuration.namespace || application_module
|
|
249
|
-
end
|
|
250
|
-
|
|
251
|
-
def load_initializers!
|
|
252
|
-
Dir["#{configuration.root}/config/initializers/**/*.rb"].sort.each do |file|
|
|
253
|
-
require file
|
|
254
|
-
end
|
|
255
|
-
end
|
|
256
|
-
end
|
|
257
|
-
end
|