hanami 0.8.0 → 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- 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
data/lib/hanami/config/mapper.rb
CHANGED
@@ -6,26 +6,18 @@ module Hanami
|
|
6
6
|
class Security
|
7
7
|
# @since 0.3.0
|
8
8
|
# @api private
|
9
|
-
#
|
10
|
-
# @see Hanami::Loader#_configure_controller_framework!
|
11
9
|
X_FRAME_OPTIONS_HEADER = 'X-Frame-Options'.freeze
|
12
10
|
|
13
11
|
# @since 0.8.0
|
14
12
|
# @api private
|
15
|
-
#
|
16
|
-
# @see Hanami::Loader#_configure_controller_framework!
|
17
13
|
X_CONTENT_TYPE_OPTIONS_HEADER = 'X-Content-Type-Options'.freeze
|
18
14
|
|
19
15
|
# @since 0.8.0
|
20
16
|
# @api private
|
21
|
-
#
|
22
|
-
# @see Hanami::Loader#_configure_controller_framework!
|
23
17
|
X_XSS_PROTECTION_HEADER = 'X-XSS-Protection'.freeze
|
24
18
|
|
25
19
|
# @since 0.3.0
|
26
20
|
# @api private
|
27
|
-
#
|
28
|
-
# @see Hanami::Loader#_configure_controller_framework!
|
29
21
|
CONTENT_SECURITY_POLICY_HEADER = 'Content-Security-Policy'.freeze
|
30
22
|
|
31
23
|
# @since 0.8.0
|
data/lib/hanami/configuration.rb
CHANGED
@@ -1,1723 +1,53 @@
|
|
1
|
-
require '
|
2
|
-
require '
|
3
|
-
require 'hanami/
|
4
|
-
require 'hanami/
|
5
|
-
require 'hanami/
|
6
|
-
require 'hanami/config/framework_configuration'
|
7
|
-
require 'hanami/config/load_paths'
|
8
|
-
require 'hanami/config/logger'
|
9
|
-
require 'hanami/config/mapping'
|
10
|
-
require 'hanami/config/routes'
|
11
|
-
require 'hanami/config/security'
|
12
|
-
require 'hanami/config/sessions'
|
1
|
+
require 'concurrent'
|
2
|
+
require 'delegate'
|
3
|
+
require 'hanami/application'
|
4
|
+
require 'hanami/utils/class'
|
5
|
+
require 'hanami/utils/string'
|
13
6
|
|
14
7
|
module Hanami
|
15
|
-
# Configuration for a Hanami application
|
16
|
-
#
|
17
|
-
# @since 0.1.0
|
18
8
|
class Configuration
|
19
|
-
|
20
|
-
|
21
|
-
#
|
22
|
-
# @see Hanami::Configuration#ssl?
|
23
|
-
SSL_SCHEME = 'https'.freeze
|
9
|
+
class App < SimpleDelegator
|
10
|
+
attr_reader :path_prefix
|
24
11
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
#
|
29
|
-
# @since 0.1.0
|
30
|
-
# @api private
|
31
|
-
def initialize
|
32
|
-
@blk = Proc.new{}
|
33
|
-
@env = Environment.new
|
34
|
-
@configurations = Hash.new { |k, v| k[v] = [] }
|
35
|
-
end
|
36
|
-
|
37
|
-
# Set a block yield when the configuration will be loaded or
|
38
|
-
# set a path for the specific environment.
|
39
|
-
#
|
40
|
-
# @param environment [Symbol,nil] the configuration environment name
|
41
|
-
# @param blk [Proc] the configuration block
|
42
|
-
#
|
43
|
-
# @return [self]
|
44
|
-
#
|
45
|
-
# @since 0.1.0
|
46
|
-
# @api private
|
47
|
-
def configure(environment = nil, path = nil, &blk)
|
48
|
-
if environment && path
|
49
|
-
@configurations[environment.to_s] << Config::Configure.new(root, path, &blk)
|
50
|
-
elsif environment
|
51
|
-
@configurations[environment.to_s] << blk
|
52
|
-
else
|
53
|
-
@blk = blk
|
12
|
+
def initialize(app, path_prefix)
|
13
|
+
super(app)
|
14
|
+
@path_prefix = path_prefix
|
54
15
|
end
|
55
|
-
|
56
|
-
self
|
57
16
|
end
|
58
17
|
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
#
|
63
|
-
# @return [self]
|
64
|
-
#
|
65
|
-
# @since 0.1.0
|
66
|
-
# @api private
|
67
|
-
def load!(namespace = nil)
|
68
|
-
@namespace = namespace
|
69
|
-
evaluate_configurations!
|
70
|
-
|
71
|
-
self
|
18
|
+
def initialize(&blk)
|
19
|
+
@settings = Concurrent::Map.new
|
20
|
+
instance_eval(&blk)
|
72
21
|
end
|
73
22
|
|
74
|
-
|
75
|
-
|
76
|
-
# @return [Hanami::Config::Security]
|
77
|
-
#
|
78
|
-
# @since 0.3.0
|
79
|
-
#
|
80
|
-
# @see Hanami::Config::Security
|
81
|
-
#
|
82
|
-
# @example Getting values
|
83
|
-
# require 'hanami'
|
84
|
-
#
|
85
|
-
# module Bookshelf
|
86
|
-
# class Application < Hanami::Application
|
87
|
-
# configure do
|
88
|
-
# security.x_frame_options "ALLOW ALL"
|
89
|
-
# security.content_security_policy "script-src 'self' https://apis.example.com"
|
90
|
-
# end
|
91
|
-
# end
|
92
|
-
# end
|
93
|
-
#
|
94
|
-
# Bookshelf::Application.configuration.security.x_frame_options # => "ALLOW ALL"
|
95
|
-
# Bookshelf::Application.configuration.security.content_security_policy # => "script-src 'self' https://apis.example.com"
|
96
|
-
#
|
97
|
-
# @example Setting values
|
98
|
-
# require 'hanami'
|
99
|
-
#
|
100
|
-
# module Bookshelf
|
101
|
-
# class Application < Hanami::Application
|
102
|
-
# configure do
|
103
|
-
# security.x_frame_options "ALLOW ALL"
|
104
|
-
# security.content_security_policy "script-src 'self' https://apis.example.com"
|
105
|
-
# end
|
106
|
-
# end
|
107
|
-
# end
|
108
|
-
def security
|
109
|
-
@security ||= Config::Security.new
|
23
|
+
def mount(app, options)
|
24
|
+
mounted[app] = App.new(app, options.fetch(:at))
|
110
25
|
end
|
111
26
|
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
#
|
116
|
-
# @since 0.4.0
|
117
|
-
#
|
118
|
-
# @see Hanami::Routing::ForceSsl
|
119
|
-
def force_ssl(value = nil)
|
120
|
-
if value
|
121
|
-
@force_ssl = value
|
27
|
+
def model(&blk)
|
28
|
+
if block_given?
|
29
|
+
settings.put_if_absent(:model, blk)
|
122
30
|
else
|
123
|
-
|
31
|
+
settings.fetch(:model)
|
124
32
|
end
|
125
33
|
end
|
126
34
|
|
127
|
-
|
128
|
-
|
129
|
-
# By default it returns the current directory, for this reason, **all the
|
130
|
-
# commands must be executed from the top level directory of the project**.
|
131
|
-
#
|
132
|
-
# If for some reason, that constraint above cannot be satisfied, please
|
133
|
-
# configure the root directory, so that commands can be executed from
|
134
|
-
# everywhere.
|
135
|
-
#
|
136
|
-
# This is part of a DSL, for this reason when this method is called with
|
137
|
-
# an argument, it will set the corresponding instance variable. When
|
138
|
-
# called without, it will return the already set value, or the default.
|
139
|
-
#
|
140
|
-
# @overload root(value)
|
141
|
-
# Sets the given value
|
142
|
-
# @param value [String,Pathname,#to_pathname] The root directory of the app
|
143
|
-
#
|
144
|
-
# @overload root
|
145
|
-
# Gets the value
|
146
|
-
# @return [Pathname]
|
147
|
-
# @raise [Errno::ENOENT] if the path cannot be found
|
148
|
-
#
|
149
|
-
# @since 0.1.0
|
150
|
-
#
|
151
|
-
# @see http://www.ruby-doc.org/core-2.1.2/Dir.html#method-c-pwd
|
152
|
-
#
|
153
|
-
# @example Getting the value
|
154
|
-
# require 'hanami'
|
155
|
-
#
|
156
|
-
# module Bookshelf
|
157
|
-
# class Application < Hanami::Application
|
158
|
-
# end
|
159
|
-
# end
|
160
|
-
#
|
161
|
-
# Bookshelf::Application.configuration.root # => #<Pathname:/path/to/root>
|
162
|
-
#
|
163
|
-
# @example Setting the value
|
164
|
-
# require 'hanami'
|
165
|
-
#
|
166
|
-
# module Bookshelf
|
167
|
-
# class Application < Hanami::Application
|
168
|
-
# configure do
|
169
|
-
# root '/path/to/another/root'
|
170
|
-
# end
|
171
|
-
# end
|
172
|
-
# end
|
173
|
-
def root(value = nil)
|
174
|
-
if value
|
175
|
-
@root = value
|
176
|
-
else
|
177
|
-
Utils::Kernel.Pathname(@root || Dir.pwd).realpath
|
178
|
-
end
|
35
|
+
def mailer(&blk)
|
36
|
+
settings.put_if_absent(:mailer, blk)
|
179
37
|
end
|
180
38
|
|
181
|
-
|
182
|
-
|
183
|
-
# By default it returns the Ruby namespace of the application. For instance
|
184
|
-
# for an application `Bookshelf::Application`, it returns `Bookshelf`.
|
185
|
-
#
|
186
|
-
# This value isn't set at the init time, but when the configuration is
|
187
|
-
# loaded with `#load!`.
|
188
|
-
#
|
189
|
-
# Hanami applications are namespaced: all the controllers and views live
|
190
|
-
# under the application module, without polluting the global namespace.
|
191
|
-
# However, if for some reason, you want top level classes, set this value
|
192
|
-
# to `Object` (which is the top level namespace for Ruby).
|
193
|
-
#
|
194
|
-
# This is part of a DSL, for this reason when this method is called with
|
195
|
-
# an argument, it will set the corresponding instance variable. When
|
196
|
-
# called without, it will return the already set value, or the default.
|
197
|
-
#
|
198
|
-
# @overload namespace(value)
|
199
|
-
# Sets the given value
|
200
|
-
# @param value [Class,Module] A valid Ruby namespace
|
201
|
-
#
|
202
|
-
# @overload namespace
|
203
|
-
# Gets the value
|
204
|
-
# @return [Class,Module] a Ruby namespace
|
205
|
-
#
|
206
|
-
# @since 0.1.0
|
207
|
-
#
|
208
|
-
# @example Getting the value
|
209
|
-
# require 'hanami'
|
210
|
-
#
|
211
|
-
# module Bookshelf
|
212
|
-
# class Application < Hanami::Application
|
213
|
-
# end
|
214
|
-
# end
|
215
|
-
#
|
216
|
-
# Bookshelf::Application.configuration.namespace # => Bookshelf
|
217
|
-
#
|
218
|
-
# # It will lookup namespaced controllers under Bookshelf
|
219
|
-
# # eg. Bookshelf::Controllers::Dashboard
|
220
|
-
#
|
221
|
-
# @example Setting the value
|
222
|
-
# require 'hanami'
|
223
|
-
#
|
224
|
-
# module Bookshelf
|
225
|
-
# class Application < Hanami::Application
|
226
|
-
# configure do
|
227
|
-
# namespace Object
|
228
|
-
# end
|
229
|
-
# end
|
230
|
-
# end
|
231
|
-
#
|
232
|
-
# Bookshelf::Application.configuration.namespace # => Object
|
233
|
-
#
|
234
|
-
# # It will lookup top level controllers under Object
|
235
|
-
# # eg. DashboardController
|
236
|
-
def namespace(value = nil)
|
237
|
-
if value
|
238
|
-
@namespace = value
|
239
|
-
else
|
240
|
-
@namespace
|
241
|
-
end
|
39
|
+
def mounted
|
40
|
+
settings.fetch_or_store(:mounted, {})
|
242
41
|
end
|
243
42
|
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
#
|
248
|
-
# It accepts a Symbol as layout name. When the application is loaded, it
|
249
|
-
# will lookup for the corresponding class.
|
250
|
-
#
|
251
|
-
# All the views will use this layout, unless otherwise specified.
|
252
|
-
#
|
253
|
-
# This is part of a DSL, for this reason when this method is called with
|
254
|
-
# an argument, it will set the corresponding instance variable. When
|
255
|
-
# called without, it will return the already set value, or the default.
|
256
|
-
#
|
257
|
-
# @overload layout(value)
|
258
|
-
# Sets the given value
|
259
|
-
# @param value [Symbol] the layout name
|
260
|
-
#
|
261
|
-
# @overload layout
|
262
|
-
# Gets the value
|
263
|
-
# @return [Symbol,nil] the layout name
|
264
|
-
#
|
265
|
-
# @since 0.1.0
|
266
|
-
#
|
267
|
-
# @see http://rdoc.info/gems/hanami-view/Hanami/Layout
|
268
|
-
# @see http://rdoc.info/gems/hanami-view/Hanami/View/Configuration:layout
|
269
|
-
#
|
270
|
-
# @example Getting the value
|
271
|
-
# require 'hanami'
|
272
|
-
#
|
273
|
-
# module Bookshelf
|
274
|
-
# class Application < Hanami::Application
|
275
|
-
# end
|
276
|
-
# end
|
277
|
-
#
|
278
|
-
# Bookshelf::Application.configuration.layout # => nil
|
279
|
-
#
|
280
|
-
# # All the views will render without a layout
|
281
|
-
#
|
282
|
-
# @example Setting the value
|
283
|
-
# require 'hanami'
|
284
|
-
#
|
285
|
-
# module Bookshelf
|
286
|
-
# class Application < Hanami::Application
|
287
|
-
# configure do
|
288
|
-
# layout :application
|
289
|
-
# end
|
290
|
-
# end
|
291
|
-
#
|
292
|
-
# module Views
|
293
|
-
# module Dashboard
|
294
|
-
# class Index
|
295
|
-
# include Bookshelf::Views
|
296
|
-
# end
|
297
|
-
#
|
298
|
-
# class JsonIndex < Index
|
299
|
-
# layout nil
|
300
|
-
# end
|
301
|
-
# end
|
302
|
-
# end
|
303
|
-
# end
|
304
|
-
#
|
305
|
-
# Bookshelf::Application.configuration.namespace layout => :application
|
306
|
-
#
|
307
|
-
# # All the views will use Bookshelf::Views::ApplicationLayout, unless
|
308
|
-
# # they set a different value.
|
309
|
-
#
|
310
|
-
# Bookshelf::Views::Dashboard::Index.layout
|
311
|
-
# # => Bookshelf::Views::ApplicationLayout
|
312
|
-
#
|
313
|
-
# Bookshelf::Views::Dashboard::JsonIndex.layout
|
314
|
-
# # => Hanami::View::Rendering::NullLayout
|
315
|
-
def layout(value = nil)
|
316
|
-
if value
|
317
|
-
@layout = value
|
318
|
-
else
|
319
|
-
@layout
|
320
|
-
end
|
321
|
-
end
|
322
|
-
|
323
|
-
# Templates root.
|
324
|
-
# The application will recursively look for templates under this path.
|
325
|
-
#
|
326
|
-
# By default it's equal to the application `root`.
|
327
|
-
#
|
328
|
-
# Otherwise, you can specify a different relative path under `root`.
|
329
|
-
#
|
330
|
-
# This is part of a DSL, for this reason when this method is called with
|
331
|
-
# an argument, it will set the corresponding instance variable. When
|
332
|
-
# called without, it will return the already set value, or the default.
|
333
|
-
#
|
334
|
-
# @overload templates(value)
|
335
|
-
# Sets the given value
|
336
|
-
# @param value [String] the relative path to the templates root.
|
337
|
-
#
|
338
|
-
# @overload templates
|
339
|
-
# Gets the value
|
340
|
-
# @return [Pathname] templates root
|
341
|
-
#
|
342
|
-
# @since 0.1.0
|
343
|
-
#
|
344
|
-
# @see Hanami::Configuration#root
|
345
|
-
# @see http://rdoc.info/gems/hanami-view/Hanami/View/Configuration:root
|
346
|
-
#
|
347
|
-
# @example Getting the value
|
348
|
-
# require 'hanami'
|
349
|
-
#
|
350
|
-
# module Bookshelf
|
351
|
-
# class Application < Hanami::Application
|
352
|
-
# end
|
353
|
-
# end
|
354
|
-
#
|
355
|
-
# Bookshelf::Application.configuration.templates
|
356
|
-
# # => #<Pathname:/root/path>
|
357
|
-
#
|
358
|
-
# @example Setting the value
|
359
|
-
# require 'hanami'
|
360
|
-
#
|
361
|
-
# module Bookshelf
|
362
|
-
# class Application < Hanami::Application
|
363
|
-
# configure do
|
364
|
-
# templates 'app/templates'
|
365
|
-
# end
|
366
|
-
# end
|
367
|
-
# end
|
368
|
-
#
|
369
|
-
# Bookshelf::Application.configuration.templates
|
370
|
-
# # => #<Pathname:/root/path/app/templates>
|
371
|
-
def templates(value = nil)
|
372
|
-
if value
|
373
|
-
@templates = value
|
374
|
-
else
|
375
|
-
root.join @templates.to_s
|
376
|
-
end
|
377
|
-
end
|
378
|
-
|
379
|
-
# The application will serve the static assets under these directories.
|
380
|
-
#
|
381
|
-
# By default it's equal to the `public/` directory under the application
|
382
|
-
# `root`.
|
383
|
-
#
|
384
|
-
# Otherwise, you can add different relatives paths under `root`.
|
385
|
-
#
|
386
|
-
# @overload assets
|
387
|
-
# Gets the value
|
388
|
-
# @return [Hanami::Config::Assets] assets root
|
389
|
-
#
|
390
|
-
# @since 0.1.0
|
391
|
-
#
|
392
|
-
# @example Getting the value
|
393
|
-
# require 'hanami'
|
394
|
-
#
|
395
|
-
# module Bookshelf
|
396
|
-
# class Application < Hanami::Application
|
397
|
-
# end
|
398
|
-
# end
|
399
|
-
#
|
400
|
-
# Bookshelf::Application.configuration.assets
|
401
|
-
# # => #<Pathname:/root/path/public>
|
402
|
-
#
|
403
|
-
# @example Adding new assets paths
|
404
|
-
# require 'hanami'
|
405
|
-
#
|
406
|
-
# module Bookshelf
|
407
|
-
# class Application < Hanami::Application
|
408
|
-
# configure do
|
409
|
-
# assets do
|
410
|
-
# sources << [
|
411
|
-
# 'vendor/assets'
|
412
|
-
# ]
|
413
|
-
# end
|
414
|
-
# end
|
415
|
-
# end
|
416
|
-
# end
|
417
|
-
#
|
418
|
-
# Bookshelf::Application.configuration.assets
|
419
|
-
# # => #<Hanami::Config::Assets @root=#<Pathname:/root/path/assets>, @paths=["public"]>
|
420
|
-
def assets(&blk)
|
421
|
-
if @assets
|
422
|
-
@assets.__add(&blk)
|
423
|
-
else
|
424
|
-
@assets ||= Config::FrameworkConfiguration.new(&blk)
|
425
|
-
end
|
426
|
-
end
|
427
|
-
|
428
|
-
# Configure cookies
|
429
|
-
# Enable cookies (disabled by default).
|
430
|
-
#
|
431
|
-
# This is part of a DSL, for this reason when this method is called with
|
432
|
-
# an argument, it will set the corresponding instance variable. When
|
433
|
-
# called without, it will return the already set value, or the default.
|
434
|
-
#
|
435
|
-
# @overload cookies(options)
|
436
|
-
# Sets the given value with their options.
|
437
|
-
# @param options [Hash, TrueClass, FalseClass]
|
438
|
-
#
|
439
|
-
# @overload cookies
|
440
|
-
# Gets the value.
|
441
|
-
# @return [Hanami::Config::Cookies]
|
442
|
-
#
|
443
|
-
# @example Getting the value
|
444
|
-
# require 'hanami'
|
445
|
-
#
|
446
|
-
# module Bookshelf
|
447
|
-
# class Application < Hanami::Application
|
448
|
-
# end
|
449
|
-
# end
|
450
|
-
#
|
451
|
-
# Bookshelf::Application.configuration.cookies
|
452
|
-
# # => #<Hanami::Config::Cookies:0x0000000329f880 @options={}, @default_options={:httponly=>true, :secure=>false}>
|
453
|
-
#
|
454
|
-
# @example Setting the value
|
455
|
-
# require 'hanami'
|
456
|
-
#
|
457
|
-
# module Bookshelf
|
458
|
-
# class Application < Hanami::Application
|
459
|
-
# configure do
|
460
|
-
# cookies domain: 'hanamirb.org'
|
461
|
-
# end
|
462
|
-
# end
|
463
|
-
# end
|
464
|
-
#
|
465
|
-
# Bookshelf::Application.configuration.cookies
|
466
|
-
# # => #<Hanami::Config::Cookies:0x0000000329f880 @options={:domain=>'hanamirb.org'}, @default_options={:domain=>'hanamirb.org', :httponly=>true, :secure=>false}>
|
467
|
-
def cookies(options = nil)
|
468
|
-
if options.nil?
|
469
|
-
@cookies ||= Config::Cookies.new(self, options)
|
470
|
-
else
|
471
|
-
@cookies = Config::Cookies.new(self, options)
|
472
|
-
end
|
473
|
-
end
|
474
|
-
|
475
|
-
# Configure sessions
|
476
|
-
# Enable sessions (disabled by default).
|
477
|
-
#
|
478
|
-
# This is part of a DSL, for this reason when this method is called with
|
479
|
-
# an argument, it will set the corresponding instance variable. When
|
480
|
-
# called without, it will return the already set value, or the default.
|
481
|
-
#
|
482
|
-
# Given Class as adapter it will be used as sessions middleware.
|
483
|
-
# Given String as adapter it will be resolved as class name and used as
|
484
|
-
# sessions middleware.
|
485
|
-
# Given Symbol as adapter it is assumed it's name of the class under
|
486
|
-
# Rack::Session namespace that will be used as sessions middleware
|
487
|
-
# (e.g. :cookie for Rack::Session::Cookie).
|
488
|
-
#
|
489
|
-
# By default options include domain inferred from host configuration, and
|
490
|
-
# secure flag inferred from scheme configuration.
|
491
|
-
#
|
492
|
-
# @overload sessions(adapter, options)
|
493
|
-
# Sets the given value.
|
494
|
-
# @param adapter [Class, String, Symbol] Rack middleware for sessions management
|
495
|
-
# @param options [Hash] options to pass to sessions middleware
|
496
|
-
#
|
497
|
-
# @overload sessions(false)
|
498
|
-
# Disables sessions
|
499
|
-
#
|
500
|
-
# @overload sessions
|
501
|
-
# Gets the value.
|
502
|
-
# @return [Hanami::Config::Sessions] sessions configuration
|
503
|
-
#
|
504
|
-
# @since 0.2.0
|
505
|
-
#
|
506
|
-
# @see Hanami::Configuration#host
|
507
|
-
# @see Hanami::Configuration#scheme
|
508
|
-
#
|
509
|
-
# @example Getting the value
|
510
|
-
# require 'hanami'
|
511
|
-
#
|
512
|
-
# module Bookshelf
|
513
|
-
# class Application < Hanami::Application
|
514
|
-
# end
|
515
|
-
# end
|
516
|
-
#
|
517
|
-
# Bookshelf::Application.configuration.sessions
|
518
|
-
# # => #<Hanami::Config::Sessions:0x00000001ca0c28 @enabled=false>
|
519
|
-
#
|
520
|
-
# @example Setting the value with symbol
|
521
|
-
# require 'hanami'
|
522
|
-
#
|
523
|
-
# module Bookshelf
|
524
|
-
# class Application < Hanami::Application
|
525
|
-
# configure do
|
526
|
-
# sessions :cookie, secret: 'abc123'
|
527
|
-
# end
|
528
|
-
# end
|
529
|
-
# end
|
530
|
-
#
|
531
|
-
# Bookshelf::Application.configuration.sessions
|
532
|
-
# # => #<Hanami::Config::Sessions:0x00000001589458 @enabled=true, @adapter=:cookie, @options={:domain=>"localhost", :secure=>false}>
|
533
|
-
#
|
534
|
-
# @example Disabling previously enabled sessions
|
535
|
-
# require 'hanami'
|
536
|
-
#
|
537
|
-
# module Bookshelf
|
538
|
-
# class Application < Hanami::Application
|
539
|
-
# configure do
|
540
|
-
# sessions :cookie
|
541
|
-
# sessions false
|
542
|
-
# end
|
543
|
-
# end
|
544
|
-
# end
|
545
|
-
#
|
546
|
-
# Bookshelf::Application.configuration.sessions
|
547
|
-
# # => #<Hanami::Config::Sessions:0x00000002460d78 @enabled=false>
|
548
|
-
#
|
549
|
-
def sessions(adapter = nil, options = {})
|
550
|
-
if adapter.nil?
|
551
|
-
@sessions ||= Config::Sessions.new
|
552
|
-
else
|
553
|
-
@sessions = Config::Sessions.new(adapter, options, self)
|
554
|
-
end
|
555
|
-
end
|
556
|
-
|
557
|
-
# Application load paths
|
558
|
-
# The application will recursively load all the Ruby files under these paths.
|
559
|
-
#
|
560
|
-
# By default it's empty in order to allow developers to decide their own
|
561
|
-
# app structure.
|
562
|
-
#
|
563
|
-
# @return [Hanami::Config::LoadPaths] a set of load paths
|
564
|
-
#
|
565
|
-
# @since 0.1.0
|
566
|
-
#
|
567
|
-
# @see Hanami::Configuration#root
|
568
|
-
#
|
569
|
-
# @example Getting the value
|
570
|
-
# require 'hanami'
|
571
|
-
#
|
572
|
-
# module Bookshelf
|
573
|
-
# class Application < Hanami::Application
|
574
|
-
# end
|
575
|
-
# end
|
576
|
-
#
|
577
|
-
# Bookshelf::Application.configuration.load_paths
|
578
|
-
# # => #<Hanami::Config::LoadPaths:0x007ff4fa212310 @paths=[]>
|
579
|
-
#
|
580
|
-
# @example Setting the value
|
581
|
-
# require 'hanami'
|
582
|
-
#
|
583
|
-
# module Bookshelf
|
584
|
-
# class Application < Hanami::Application
|
585
|
-
# configure do
|
586
|
-
# load_paths << [
|
587
|
-
# 'app/controllers',
|
588
|
-
# 'app/views
|
589
|
-
# ]
|
590
|
-
# end
|
591
|
-
# end
|
592
|
-
# end
|
593
|
-
#
|
594
|
-
# Bookshelf::Application.configuration.assets
|
595
|
-
# # => #<Hanami::Config::LoadPaths:0x007fe3a20b18e0 @paths=[["app/controllers", "app/views"]]>
|
596
|
-
def load_paths
|
597
|
-
@load_paths ||= Config::LoadPaths.new
|
598
|
-
end
|
599
|
-
|
600
|
-
# Application routes.
|
601
|
-
#
|
602
|
-
# Specify a set of routes for the application, by passing a block, or a
|
603
|
-
# relative path where to find the file that describes them.
|
604
|
-
#
|
605
|
-
# By default it's `nil`.
|
606
|
-
#
|
607
|
-
# This is part of a DSL, for this reason when this method is called with
|
608
|
-
# an argument, it will set the corresponding instance variable. When
|
609
|
-
# called without, it will return the already set value, or the default.
|
610
|
-
#
|
611
|
-
# @overload routes(blk)
|
612
|
-
# Specify a set of routes in the given block
|
613
|
-
# @param blk [Proc] the routes definitions
|
614
|
-
#
|
615
|
-
# @overload routes(path)
|
616
|
-
# Specify a relative path where to find the routes file
|
617
|
-
# @param path [String] the relative path
|
618
|
-
#
|
619
|
-
# @overload routes
|
620
|
-
# Gets the value
|
621
|
-
# @return [Hanami::Config::Routes] the set of routes
|
622
|
-
#
|
623
|
-
# @since 0.1.0
|
624
|
-
#
|
625
|
-
# @see http://rdoc.info/gems/hanami-router/Hanami/Router
|
626
|
-
#
|
627
|
-
# @example Getting the value
|
628
|
-
# require 'hanami'
|
629
|
-
#
|
630
|
-
# module Bookshelf
|
631
|
-
# class Application < Hanami::Application
|
632
|
-
# end
|
633
|
-
# end
|
634
|
-
#
|
635
|
-
# Bookshelf::Application.configuration.routes
|
636
|
-
# # => nil
|
637
|
-
#
|
638
|
-
# @example Setting the value, by passing a block
|
639
|
-
# require 'hanami'
|
640
|
-
#
|
641
|
-
# module Bookshelf
|
642
|
-
# class Application < Hanami::Application
|
643
|
-
# configure do
|
644
|
-
# routes do
|
645
|
-
# get '/', to: 'dashboard#index'
|
646
|
-
# resources :books
|
647
|
-
# end
|
648
|
-
# end
|
649
|
-
# end
|
650
|
-
# end
|
651
|
-
#
|
652
|
-
# Bookshelf::Application.configuration.routes
|
653
|
-
# # => #<Hanami::Config::Routes:0x007ff50a991388 @blk=#<Proc:0x007ff50a991338@(irb):4>, @path=#<Pathname:.>>
|
654
|
-
#
|
655
|
-
# @example Setting the value, by passing a relative path
|
656
|
-
# require 'hanami'
|
657
|
-
#
|
658
|
-
# module Bookshelf
|
659
|
-
# class Application < Hanami::Application
|
660
|
-
# configure do
|
661
|
-
# routes 'config/routes'
|
662
|
-
# end
|
663
|
-
# end
|
664
|
-
# end
|
665
|
-
#
|
666
|
-
# Bookshelf::Application.configuration.routes
|
667
|
-
# # => #<Hanami::Config::Routes:0x007ff50a991388 @blk=nil, @path=#<Pathname:config/routes.rb>>
|
668
|
-
def routes(path = nil, &blk)
|
669
|
-
if path or block_given?
|
670
|
-
@routes = Config::Routes.new(root, path, &blk)
|
671
|
-
else
|
672
|
-
@routes
|
673
|
-
end
|
674
|
-
end
|
675
|
-
|
676
|
-
# Body parsing configuration.
|
677
|
-
#
|
678
|
-
# Specify a set of parsers for specific mime types that your application will use. This method will
|
679
|
-
# return the application's parsers which you can use to add existing and new custom parsers for your
|
680
|
-
# application to use.
|
681
|
-
#
|
682
|
-
# By default it's an empty `Array`
|
683
|
-
#
|
684
|
-
# This is part of a DSL, for this reason when this method is called with
|
685
|
-
# an argument, it will set the corresponding instance variable. When
|
686
|
-
# called without, it will return the already set value, or the default.
|
687
|
-
#
|
688
|
-
# @overload body_parsers(parsers)
|
689
|
-
# Specify a set of body parsers.
|
690
|
-
# @param parsers [Array] the body parser definitions
|
691
|
-
#
|
692
|
-
# @overload body_parsers
|
693
|
-
# Gets the value
|
694
|
-
# @return [Array] the set of parsers
|
695
|
-
#
|
696
|
-
# @since 0.2.0
|
697
|
-
#
|
698
|
-
# @example Getting the value
|
699
|
-
# require 'hanami'
|
700
|
-
#
|
701
|
-
# module Bookshelf
|
702
|
-
# class Application < Hanami::Application
|
703
|
-
# end
|
704
|
-
# end
|
705
|
-
#
|
706
|
-
# Bookshelf::Application.configuration.body_parsers
|
707
|
-
# # => []
|
708
|
-
#
|
709
|
-
# @example Setting the value
|
710
|
-
# require 'hanami'
|
711
|
-
#
|
712
|
-
# module Bookshelf
|
713
|
-
# class Application < Hanami::Application
|
714
|
-
# configure do
|
715
|
-
# body_parsers :json, XmlParser.new
|
716
|
-
# end
|
717
|
-
# end
|
718
|
-
# end
|
719
|
-
#
|
720
|
-
# Bookshelf::Application.configuration.body_parsers
|
721
|
-
# # => [:json, XmlParser.new]
|
722
|
-
#
|
723
|
-
# @example Setting a new value after one is set.
|
724
|
-
# require 'hanami'
|
725
|
-
#
|
726
|
-
# module Bookshelf
|
727
|
-
# class Application < Hanami::Application
|
728
|
-
# configure do
|
729
|
-
# body_parsers :json
|
730
|
-
# body_parsers XmlParser.new
|
731
|
-
# end
|
732
|
-
# end
|
733
|
-
# end
|
734
|
-
#
|
735
|
-
# Bookshelf::Application.configuration.body_parsers
|
736
|
-
# # => [XmlParser.new]
|
737
|
-
#
|
738
|
-
def body_parsers(*parsers)
|
739
|
-
if parsers.empty?
|
740
|
-
@body_parsers ||= []
|
741
|
-
else
|
742
|
-
@body_parsers = parsers
|
743
|
-
end
|
744
|
-
end
|
745
|
-
|
746
|
-
# Application middleware.
|
747
|
-
#
|
748
|
-
# Specify middleware that your application will use. This method will return
|
749
|
-
# the application's underlying Middleware stack which you can use to add new
|
750
|
-
# middleware for your application to use. By default, the middleware stack
|
751
|
-
# will contain only `Rack::Static` and `Rack::MethodOverride`. However, if
|
752
|
-
# `assets false` was specified # in the configuration block, the default
|
753
|
-
# `Rack::Static` will be removed.
|
754
|
-
#
|
755
|
-
# @since 0.2.0
|
756
|
-
#
|
757
|
-
# @see http://rdoc.info/gems/rack/Rack/Static
|
758
|
-
# @see Hanami::Middleware#use
|
759
|
-
#
|
760
|
-
# @example
|
761
|
-
# require 'hanami'
|
762
|
-
#
|
763
|
-
# module Bookshelf
|
764
|
-
# class Application < Hanami::Application
|
765
|
-
# configure do
|
766
|
-
# middleware.use Rack::MethodOverride, nil, 'max-age=0, private, must-revalidate'
|
767
|
-
# middleware.use Rack::ETag
|
768
|
-
# end
|
769
|
-
# end
|
770
|
-
# end
|
771
|
-
def middleware
|
772
|
-
@middleware ||= Hanami::Middleware.new(self)
|
773
|
-
end
|
774
|
-
|
775
|
-
# Application collection mapping.
|
776
|
-
#
|
777
|
-
# Specify a set of collections for the application, by passing a block, or a
|
778
|
-
# relative path where to find the file that describes them.
|
779
|
-
#
|
780
|
-
# By default it's `nil`.
|
781
|
-
#
|
782
|
-
# This is part of a DSL, for this reason when this method is called with
|
783
|
-
# an argument, it will set the corresponding instance variable. When
|
784
|
-
# called without, it will return the already set value, or the default.
|
785
|
-
#
|
786
|
-
# @overload mapping(blk)
|
787
|
-
# Specify a set of mapping in the given block
|
788
|
-
# @param blk [Proc] the mapping definitions
|
789
|
-
#
|
790
|
-
# @overload mapping(path)
|
791
|
-
# Specify a relative path where to find the mapping file
|
792
|
-
# @param path [String] the relative path
|
793
|
-
#
|
794
|
-
# @overload mapping
|
795
|
-
# Gets the value
|
796
|
-
# @return [Hanami::Config::Mapping] the set of mappings
|
797
|
-
#
|
798
|
-
# @since 0.2.0
|
799
|
-
#
|
800
|
-
# @see http://rdoc.info/gems/hanami-model/Hanami/Mapper
|
801
|
-
#
|
802
|
-
# @example Getting the value
|
803
|
-
# require 'hanami'
|
804
|
-
#
|
805
|
-
# module Bookshelf
|
806
|
-
# class Application < Hanami::Application
|
807
|
-
# end
|
808
|
-
# end
|
809
|
-
#
|
810
|
-
# Bookshelf::Application.configuration.mapping
|
811
|
-
# # => nil
|
812
|
-
#
|
813
|
-
# @example Setting the value, by passing a block
|
814
|
-
# require 'hanami'
|
815
|
-
#
|
816
|
-
# module Bookshelf
|
817
|
-
# class Application < Hanami::Application
|
818
|
-
# configure do
|
819
|
-
# mapping do
|
820
|
-
# collection :users do
|
821
|
-
# entity User
|
822
|
-
#
|
823
|
-
# attribute :id, Integer
|
824
|
-
# attribute :name, String
|
825
|
-
# end
|
826
|
-
# end
|
827
|
-
# end
|
828
|
-
# end
|
829
|
-
# end
|
830
|
-
#
|
831
|
-
# Bookshelf::Application.configuration.mapping
|
832
|
-
# # => #<Hanami::Config::Mapping:0x007ff50a991388 @blk=#<Proc:0x007ff123991338@(irb):4>, @path=#<Pathname:.>>
|
833
|
-
#
|
834
|
-
# @example Setting the value, by passing a relative path
|
835
|
-
# require 'hanami'
|
836
|
-
#
|
837
|
-
# module Bookshelf
|
838
|
-
# class Application < Hanami::Application
|
839
|
-
# configure do
|
840
|
-
# mapping 'config/mapping'
|
841
|
-
# end
|
842
|
-
# end
|
843
|
-
# end
|
844
|
-
#
|
845
|
-
# Bookshelf::Application.configuration.mapping
|
846
|
-
# # => #<Hanami::Config::Routes:0x007ff50a991388 @blk=nil, @path=#<Pathname:config/mapping.rb>>
|
847
|
-
def mapping(path = nil, &blk)
|
848
|
-
if path or block_given?
|
849
|
-
@mapping = Config::Mapping.new(root, path, &blk)
|
850
|
-
else
|
851
|
-
@mapping
|
852
|
-
end
|
853
|
-
end
|
854
|
-
|
855
|
-
# Adapter configuration.
|
856
|
-
# The application will instantiate adapter instance based on this configuration.
|
857
|
-
#
|
858
|
-
# The given options must have key pairs :type and :uri
|
859
|
-
# If it isn't, at the runtime the framework will raise a
|
860
|
-
# `ArgumentError`.
|
861
|
-
#
|
862
|
-
# This is part of a DSL, for this reason when this method is called with
|
863
|
-
# an argument, it will set the corresponding instance variable. When
|
864
|
-
# called without, it will return the already set value, or the default.
|
865
|
-
#
|
866
|
-
# @overload adapter(options)
|
867
|
-
# Sets the given type and uri
|
868
|
-
# @param options [Hash] a set of options for adapter
|
869
|
-
#
|
870
|
-
# @overload adapter
|
871
|
-
# Gets the value
|
872
|
-
# @return [Hash] adapter options
|
873
|
-
#
|
874
|
-
# @since 0.2.0
|
875
|
-
#
|
876
|
-
# @see Hanami::Configuration#adapter
|
877
|
-
# @see http://rdoc.info/gems/hanami-model/Hanami/Model/Configuration:adapter
|
878
|
-
#
|
879
|
-
# @example
|
880
|
-
# require 'hanami'
|
881
|
-
#
|
882
|
-
# module Bookshelf
|
883
|
-
# class Application < Hanami::Application
|
884
|
-
# configure do
|
885
|
-
# adapter type: :sql, uri: 'sqlite3://uri'
|
886
|
-
# end
|
887
|
-
# end
|
888
|
-
# end
|
889
|
-
#
|
890
|
-
# Bookshelf::Application.configuration.adapter
|
891
|
-
# # => {type: :sql, uri: 'sqlite3://uri'}
|
892
|
-
def adapter(options = {})
|
893
|
-
if !options.empty?
|
894
|
-
@adapter = options
|
895
|
-
else
|
896
|
-
@adapter
|
897
|
-
end
|
898
|
-
end
|
899
|
-
|
900
|
-
# Set a format as default fallback for all the requests without a strict
|
901
|
-
# requirement for the mime type.
|
902
|
-
#
|
903
|
-
# The given format must be coercible to a symbol, and be a valid mime type
|
904
|
-
# alias. If it isn't, at the runtime the framework will raise a
|
905
|
-
# `Hanami::Controller::UnknownFormatError`.
|
906
|
-
#
|
907
|
-
# By default this value is `:html`.
|
908
|
-
#
|
909
|
-
# This is part of a DSL, for this reason when this method is called with
|
910
|
-
# an argument, it will set the corresponding instance variable. When
|
911
|
-
# called without, it will return the already set value, or the default.
|
912
|
-
#
|
913
|
-
# @overload default_request_format(format)
|
914
|
-
# Sets the given value
|
915
|
-
# @param format [#to_sym] the symbol format
|
916
|
-
# @raise [TypeError] if it cannot be coerced to a symbol
|
917
|
-
#
|
918
|
-
# @overload default_request_format
|
919
|
-
# Gets the value
|
920
|
-
# @return [Symbol]
|
921
|
-
#
|
922
|
-
# @since 0.5.0
|
923
|
-
#
|
924
|
-
# @see http://rdoc.info/gems/hanami-controller/Hanami/Controller/Configuration#default_request_format
|
925
|
-
#
|
926
|
-
# @example Getting the value
|
927
|
-
# require 'hanami'
|
928
|
-
#
|
929
|
-
# module Bookshelf
|
930
|
-
# class Application < Hanami::Application
|
931
|
-
# end
|
932
|
-
# end
|
933
|
-
#
|
934
|
-
# Bookshelf::Application.configuration.default_request_format # => :html
|
935
|
-
#
|
936
|
-
# @example Setting the value
|
937
|
-
# require 'hanami'
|
938
|
-
#
|
939
|
-
# module Bookshelf
|
940
|
-
# class Application < Hanami::Application
|
941
|
-
# configure do
|
942
|
-
# default_request_format :json
|
943
|
-
# end
|
944
|
-
# end
|
945
|
-
# end
|
946
|
-
#
|
947
|
-
# Bookshelf::Application.configuration.default_request_format # => :json
|
948
|
-
def default_request_format(format = nil)
|
949
|
-
if format
|
950
|
-
@default_request_format = Utils::Kernel.Symbol(format)
|
951
|
-
else
|
952
|
-
@default_request_format || :html
|
953
|
-
end
|
954
|
-
end
|
955
|
-
|
956
|
-
# Set a format to be used for all responses regardless of the request type.
|
957
|
-
#
|
958
|
-
# The given format must be coercible to a symbol, and be a valid mime type
|
959
|
-
# alias. If it isn't, at the runtime the framework will raise a
|
960
|
-
# `Hanami::Controller::UnknownFormatError`.
|
961
|
-
#
|
962
|
-
# By default this value is `:html`.
|
963
|
-
#
|
964
|
-
# This is part of a DSL, for this reason when this method is called with
|
965
|
-
# an argument, it will set the corresponding instance variable. When
|
966
|
-
# called without, it will return the already set value, or the default.
|
967
|
-
#
|
968
|
-
# @overload default_response_format(format)
|
969
|
-
# Sets the given value
|
970
|
-
# @param format [#to_sym] the symbol format
|
971
|
-
# @raise [TypeError] if it cannot be coerced to a symbol
|
972
|
-
#
|
973
|
-
# @overload default_response_format
|
974
|
-
# Gets the value
|
975
|
-
# @return [Symbol,nil]
|
976
|
-
#
|
977
|
-
# @since 0.5.0
|
978
|
-
#
|
979
|
-
# @see http://rdoc.info/gems/hanami-controller/Hanami/Controller/Configuration#default_response_format
|
980
|
-
#
|
981
|
-
# @example Getting the value
|
982
|
-
# require 'hanami'
|
983
|
-
#
|
984
|
-
# module Bookshelf
|
985
|
-
# class Application < Hanami::Application
|
986
|
-
# end
|
987
|
-
# end
|
988
|
-
#
|
989
|
-
# Bookshelf::Application.configuration.default_response_format # => :html
|
990
|
-
#
|
991
|
-
# @example Setting the value
|
992
|
-
# require 'hanami'
|
993
|
-
#
|
994
|
-
# module Bookshelf
|
995
|
-
# class Application < Hanami::Application
|
996
|
-
# configure do
|
997
|
-
# default_response_format :json
|
998
|
-
# end
|
999
|
-
# end
|
1000
|
-
# end
|
1001
|
-
#
|
1002
|
-
# Bookshelf::Application.configuration.default_response_format # => :json
|
1003
|
-
def default_response_format(format = nil)
|
1004
|
-
if format
|
1005
|
-
@default_response_format = Utils::Kernel.Symbol(format)
|
1006
|
-
else
|
1007
|
-
@default_response_format
|
1008
|
-
end
|
1009
|
-
end
|
1010
|
-
|
1011
|
-
# Set a format as default fallback for all the requests without a strict
|
1012
|
-
# requirement for the mime type.
|
1013
|
-
#
|
1014
|
-
# @since 0.1.0
|
1015
|
-
#
|
1016
|
-
# @deprecated Use {#default_request_format} instead.
|
1017
|
-
def default_format(format = nil)
|
1018
|
-
Hanami::Utils::Deprecation.new('default_format is deprecated, please use default_request_format')
|
1019
|
-
default_request_format(format)
|
1020
|
-
end
|
1021
|
-
|
1022
|
-
# The URI scheme for this application.
|
1023
|
-
# This is used by the router helpers to generate absolute URLs.
|
1024
|
-
#
|
1025
|
-
# By default this value is `"http"`.
|
1026
|
-
#
|
1027
|
-
# This is part of a DSL, for this reason when this method is called with
|
1028
|
-
# an argument, it will set the corresponding instance variable. When
|
1029
|
-
# called without, it will return the already set value, or the default.
|
1030
|
-
#
|
1031
|
-
# @overload scheme(value)
|
1032
|
-
# Sets the given value
|
1033
|
-
# @param value [String] the URI scheme
|
1034
|
-
#
|
1035
|
-
# @overload scheme
|
1036
|
-
# Gets the value
|
1037
|
-
# @return [String]
|
1038
|
-
#
|
1039
|
-
# @since 0.1.0
|
1040
|
-
#
|
1041
|
-
# @see http://en.wikipedia.org/wiki/URI_scheme
|
1042
|
-
#
|
1043
|
-
# @example Getting the value
|
1044
|
-
# require 'hanami'
|
1045
|
-
#
|
1046
|
-
# module Bookshelf
|
1047
|
-
# class Application < Hanami::Application
|
1048
|
-
# end
|
1049
|
-
# end
|
1050
|
-
#
|
1051
|
-
# Bookshelf::Application.configuration.scheme # => "http"
|
1052
|
-
#
|
1053
|
-
# @example Setting the value
|
1054
|
-
# require 'hanami'
|
1055
|
-
#
|
1056
|
-
# module Bookshelf
|
1057
|
-
# class Application < Hanami::Application
|
1058
|
-
# configure do
|
1059
|
-
# scheme 'https'
|
1060
|
-
# end
|
1061
|
-
# end
|
1062
|
-
# end
|
1063
|
-
#
|
1064
|
-
# Bookshelf::Application.configuration.scheme # => "https"
|
1065
|
-
def scheme(value = nil)
|
1066
|
-
if value
|
1067
|
-
@scheme = value
|
1068
|
-
else
|
1069
|
-
@scheme ||= 'http'
|
1070
|
-
end
|
1071
|
-
end
|
1072
|
-
|
1073
|
-
# Check if the application uses SSL
|
1074
|
-
#
|
1075
|
-
# @return [FalseClass,TrueClass] the result of the check
|
1076
|
-
#
|
1077
|
-
# @since 0.2.0
|
1078
|
-
#
|
1079
|
-
# @see Hanami::Configuration#scheme
|
1080
|
-
def ssl?
|
1081
|
-
scheme == SSL_SCHEME
|
1082
|
-
end
|
1083
|
-
|
1084
|
-
# The URI host for this application.
|
1085
|
-
# This is used by the router helpers to generate absolute URLs.
|
1086
|
-
#
|
1087
|
-
# By default this value is `"localhost"`.
|
1088
|
-
#
|
1089
|
-
# This is part of a DSL, for this reason when this method is called with
|
1090
|
-
# an argument, it will set the corresponding instance variable. When
|
1091
|
-
# called without, it will return the already set value, or the default.
|
1092
|
-
#
|
1093
|
-
# @overload host(value)
|
1094
|
-
# Sets the given value
|
1095
|
-
# @param value [String] the URI host
|
1096
|
-
#
|
1097
|
-
# @overload scheme
|
1098
|
-
# Gets the value
|
1099
|
-
# @return [String]
|
1100
|
-
#
|
1101
|
-
# @since 0.1.0
|
1102
|
-
#
|
1103
|
-
# @see http://en.wikipedia.org/wiki/URI_scheme
|
1104
|
-
#
|
1105
|
-
# @example Getting the value
|
1106
|
-
# require 'hanami'
|
1107
|
-
#
|
1108
|
-
# module Bookshelf
|
1109
|
-
# class Application < Hanami::Application
|
1110
|
-
# end
|
1111
|
-
# end
|
1112
|
-
#
|
1113
|
-
# Bookshelf::Application.configuration.host # => "localhost"
|
1114
|
-
#
|
1115
|
-
# @example Setting the value
|
1116
|
-
# require 'hanami'
|
1117
|
-
#
|
1118
|
-
# module Bookshelf
|
1119
|
-
# class Application < Hanami::Application
|
1120
|
-
# configure do
|
1121
|
-
# host 'bookshelf.org'
|
1122
|
-
# end
|
1123
|
-
# end
|
1124
|
-
# end
|
1125
|
-
#
|
1126
|
-
# Bookshelf::Application.configuration.host # => "bookshelf.org"
|
1127
|
-
def host(value = nil)
|
1128
|
-
if value
|
1129
|
-
@host = value
|
1130
|
-
else
|
1131
|
-
@host ||= @env.host
|
1132
|
-
end
|
1133
|
-
end
|
1134
|
-
|
1135
|
-
# The URI port for this application.
|
1136
|
-
# This is used by the router helpers to generate absolute URLs.
|
1137
|
-
#
|
1138
|
-
# By default this value is `2300`.
|
1139
|
-
#
|
1140
|
-
# This is part of a DSL, for this reason when this method is called with
|
1141
|
-
# an argument, it will set the corresponding instance variable. When
|
1142
|
-
# called without, it will return the already set value, or the default.
|
1143
|
-
#
|
1144
|
-
# @overload port(value)
|
1145
|
-
# Sets the given value
|
1146
|
-
# @param value [#to_int] the URI port
|
1147
|
-
# @raise [TypeError] if the given value cannot be coerced to Integer
|
1148
|
-
#
|
1149
|
-
# @overload scheme
|
1150
|
-
# Gets the value
|
1151
|
-
# @return [String]
|
1152
|
-
#
|
1153
|
-
# @since 0.1.0
|
1154
|
-
#
|
1155
|
-
# @see http://en.wikipedia.org/wiki/URI_scheme
|
1156
|
-
#
|
1157
|
-
# @example Getting the value
|
1158
|
-
# require 'hanami'
|
1159
|
-
#
|
1160
|
-
# module Bookshelf
|
1161
|
-
# class Application < Hanami::Application
|
1162
|
-
# end
|
1163
|
-
# end
|
1164
|
-
#
|
1165
|
-
# Bookshelf::Application.configuration.port # => 2300
|
1166
|
-
#
|
1167
|
-
# @example Setting the value
|
1168
|
-
# require 'hanami'
|
1169
|
-
#
|
1170
|
-
# module Bookshelf
|
1171
|
-
# class Application < Hanami::Application
|
1172
|
-
# configure do
|
1173
|
-
# port 8080
|
1174
|
-
# end
|
1175
|
-
# end
|
1176
|
-
# end
|
1177
|
-
#
|
1178
|
-
# Bookshelf::Application.configuration.port # => 8080
|
1179
|
-
def port(value = nil)
|
1180
|
-
if value
|
1181
|
-
@port = Integer(value)
|
1182
|
-
else
|
1183
|
-
@port || @env.port
|
1184
|
-
end
|
1185
|
-
end
|
1186
|
-
|
1187
|
-
# Defines a relative pattern to find controllers.
|
1188
|
-
#
|
1189
|
-
# Hanami supports multiple architectures (aka application structures), this
|
1190
|
-
# setting helps to understand the namespace where to find applications'
|
1191
|
-
# controllers and actions.
|
1192
|
-
#
|
1193
|
-
# By default this equals to <tt>"Controllers::%{controller}::%{action}"</tt>
|
1194
|
-
# That means controllers must be structured like this:
|
1195
|
-
# <tt>Bookshelf::Controllers::Dashboard::Index</tt>, where <tt>Bookshelf</tt>
|
1196
|
-
# is the application module, <tt>Controllers</tt> is the first value
|
1197
|
-
# specified in the pattern, <tt>Dashboard</tt> the controller and
|
1198
|
-
# <tt>Index</tt> the action.
|
1199
|
-
#
|
1200
|
-
# This pattern MUST always contain <tt>"%{controller}"</tt> and <tt>%{action}</tt>.
|
1201
|
-
# This pattern SHOULD be used accordingly to <tt>#view_pattern</tt> value.
|
1202
|
-
#
|
1203
|
-
# This is part of a DSL, for this reason when this method is called with
|
1204
|
-
# an argument, it will set the corresponding instance variable. When
|
1205
|
-
# called without, it will return the already set value, or the default.
|
1206
|
-
#
|
1207
|
-
# @overload controller_pattern(value)
|
1208
|
-
# Sets the given value
|
1209
|
-
# @param value [String] the controller pattern
|
1210
|
-
#
|
1211
|
-
# @overload controller_pattern
|
1212
|
-
# Gets the value
|
1213
|
-
# @return [String]
|
1214
|
-
#
|
1215
|
-
# @since 0.1.0
|
1216
|
-
#
|
1217
|
-
# @see Hanami::Configuration#view_pattern
|
1218
|
-
#
|
1219
|
-
# @example Getting the value
|
1220
|
-
# require 'hanami'
|
1221
|
-
#
|
1222
|
-
# module Bookshelf
|
1223
|
-
# class Application < Hanami::Application
|
1224
|
-
# configure do
|
1225
|
-
# routes do
|
1226
|
-
# get '/', to: 'dashboard#index'
|
1227
|
-
# end
|
1228
|
-
# end
|
1229
|
-
# end
|
1230
|
-
#
|
1231
|
-
# module Controllers::Dashboard
|
1232
|
-
# class Index
|
1233
|
-
# include Bookshelf::Action
|
1234
|
-
#
|
1235
|
-
# def call(params)
|
1236
|
-
# # ...
|
1237
|
-
# end
|
1238
|
-
# end
|
1239
|
-
# end
|
1240
|
-
# end
|
1241
|
-
#
|
1242
|
-
# Bookshelf::Application.configuration.controller_pattern
|
1243
|
-
# # => "Controllers::%{controller}::%{action}"
|
1244
|
-
#
|
1245
|
-
# # All the controllers MUST live under Bookshelf::Controllers
|
1246
|
-
#
|
1247
|
-
# # GET '/' # => Bookshelf::Controllers::Dashboard::Index
|
1248
|
-
#
|
1249
|
-
# @example Setting the value
|
1250
|
-
# require 'hanami'
|
1251
|
-
#
|
1252
|
-
# module Bookshelf
|
1253
|
-
# class Application < Hanami::Application
|
1254
|
-
# configure do
|
1255
|
-
# controller_pattern "%{controller}Controller::%{action}"
|
1256
|
-
#
|
1257
|
-
# routes do
|
1258
|
-
# get '/', to: 'dashboard#index'
|
1259
|
-
# end
|
1260
|
-
# end
|
1261
|
-
# end
|
1262
|
-
#
|
1263
|
-
# module DashboardController
|
1264
|
-
# class Index
|
1265
|
-
# include Bookshelf::Action
|
1266
|
-
#
|
1267
|
-
# def call(params)
|
1268
|
-
# end
|
1269
|
-
# end
|
1270
|
-
# end
|
1271
|
-
# end
|
1272
|
-
#
|
1273
|
-
# Bookshelf::Application.configuration.controller_pattern
|
1274
|
-
# # => "%{controller}Controller::%{action}"
|
1275
|
-
#
|
1276
|
-
# # All the controllers are directly under the Bookshelf module
|
1277
|
-
#
|
1278
|
-
# # GET '/' # => Bookshelf::DashboardController::Index
|
1279
|
-
#
|
1280
|
-
# @example Setting the value for a top level name structure
|
1281
|
-
# require 'hanami'
|
1282
|
-
#
|
1283
|
-
# module Bookshelf
|
1284
|
-
# class Application < Hanami::Application
|
1285
|
-
# configure do
|
1286
|
-
# namespace Object
|
1287
|
-
# controller_pattern "%{controller}Controller::%{action}"
|
1288
|
-
#
|
1289
|
-
# routes do
|
1290
|
-
# get '/', to: 'dashboard#index'
|
1291
|
-
# end
|
1292
|
-
# end
|
1293
|
-
# end
|
1294
|
-
# end
|
1295
|
-
#
|
1296
|
-
# module DashboardController
|
1297
|
-
# class Index
|
1298
|
-
# include Bookshelf::Action
|
1299
|
-
#
|
1300
|
-
# def call(params)
|
1301
|
-
# end
|
1302
|
-
# end
|
1303
|
-
# end
|
1304
|
-
#
|
1305
|
-
# Bookshelf::Application.configuration.controller_pattern
|
1306
|
-
# # => "%{controller}Controller::%{action}"
|
1307
|
-
#
|
1308
|
-
# # All the controllers are at the top level namespace
|
1309
|
-
#
|
1310
|
-
# # GET '/' # => DashboardController::Index
|
1311
|
-
def controller_pattern(value = nil)
|
1312
|
-
if value
|
1313
|
-
@controller_pattern = value
|
1314
|
-
else
|
1315
|
-
@controller_pattern ||= 'Controllers::%{controller}::%{action}'
|
1316
|
-
end
|
1317
|
-
end
|
1318
|
-
|
1319
|
-
# Defines a relative pattern to find views:.
|
1320
|
-
#
|
1321
|
-
# Hanami supports multiple architectures (aka application structures), this
|
1322
|
-
# setting helps to understand the namespace where to find applications'
|
1323
|
-
# views:.
|
1324
|
-
#
|
1325
|
-
# By default this equals to <tt>"Views::%{controller}::%{action}"</tt>
|
1326
|
-
# That means views must be structured like this:
|
1327
|
-
# <tt>Bookshelf::Views::Dashboard::Index</tt>, where <tt>Bookshelf</tt> is
|
1328
|
-
# the application module, <tt>Views</tt> is the first value specified in the
|
1329
|
-
# pattern, <tt>Dashboard</tt> a module corresponding to the controller name
|
1330
|
-
# and <tt>Index</tt> the view, corresponding to the action name.
|
1331
|
-
#
|
1332
|
-
# This pattern MUST always contain <tt>"%{controller}"</tt> and <tt>%{action}</tt>.
|
1333
|
-
# This pattern SHOULD be used accordingly to <tt>#controller_pattern</tt> value.
|
1334
|
-
#
|
1335
|
-
# This is part of a DSL, for this reason when this method is called with
|
1336
|
-
# an argument, it will set the corresponding instance variable. When
|
1337
|
-
# called without, it will return the already set value, or the default.
|
1338
|
-
#
|
1339
|
-
# @overload view_pattern(value)
|
1340
|
-
# Sets the given value
|
1341
|
-
# @param value [String] the view pattern
|
1342
|
-
#
|
1343
|
-
# @overload controller_pattern
|
1344
|
-
# Gets the value
|
1345
|
-
# @return [String]
|
1346
|
-
#
|
1347
|
-
# @since 0.1.0
|
1348
|
-
#
|
1349
|
-
# @see Hanami::Configuration#controller_pattern
|
1350
|
-
#
|
1351
|
-
# @example Getting the value
|
1352
|
-
# require 'hanami'
|
1353
|
-
#
|
1354
|
-
# module Bookshelf
|
1355
|
-
# class Application < Hanami::Application
|
1356
|
-
# configure do
|
1357
|
-
# routes do
|
1358
|
-
# get '/', to: 'dashboard#index'
|
1359
|
-
# end
|
1360
|
-
# end
|
1361
|
-
# end
|
1362
|
-
#
|
1363
|
-
# module Views
|
1364
|
-
# module Dashboard
|
1365
|
-
# class Index
|
1366
|
-
# include Bookshelf::View
|
1367
|
-
# end
|
1368
|
-
# end
|
1369
|
-
# end
|
1370
|
-
# end
|
1371
|
-
#
|
1372
|
-
# Bookshelf::Application.configuration.view_pattern
|
1373
|
-
# # => "Views::%{controller}::%{action}"
|
1374
|
-
#
|
1375
|
-
# # All the views MUST live under Bookshelf::Views
|
1376
|
-
#
|
1377
|
-
# # GET '/' # => Bookshelf::Views::Dashboard::Index
|
1378
|
-
#
|
1379
|
-
# @example Setting the value
|
1380
|
-
# require 'hanami'
|
1381
|
-
#
|
1382
|
-
# module Bookshelf
|
1383
|
-
# class Application < Hanami::Application
|
1384
|
-
# configure do
|
1385
|
-
# view_pattern "%{controller}::%{action}"
|
1386
|
-
#
|
1387
|
-
# routes do
|
1388
|
-
# get '/', to: 'dashboard#index'
|
1389
|
-
# end
|
1390
|
-
# end
|
1391
|
-
# end
|
1392
|
-
#
|
1393
|
-
# module Dashboard
|
1394
|
-
# class Index
|
1395
|
-
# include Bookshelf::View
|
1396
|
-
# end
|
1397
|
-
# end
|
1398
|
-
# end
|
1399
|
-
#
|
1400
|
-
# Bookshelf::Application.configuration.view_pattern
|
1401
|
-
# # => "%{controller}::%{action}"
|
1402
|
-
#
|
1403
|
-
# # All the views are directly under the Bookshelf module
|
1404
|
-
#
|
1405
|
-
# # GET '/' # => Bookshelf::Dashboard::Index
|
1406
|
-
#
|
1407
|
-
# @example Setting the value for a top level name structure
|
1408
|
-
# require 'hanami'
|
1409
|
-
#
|
1410
|
-
# module Bookshelf
|
1411
|
-
# class Application < Hanami::Application
|
1412
|
-
# configure do
|
1413
|
-
# namespace Object
|
1414
|
-
# view_pattern "%{controller}::%{action}"
|
1415
|
-
#
|
1416
|
-
# routes do
|
1417
|
-
# get '/', to: 'dashboard#index'
|
1418
|
-
# end
|
1419
|
-
# end
|
1420
|
-
# end
|
1421
|
-
# end
|
1422
|
-
#
|
1423
|
-
# module Dashboard
|
1424
|
-
# class Index
|
1425
|
-
# include Bookshelf::View
|
1426
|
-
# end
|
1427
|
-
# end
|
1428
|
-
#
|
1429
|
-
# Bookshelf::Application.configuration.view_pattern
|
1430
|
-
# # => "%{controller}::%{action}"
|
1431
|
-
#
|
1432
|
-
# # All the views: are at the top level namespace
|
1433
|
-
#
|
1434
|
-
# # GET '/' # => Dashboard::Index
|
1435
|
-
def view_pattern(value = nil)
|
1436
|
-
if value
|
1437
|
-
@view_pattern = value
|
1438
|
-
else
|
1439
|
-
@view_pattern ||= 'Views::%{controller}::%{action}'
|
1440
|
-
end
|
1441
|
-
end
|
1442
|
-
|
1443
|
-
# Decide if handle exceptions with an HTTP status or let them uncaught
|
1444
|
-
#
|
1445
|
-
# If this value is set to `true`, the configured exceptions will return
|
1446
|
-
# the specified HTTP status, the rest of them with `500`.
|
1447
|
-
#
|
1448
|
-
# If this value is set to `false`, the exceptions won't be caught.
|
1449
|
-
#
|
1450
|
-
# This is part of a DSL, for this reason when this method is called with
|
1451
|
-
# an argument, it will set the corresponding instance variable. When
|
1452
|
-
# called without, it will return the already set value, or the default.
|
1453
|
-
#
|
1454
|
-
# @overload handle_exceptions(value)
|
1455
|
-
# Sets the given value
|
1456
|
-
# @param value [TrueClass, FalseClass] true or false, default to true
|
1457
|
-
#
|
1458
|
-
# @overload handle_exceptions
|
1459
|
-
# Gets the value
|
1460
|
-
# @return [TrueClass, FalseClass]
|
1461
|
-
#
|
1462
|
-
# @since 0.2.0
|
1463
|
-
#
|
1464
|
-
# @see http://rdoc.info/gems/hanami-controller/Hanami/Controller/Configuration:handle_exceptions
|
1465
|
-
# @see http://httpstatus.es/500
|
1466
|
-
#
|
1467
|
-
# @example Enabled (default)
|
1468
|
-
# require 'hanami'
|
1469
|
-
#
|
1470
|
-
# module Bookshelf
|
1471
|
-
# class Application < Hanami::Application
|
1472
|
-
# configure do
|
1473
|
-
# routes do
|
1474
|
-
# get '/error', to: 'error#index'
|
1475
|
-
# end
|
1476
|
-
# end
|
1477
|
-
#
|
1478
|
-
# load!
|
1479
|
-
# end
|
1480
|
-
#
|
1481
|
-
# module Controllers::Error
|
1482
|
-
# class Index
|
1483
|
-
# include Bookshelf::Action
|
1484
|
-
#
|
1485
|
-
# def call(params)
|
1486
|
-
# raise ArgumentError
|
1487
|
-
# end
|
1488
|
-
# end
|
1489
|
-
# end
|
1490
|
-
# end
|
1491
|
-
#
|
1492
|
-
# # GET '/error' # => 500 - Internal Server Error
|
1493
|
-
#
|
1494
|
-
# @example Disabled
|
1495
|
-
# require 'hanami'
|
1496
|
-
#
|
1497
|
-
# module Bookshelf
|
1498
|
-
# class Application < Hanami::Application
|
1499
|
-
# configure do
|
1500
|
-
# handle_exceptions false
|
1501
|
-
#
|
1502
|
-
# routes do
|
1503
|
-
# get '/error', to: 'error#index'
|
1504
|
-
# end
|
1505
|
-
# end
|
1506
|
-
#
|
1507
|
-
# load!
|
1508
|
-
# end
|
1509
|
-
#
|
1510
|
-
# module Controllers::Error
|
1511
|
-
# class Index
|
1512
|
-
# include Bookshelf::Action
|
1513
|
-
#
|
1514
|
-
# def call(params)
|
1515
|
-
# raise ArgumentError
|
1516
|
-
# end
|
1517
|
-
# end
|
1518
|
-
# end
|
1519
|
-
# end
|
1520
|
-
#
|
1521
|
-
# # GET '/error' # => raises ArgumentError
|
1522
|
-
def handle_exceptions(value = nil)
|
1523
|
-
if value.nil?
|
1524
|
-
@handle_exceptions
|
1525
|
-
else
|
1526
|
-
@handle_exceptions = value
|
1527
|
-
end
|
1528
|
-
end
|
1529
|
-
|
1530
|
-
# It lazily collects all the low level settings for Hanami::Model's
|
1531
|
-
# configuration and applies them when the application is loaded.
|
1532
|
-
#
|
1533
|
-
# NOTE: This forwards all the configurations to Hanami::Model, without
|
1534
|
-
# checking them. Before to use this feature, please have a look at the
|
1535
|
-
# current Hanami::Model version installed.
|
1536
|
-
#
|
1537
|
-
# NOTE: This may override some configurations of your application.
|
1538
|
-
#
|
1539
|
-
# @return [Hanami::Config::FrameworkConfiguration] the configuration
|
1540
|
-
#
|
1541
|
-
# @since 0.2.0
|
1542
|
-
#
|
1543
|
-
# @see http://www.rubydoc.info/gems/hanami-model/Hanami/Model/Configuration
|
1544
|
-
#
|
1545
|
-
# @example Define a setting
|
1546
|
-
# require 'hanami'
|
1547
|
-
# require 'hanami/model'
|
1548
|
-
#
|
1549
|
-
# module Bookshelf
|
1550
|
-
# class Application < Hanami::Application
|
1551
|
-
# configure do
|
1552
|
-
# model.adapter type: :memory, uri: 'memory://localhost/database'
|
1553
|
-
# end
|
1554
|
-
# end
|
1555
|
-
# end
|
1556
|
-
#
|
1557
|
-
# @example Override a setting
|
1558
|
-
# require 'hanami'
|
1559
|
-
# require 'hanami/model'
|
1560
|
-
#
|
1561
|
-
# module Bookshelf
|
1562
|
-
# class Application < Hanami::Application
|
1563
|
-
# configure do
|
1564
|
-
# adapter type: :sql, uri: 'postgres://localhost/database'
|
1565
|
-
# model.adapter type: :memory, uri: 'memory://localhost/database'
|
1566
|
-
# end
|
1567
|
-
# end
|
1568
|
-
# end
|
1569
|
-
#
|
1570
|
-
# # The memory adapter will override the SQL one
|
1571
|
-
def model
|
1572
|
-
@model ||= Config::FrameworkConfiguration.new
|
1573
|
-
end
|
1574
|
-
|
1575
|
-
# It lazily collects all the low level settings for Hanami::Controller's
|
1576
|
-
# configuration and applies them when the application is loaded.
|
1577
|
-
#
|
1578
|
-
# NOTE: This forwards all the configurations to Hanami::Controller, without
|
1579
|
-
# checking them. Before to use this feature, please have a look at the
|
1580
|
-
# current Hanami::Controller version installed.
|
1581
|
-
#
|
1582
|
-
# NOTE: This may override some configurations of your application.
|
1583
|
-
#
|
1584
|
-
# @return [Hanami::Config::FrameworkConfiguration] the configuration
|
1585
|
-
#
|
1586
|
-
# @since 0.2.0
|
1587
|
-
#
|
1588
|
-
# @see http://www.rubydoc.info/gems/hanami-controller/Hanami/Controller/Configuration
|
1589
|
-
#
|
1590
|
-
# @example Define a setting
|
1591
|
-
# require 'hanami'
|
1592
|
-
#
|
1593
|
-
# module Bookshelf
|
1594
|
-
# class Application < Hanami::Application
|
1595
|
-
# configure do
|
1596
|
-
# controller.default_request_format :json
|
1597
|
-
# end
|
1598
|
-
# end
|
1599
|
-
# end
|
1600
|
-
#
|
1601
|
-
# @example Override a setting
|
1602
|
-
# require 'hanami'
|
1603
|
-
#
|
1604
|
-
# module Bookshelf
|
1605
|
-
# class Application < Hanami::Application
|
1606
|
-
# configure do
|
1607
|
-
# handle_exceptions false
|
1608
|
-
# controller.handle_exceptions true
|
1609
|
-
# end
|
1610
|
-
# end
|
1611
|
-
# end
|
1612
|
-
#
|
1613
|
-
# # Exceptions will be handled
|
1614
|
-
def controller
|
1615
|
-
@controller ||= Config::FrameworkConfiguration.new
|
1616
|
-
end
|
1617
|
-
|
1618
|
-
# It lazily collects all the low level settings for Hanami::View's
|
1619
|
-
# configuration and applies them when the application is loaded.
|
1620
|
-
#
|
1621
|
-
# NOTE: This forwards all the configurations to Hanami::View, without
|
1622
|
-
# checking them. Before to use this feature, please have a look at the
|
1623
|
-
# current Hanami::View version installed.
|
1624
|
-
#
|
1625
|
-
# NOTE: This may override some configurations of your application.
|
1626
|
-
#
|
1627
|
-
# @return [Hanami::Config::FrameworkConfiguration] the configuration
|
1628
|
-
#
|
1629
|
-
# @since 0.2.0
|
1630
|
-
#
|
1631
|
-
# @see http://www.rubydoc.info/gems/hanami-view/Hanami/View/Configuration
|
1632
|
-
#
|
1633
|
-
# @example Define a setting
|
1634
|
-
# require 'hanami'
|
1635
|
-
#
|
1636
|
-
# module Bookshelf
|
1637
|
-
# class Application < Hanami::Application
|
1638
|
-
# configure do
|
1639
|
-
# view.layout :application
|
1640
|
-
# end
|
1641
|
-
# end
|
1642
|
-
# end
|
1643
|
-
#
|
1644
|
-
# @example Override a setting
|
1645
|
-
# require 'hanami'
|
1646
|
-
#
|
1647
|
-
# module Bookshelf
|
1648
|
-
# class Application < Hanami::Application
|
1649
|
-
# configure do
|
1650
|
-
# layout :application
|
1651
|
-
# view.layout :backend
|
1652
|
-
# end
|
1653
|
-
# end
|
1654
|
-
# end
|
1655
|
-
#
|
1656
|
-
# # It will use `:backend` layout
|
1657
|
-
def view
|
1658
|
-
@view ||= Config::FrameworkConfiguration.new
|
1659
|
-
end
|
1660
|
-
|
1661
|
-
# Defines a Config::Logger instance to the logger configuration.
|
1662
|
-
#
|
1663
|
-
# This instance will be used to generate the hanami logger available on application module.
|
1664
|
-
#
|
1665
|
-
# @return [Config::Logger] Configure logger instance
|
1666
|
-
#
|
1667
|
-
# @since 0.5.0
|
1668
|
-
#
|
1669
|
-
# @example Define a logger
|
1670
|
-
# require 'hanami'
|
1671
|
-
#
|
1672
|
-
# module Bookshelf
|
1673
|
-
# class Application < Hanami::Application
|
1674
|
-
# configure do
|
1675
|
-
# logger.stream 'path/to/log/file'
|
1676
|
-
# end
|
1677
|
-
# load!
|
1678
|
-
# end
|
1679
|
-
#
|
1680
|
-
# module Controllers::Error
|
1681
|
-
# class Index
|
1682
|
-
# include Bookshelf::Action
|
1683
|
-
#
|
1684
|
-
# def call(params)
|
1685
|
-
# Bookshelf::Logger.info "Logging to STDOUT"
|
1686
|
-
# end
|
1687
|
-
# end
|
1688
|
-
# end
|
1689
|
-
# end
|
1690
|
-
#
|
1691
|
-
def logger
|
1692
|
-
@logger ||= Config::Logger.new
|
1693
|
-
end
|
1694
|
-
|
1695
|
-
# This options is used as a bridge between container and router application.
|
1696
|
-
#
|
1697
|
-
# @return [String, NilClass] path prefix for routes
|
1698
|
-
#
|
1699
|
-
# @since 0.4.0
|
1700
|
-
# @api private
|
1701
|
-
def path_prefix(value = nil)
|
1702
|
-
if value.nil?
|
1703
|
-
@path_prefix
|
1704
|
-
else
|
1705
|
-
@path_prefix = value
|
43
|
+
def apps
|
44
|
+
mounted.each_pair do |klass, app|
|
45
|
+
yield(app) if klass.ancestors.include?(Hanami::Application)
|
1706
46
|
end
|
1707
47
|
end
|
1708
48
|
|
1709
49
|
private
|
1710
50
|
|
1711
|
-
|
1712
|
-
# @api private
|
1713
|
-
def evaluate_configurations!
|
1714
|
-
configurations.each { |c| instance_eval(&c) }
|
1715
|
-
end
|
1716
|
-
|
1717
|
-
# @since 0.2.0
|
1718
|
-
# @api private
|
1719
|
-
def configurations
|
1720
|
-
[ @blk ] + @configurations[@env.environment]
|
1721
|
-
end
|
51
|
+
attr_reader :settings
|
1722
52
|
end
|
1723
53
|
end
|