hanami 0.8.0 → 0.9.0

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