lotusrb 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +53 -0
- data/README.md +241 -311
- data/bin/lotus +4 -0
- data/lib/lotus/application.rb +111 -15
- data/lib/lotus/cli.rb +85 -0
- data/lib/lotus/commands/console.rb +62 -0
- data/lib/lotus/commands/new.rb +32 -0
- data/lib/lotus/commands/routes.rb +14 -0
- data/lib/lotus/commands/server.rb +65 -0
- data/lib/lotus/config/assets.rb +24 -10
- data/lib/lotus/config/configure.rb +17 -0
- data/lib/lotus/config/framework_configuration.rb +30 -0
- data/lib/lotus/config/load_paths.rb +1 -1
- data/lib/lotus/config/sessions.rb +97 -0
- data/lib/lotus/configuration.rb +698 -40
- data/lib/lotus/container.rb +30 -0
- data/lib/lotus/environment.rb +377 -0
- data/lib/lotus/frameworks.rb +17 -28
- data/lib/lotus/generators/abstract.rb +31 -0
- data/lib/lotus/generators/application/container/.gitkeep +1 -0
- data/lib/lotus/generators/application/container/Gemfile.tt +29 -0
- data/lib/lotus/generators/application/container/Rakefile.minitest.tt +10 -0
- data/lib/lotus/generators/application/container/config/.env.development.tt +2 -0
- data/lib/lotus/generators/application/container/config/.env.test.tt +2 -0
- data/lib/lotus/generators/application/container/config/.env.tt +1 -0
- data/lib/lotus/generators/application/container/config/environment.rb.tt +7 -0
- data/lib/lotus/generators/application/container/config.ru.tt +3 -0
- data/lib/lotus/generators/application/container/db/.gitkeep +1 -0
- data/lib/lotus/generators/application/container/features_helper.rb.tt +11 -0
- data/lib/lotus/generators/application/container/lib/app_name.rb.tt +31 -0
- data/lib/lotus/generators/application/container/lib/chirp/entities/.gitkeep +1 -0
- data/lib/lotus/generators/application/container/lib/chirp/repositories/.gitkeep +1 -0
- data/lib/lotus/generators/application/container/spec_helper.rb.tt +7 -0
- data/lib/lotus/generators/application/container.rb +70 -0
- data/lib/lotus/generators/slice/.gitkeep.tt +1 -0
- data/lib/lotus/generators/slice/action.rb.tt +8 -0
- data/lib/lotus/generators/slice/application.rb.tt +182 -0
- data/lib/lotus/generators/slice/config/mapping.rb.tt +10 -0
- data/lib/lotus/generators/slice/config/routes.rb.tt +8 -0
- data/lib/lotus/generators/slice/templates/application.html.erb +9 -0
- data/lib/lotus/generators/slice/templates/application.html.erb.tt +9 -0
- data/lib/lotus/generators/slice/templates/template.html.erb.tt +2 -0
- data/lib/lotus/generators/slice/view.rb.tt +5 -0
- data/lib/lotus/generators/slice/views/application_layout.rb.tt +7 -0
- data/lib/lotus/generators/slice.rb +103 -0
- data/lib/lotus/loader.rb +99 -19
- data/lib/lotus/middleware.rb +92 -9
- data/lib/lotus/rendering_policy.rb +42 -19
- data/lib/lotus/routing/default.rb +1 -1
- data/lib/lotus/setup.rb +5 -0
- data/lib/lotus/templates/welcome.html +49 -0
- data/lib/lotus/version.rb +1 -1
- data/lib/lotus/views/default.rb +13 -0
- data/lib/lotus/views/default_template_finder.rb +19 -0
- data/lib/lotus/welcome.rb +14 -0
- data/lib/lotus.rb +1 -0
- data/lotusrb.gemspec +9 -5
- metadata +122 -36
data/lib/lotus/configuration.rb
CHANGED
@@ -1,14 +1,24 @@
|
|
1
1
|
require 'lotus/utils/kernel'
|
2
|
+
require 'lotus/environment'
|
3
|
+
require 'lotus/config/framework_configuration'
|
2
4
|
require 'lotus/config/load_paths'
|
3
5
|
require 'lotus/config/assets'
|
4
6
|
require 'lotus/config/routes'
|
5
7
|
require 'lotus/config/mapping'
|
8
|
+
require 'lotus/config/sessions'
|
9
|
+
require 'lotus/config/configure'
|
6
10
|
|
7
11
|
module Lotus
|
8
12
|
# Configuration for a Lotus application
|
9
13
|
#
|
10
14
|
# @since 0.1.0
|
11
15
|
class Configuration
|
16
|
+
# @since 0.2.0
|
17
|
+
# @api private
|
18
|
+
#
|
19
|
+
# @see Lotus::Configuration#ssl?
|
20
|
+
SSL_SCHEME = 'https'.freeze
|
21
|
+
|
12
22
|
# Initialize a new configuration instance
|
13
23
|
#
|
14
24
|
# @return [Lotus::Configuration]
|
@@ -17,18 +27,30 @@ module Lotus
|
|
17
27
|
# @api private
|
18
28
|
def initialize
|
19
29
|
@blk = Proc.new{}
|
30
|
+
@env = Environment.new
|
31
|
+
@configurations = Hash.new { |k, v| k[v] = [] }
|
20
32
|
end
|
21
33
|
|
22
|
-
# Set a block yield when the configuration will be loaded
|
34
|
+
# Set a block yield when the configuration will be loaded or
|
35
|
+
# set a path for the specific environment.
|
23
36
|
#
|
37
|
+
# @param environment [Symbol,nil] the configuration environment name
|
38
|
+
# @param environment [String,nil] the configuration path of a specific environment
|
24
39
|
# @param blk [Proc] the configuration block
|
25
40
|
#
|
26
41
|
# @return [self]
|
27
42
|
#
|
28
43
|
# @since 0.1.0
|
29
44
|
# @api private
|
30
|
-
def configure(&blk)
|
31
|
-
|
45
|
+
def configure(environment = nil, path = nil, &blk)
|
46
|
+
if environment && path
|
47
|
+
@configurations[environment.to_s] << Config::Configure.new(root, path, &blk)
|
48
|
+
elsif environment
|
49
|
+
@configurations[environment.to_s] << blk
|
50
|
+
else
|
51
|
+
@blk = blk
|
52
|
+
end
|
53
|
+
|
32
54
|
self
|
33
55
|
end
|
34
56
|
|
@@ -42,7 +64,8 @@ module Lotus
|
|
42
64
|
# @api private
|
43
65
|
def load!(namespace = nil)
|
44
66
|
@namespace = namespace
|
45
|
-
|
67
|
+
evaluate_configurations!
|
68
|
+
|
46
69
|
self
|
47
70
|
end
|
48
71
|
|
@@ -298,21 +321,12 @@ module Lotus
|
|
298
321
|
end
|
299
322
|
end
|
300
323
|
|
301
|
-
#
|
302
|
-
# The application will serve the static assets under this directory.
|
324
|
+
# The application will serve the static assets under these directories.
|
303
325
|
#
|
304
326
|
# By default it's equal to the `public/` directory under the application
|
305
327
|
# `root`.
|
306
328
|
#
|
307
|
-
# Otherwise, you can
|
308
|
-
#
|
309
|
-
# This is part of a DSL, for this reason when this method is called with
|
310
|
-
# an argument, it will set the corresponding instance variable. When
|
311
|
-
# called without, it will return the already set value, or the default.
|
312
|
-
#
|
313
|
-
# @overload assets(value)
|
314
|
-
# Sets the given value
|
315
|
-
# @param value [String] the relative path to the assets dir.
|
329
|
+
# Otherwise, you can add differents relatives paths under `root`.
|
316
330
|
#
|
317
331
|
# @overload assets
|
318
332
|
# Gets the value
|
@@ -320,7 +334,7 @@ module Lotus
|
|
320
334
|
#
|
321
335
|
# @since 0.1.0
|
322
336
|
#
|
323
|
-
# @see Lotus::Configuration#
|
337
|
+
# @see Lotus::Configuration#serve_assets
|
324
338
|
#
|
325
339
|
# @example Getting the value
|
326
340
|
# require 'lotus'
|
@@ -333,24 +347,220 @@ module Lotus
|
|
333
347
|
# Bookshelf::Application.configuration.assets
|
334
348
|
# # => #<Pathname:/root/path/public>
|
335
349
|
#
|
336
|
-
# @example
|
350
|
+
# @example Adding new assets paths
|
337
351
|
# require 'lotus'
|
338
352
|
#
|
339
353
|
# module Bookshelf
|
340
354
|
# class Application < Lotus::Application
|
341
355
|
# configure do
|
342
|
-
#
|
356
|
+
# serve_assets true
|
357
|
+
# assets << [
|
358
|
+
# 'vendor/assets'
|
359
|
+
# ]
|
343
360
|
# end
|
344
361
|
# end
|
345
362
|
# end
|
346
363
|
#
|
347
364
|
# Bookshelf::Application.configuration.assets
|
348
|
-
# # => #<Pathname:/root/path/assets>
|
349
|
-
|
350
|
-
|
351
|
-
|
365
|
+
# # => #<Lotus::Config::Assets @root=#<Pathname:/root/path/assets>, @paths=["public"]>
|
366
|
+
#
|
367
|
+
def assets
|
368
|
+
@assets ||= Config::Assets.new(root)
|
369
|
+
end
|
370
|
+
|
371
|
+
# Configure serving of assets
|
372
|
+
# Enable static assets (disabled by default).
|
373
|
+
#
|
374
|
+
# This is part of a DSL, for this reason when this method is called with
|
375
|
+
# an argument, it will set the corresponding instance variable. When
|
376
|
+
# called without, it will return the already set value, or the default.
|
377
|
+
#
|
378
|
+
# @since 0.2.0
|
379
|
+
#
|
380
|
+
# @overload serve_assets(value)
|
381
|
+
# Sets the given value.
|
382
|
+
# @param value [TrueClass, FalseClass]
|
383
|
+
#
|
384
|
+
# @overload serve_assets
|
385
|
+
# Gets the value.
|
386
|
+
# @return [TrueClass, FalseClass]
|
387
|
+
#
|
388
|
+
# @see Lotus::Configuration#assets
|
389
|
+
#
|
390
|
+
# @example Getting serve assets configuration by default
|
391
|
+
# require 'lotus'
|
392
|
+
#
|
393
|
+
# module Bookshelf
|
394
|
+
# class Application < Lotus::Application
|
395
|
+
# end
|
396
|
+
# end
|
397
|
+
#
|
398
|
+
# Bookshelf::Application.configuration.serve_assets
|
399
|
+
# # => false
|
400
|
+
#
|
401
|
+
# @example Enabling static assets
|
402
|
+
# require 'lotus'
|
403
|
+
#
|
404
|
+
# module Bookshelf
|
405
|
+
# class Application < Lotus::Application
|
406
|
+
# configure do
|
407
|
+
# serve_assets true
|
408
|
+
# end
|
409
|
+
# end
|
410
|
+
# end
|
411
|
+
#
|
412
|
+
# Bookshelf::Application.configuration.serve_assets
|
413
|
+
# # => true
|
414
|
+
def serve_assets(value = nil)
|
415
|
+
if value.nil?
|
416
|
+
@serve_assets || false
|
417
|
+
else
|
418
|
+
@serve_assets = value
|
419
|
+
end
|
420
|
+
end
|
421
|
+
|
422
|
+
# Configure cookies
|
423
|
+
# Enable cookies (disabled by default).
|
424
|
+
#
|
425
|
+
# This is part of a DSL, for this reason when this method is called with
|
426
|
+
# an argument, it will set the corresponding instance variable. When
|
427
|
+
# called without, it will return the already set value, or the default.
|
428
|
+
#
|
429
|
+
# @overload cookies(value)
|
430
|
+
# Sets the given value.
|
431
|
+
# @param value [TrueClass, FalseClass]
|
432
|
+
#
|
433
|
+
# @overload cookies
|
434
|
+
# Gets the value.
|
435
|
+
# @return [TrueClass, FalseClass]
|
436
|
+
#
|
437
|
+
# @example Getting the value
|
438
|
+
# require 'lotus'
|
439
|
+
#
|
440
|
+
# module Bookshelf
|
441
|
+
# class Application < Lotus::Application
|
442
|
+
# end
|
443
|
+
# end
|
444
|
+
#
|
445
|
+
# Bookshelf::Application.configuration.cookies
|
446
|
+
# # => false
|
447
|
+
#
|
448
|
+
# @example Setting the value
|
449
|
+
# require 'lotus'
|
450
|
+
#
|
451
|
+
# module Bookshelf
|
452
|
+
# class Application < Lotus::Application
|
453
|
+
# configure do
|
454
|
+
# cookies true
|
455
|
+
# end
|
456
|
+
# end
|
457
|
+
# end
|
458
|
+
#
|
459
|
+
# Bookshelf::Application.configuration.cookies
|
460
|
+
# # => true
|
461
|
+
#
|
462
|
+
# @example Setting a new value after one is set.
|
463
|
+
# require 'lotus'
|
464
|
+
#
|
465
|
+
# module Bookshelf
|
466
|
+
# class Application < Lotus::Application
|
467
|
+
# configure do
|
468
|
+
# cookies false
|
469
|
+
# cookies true
|
470
|
+
# end
|
471
|
+
# end
|
472
|
+
# end
|
473
|
+
#
|
474
|
+
# Bookshelf::Application.configuration.cookies
|
475
|
+
# # => true
|
476
|
+
#
|
477
|
+
def cookies(value = nil)
|
478
|
+
if value.nil?
|
479
|
+
@cookies || false
|
480
|
+
else
|
481
|
+
@cookies = value
|
482
|
+
end
|
483
|
+
end
|
484
|
+
|
485
|
+
# Configure sessions
|
486
|
+
# Enable sessions (disabled by default).
|
487
|
+
#
|
488
|
+
# This is part of a DSL, for this reason when this method is called with
|
489
|
+
# an argument, it will set the corresponding instance variable. When
|
490
|
+
# called without, it will return the already set value, or the default.
|
491
|
+
#
|
492
|
+
# Given Class as adapter it will be used as sessions middleware.
|
493
|
+
# Given String as adapter it will be resolved as class name and used as
|
494
|
+
# sessions middleware.
|
495
|
+
# Given Symbol as adapter it is assumed it's name of the class under
|
496
|
+
# Rack::Session namespace that will be used as sessions middleware
|
497
|
+
# (e.g. :cookie for Rack::Session::Cookie).
|
498
|
+
#
|
499
|
+
# By default options include domain inferred from host configuration, and
|
500
|
+
# secure flag inferred from scheme configuration.
|
501
|
+
#
|
502
|
+
# @overload sessions(adapter, options)
|
503
|
+
# Sets the given value.
|
504
|
+
# @param adapter [Class, String, Symbol] Rack middleware for sessions management
|
505
|
+
# @param options [Hash] options to pass to sessions middleware
|
506
|
+
#
|
507
|
+
# @overload sessions(false)
|
508
|
+
# Disables sessions
|
509
|
+
#
|
510
|
+
# @overload sessions
|
511
|
+
# Gets the value.
|
512
|
+
# @return [Lotus::Config::Sessions] sessions configuration
|
513
|
+
#
|
514
|
+
# @since 0.2.0
|
515
|
+
#
|
516
|
+
# @see Lotus::Configuration#host
|
517
|
+
# @see Lotus::Configuration#scheme
|
518
|
+
#
|
519
|
+
# @example Getting the value
|
520
|
+
# require 'lotus'
|
521
|
+
#
|
522
|
+
# module Bookshelf
|
523
|
+
# class Application < Lotus::Application
|
524
|
+
# end
|
525
|
+
# end
|
526
|
+
#
|
527
|
+
# Bookshelf::Application.configuration.sessions
|
528
|
+
# # => #<Lotus::Config::Sessions:0x00000001ca0c28 @enabled=false>
|
529
|
+
#
|
530
|
+
# @example Setting the value with symbol
|
531
|
+
# require 'lotus'
|
532
|
+
#
|
533
|
+
# module Bookshelf
|
534
|
+
# class Application < Lotus::Application
|
535
|
+
# configure do
|
536
|
+
# sessions :cookie, secret: 'abc123'
|
537
|
+
# end
|
538
|
+
# end
|
539
|
+
# end
|
540
|
+
#
|
541
|
+
# Bookshelf::Application.configuration.sessions
|
542
|
+
# # => #<Lotus::Config::Sessions:0x00000001589458 @enabled=true, @adapter=:cookie, @options={:domain=>"localhost", :secure=>false}>
|
543
|
+
#
|
544
|
+
# @example Disabling previusly enabled sessions
|
545
|
+
# require 'lotus'
|
546
|
+
#
|
547
|
+
# module Bookshelf
|
548
|
+
# class Application < Lotus::Application
|
549
|
+
# configure do
|
550
|
+
# sessions :cookie
|
551
|
+
# sessions false
|
552
|
+
# end
|
553
|
+
# end
|
554
|
+
# end
|
555
|
+
#
|
556
|
+
# Bookshelf::Application.configuration.sessions
|
557
|
+
# # => #<Lotus::Config::Sessions:0x00000002460d78 @enabled=false>
|
558
|
+
#
|
559
|
+
def sessions(adapter = nil, options = {})
|
560
|
+
if adapter.nil?
|
561
|
+
@sessions ||= Config::Sessions.new
|
352
562
|
else
|
353
|
-
Config::
|
563
|
+
@sessions = Config::Sessions.new(adapter, options, self)
|
354
564
|
end
|
355
565
|
end
|
356
566
|
|
@@ -473,8 +683,177 @@ module Lotus
|
|
473
683
|
end
|
474
684
|
end
|
475
685
|
|
476
|
-
#
|
477
|
-
#
|
686
|
+
# Body parsing configuration.
|
687
|
+
#
|
688
|
+
# Specify a set of parsers for specific mime types that your application will use. This method will
|
689
|
+
# return the application's parsers which you can use to add existing and new custom parsers for your
|
690
|
+
# application to use.
|
691
|
+
#
|
692
|
+
# By default it's an empty `Array`
|
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 body_parsers(parsers)
|
699
|
+
# Specify a set of body parsers.
|
700
|
+
# @param parsers [Array] the body parser definitions
|
701
|
+
#
|
702
|
+
# @overload body_parsers
|
703
|
+
# Gets the value
|
704
|
+
# @return [Array] the set of parsers
|
705
|
+
#
|
706
|
+
# @since 0.2.0
|
707
|
+
#
|
708
|
+
# @example Getting the value
|
709
|
+
# require 'lotus'
|
710
|
+
#
|
711
|
+
# module Bookshelf
|
712
|
+
# class Application < Lotus::Application
|
713
|
+
# end
|
714
|
+
# end
|
715
|
+
#
|
716
|
+
# Bookshelf::Application.configuration.body_parsers
|
717
|
+
# # => []
|
718
|
+
#
|
719
|
+
# @example Setting the value
|
720
|
+
# require 'lotus'
|
721
|
+
#
|
722
|
+
# module Bookshelf
|
723
|
+
# class Application < Lotus::Application
|
724
|
+
# configure do
|
725
|
+
# body_parsers :json, XmlParser.new
|
726
|
+
# end
|
727
|
+
# end
|
728
|
+
# end
|
729
|
+
#
|
730
|
+
# Bookshelf::Application.configuration.body_parsers
|
731
|
+
# # => [:json, XmlParser.new]
|
732
|
+
#
|
733
|
+
# @example Setting a new value after one is set.
|
734
|
+
# require 'lotus'
|
735
|
+
#
|
736
|
+
# module Bookshelf
|
737
|
+
# class Application < Lotus::Application
|
738
|
+
# configure do
|
739
|
+
# body_parsers :json
|
740
|
+
# body_parsers XmlParser.new
|
741
|
+
# end
|
742
|
+
# end
|
743
|
+
# end
|
744
|
+
#
|
745
|
+
# Bookshelf::Application.configuration.body_parsers
|
746
|
+
# # => [XmlParser.new]
|
747
|
+
#
|
748
|
+
def body_parsers(*parsers)
|
749
|
+
if parsers.empty?
|
750
|
+
@body_parsers ||= []
|
751
|
+
else
|
752
|
+
@body_parsers = parsers
|
753
|
+
end
|
754
|
+
end
|
755
|
+
|
756
|
+
# Application middleware.
|
757
|
+
#
|
758
|
+
# Specify middleware that your application will use. This method will return
|
759
|
+
# the application's underlying Middleware stack which you can use to add new
|
760
|
+
# middleware for your application to use. By default, the middleware stack
|
761
|
+
# will contain only `Rack::Static` and `Rack::MethodOverride`. However, if
|
762
|
+
# `assets false` was specified # in the configuration block, the default
|
763
|
+
# `Rack::Static` will be removed.
|
764
|
+
#
|
765
|
+
# @since 0.2.0
|
766
|
+
#
|
767
|
+
# @see http://rdoc.info/gems/rack/Rack/Static
|
768
|
+
# @see Lotus::Middleware#use
|
769
|
+
#
|
770
|
+
# @example
|
771
|
+
# require 'lotus'
|
772
|
+
#
|
773
|
+
# module Bookshelf
|
774
|
+
# class Application < Lotus::Application
|
775
|
+
# configure do
|
776
|
+
# middleware.use Rack::MethodOverride, nil, 'max-age=0, private, must-revalidate'
|
777
|
+
# middleware.use Rack::ETag
|
778
|
+
# end
|
779
|
+
# end
|
780
|
+
# end
|
781
|
+
def middleware
|
782
|
+
@middleware ||= Lotus::Middleware.new(self)
|
783
|
+
end
|
784
|
+
|
785
|
+
# Application collection mapping.
|
786
|
+
#
|
787
|
+
# Specify a set of collections for the application, by passing a block, or a
|
788
|
+
# relative path where to find the file that describes them.
|
789
|
+
#
|
790
|
+
# By default it's `nil`.
|
791
|
+
#
|
792
|
+
# This is part of a DSL, for this reason when this method is called with
|
793
|
+
# an argument, it will set the corresponding instance variable. When
|
794
|
+
# called without, it will return the already set value, or the default.
|
795
|
+
#
|
796
|
+
# @overload mapping(blk)
|
797
|
+
# Specify a set of mapping in the given block
|
798
|
+
# @param blk [Proc] the mapping definitions
|
799
|
+
#
|
800
|
+
# @overload mapping(path)
|
801
|
+
# Specify a relative path where to find the mapping file
|
802
|
+
# @param path [String] the relative path
|
803
|
+
#
|
804
|
+
# @overload mapping
|
805
|
+
# Gets the value
|
806
|
+
# @return [Lotus::Config::Mapping] the set of mappings
|
807
|
+
#
|
808
|
+
# @since 0.2.0
|
809
|
+
#
|
810
|
+
# @see http://rdoc.info/gems/lotus-model/Lotus/Mapper
|
811
|
+
#
|
812
|
+
# @example Getting the value
|
813
|
+
# require 'lotus'
|
814
|
+
#
|
815
|
+
# module Bookshelf
|
816
|
+
# class Application < Lotus::Application
|
817
|
+
# end
|
818
|
+
# end
|
819
|
+
#
|
820
|
+
# Bookshelf::Application.configuration.mapping
|
821
|
+
# # => nil
|
822
|
+
#
|
823
|
+
# @example Setting the value, by passing a block
|
824
|
+
# require 'lotus'
|
825
|
+
#
|
826
|
+
# module Bookshelf
|
827
|
+
# class Application < Lotus::Application
|
828
|
+
# configure do
|
829
|
+
# mapping do
|
830
|
+
# collection :users do
|
831
|
+
# entity User
|
832
|
+
#
|
833
|
+
# attribute :id, Integer
|
834
|
+
# attribute :name, String
|
835
|
+
# end
|
836
|
+
# end
|
837
|
+
# end
|
838
|
+
# end
|
839
|
+
# end
|
840
|
+
#
|
841
|
+
# Bookshelf::Application.configuration.mapping
|
842
|
+
# # => #<Lotus::Config::Mapping:0x007ff50a991388 @blk=#<Proc:0x007ff123991338@(irb):4>, @path=#<Pathname:.>>
|
843
|
+
#
|
844
|
+
# @example Setting the value, by passing a relative path
|
845
|
+
# require 'lotus'
|
846
|
+
#
|
847
|
+
# module Bookshelf
|
848
|
+
# class Application < Lotus::Application
|
849
|
+
# configure do
|
850
|
+
# mapping 'config/mapping'
|
851
|
+
# end
|
852
|
+
# end
|
853
|
+
# end
|
854
|
+
#
|
855
|
+
# Bookshelf::Application.configuration.mapping
|
856
|
+
# # => #<Lotus::Config::Routes:0x007ff50a991388 @blk=nil, @path=#<Pathname:config/mapping.rb>>
|
478
857
|
def mapping(path = nil, &blk)
|
479
858
|
if path or block_given?
|
480
859
|
@mapping = Config::Mapping.new(root, path, &blk)
|
@@ -483,11 +862,56 @@ module Lotus
|
|
483
862
|
end
|
484
863
|
end
|
485
864
|
|
865
|
+
# Adapter configuration.
|
866
|
+
# The application will instantiate adapter instance based on this configuration.
|
867
|
+
#
|
868
|
+
# The given options must have key pairs :type and :uri
|
869
|
+
# If it isn't, at the runtime the framework will raise a
|
870
|
+
# `ArgumentError`.
|
871
|
+
#
|
872
|
+
# This is part of a DSL, for this reason when this method is called with
|
873
|
+
# an argument, it will set the corresponding instance variable. When
|
874
|
+
# called without, it will return the already set value, or the default.
|
875
|
+
#
|
876
|
+
# @overload adapter(options)
|
877
|
+
# Sets the given type and uri
|
878
|
+
# @param options [Hash] a set of options for adapter
|
879
|
+
#
|
880
|
+
# @overload adapter
|
881
|
+
# Gets the value
|
882
|
+
# @return [Hash] adapter options
|
883
|
+
#
|
884
|
+
# @since 0.2.0
|
885
|
+
#
|
886
|
+
# @see Lotus::Configuration#adapter
|
887
|
+
# @see http://rdoc.info/gems/lotus-model/Lotus/Model/Configuration:adapter
|
888
|
+
#
|
889
|
+
# @example
|
890
|
+
# require 'lotus'
|
891
|
+
#
|
892
|
+
# module Bookshelf
|
893
|
+
# class Application < Lotus::Application
|
894
|
+
# configure do
|
895
|
+
# adapter type: :sql, uri: 'sqlite3://uri'
|
896
|
+
# end
|
897
|
+
# end
|
898
|
+
# end
|
899
|
+
#
|
900
|
+
# Bookshelf::Application.configuration.adapter
|
901
|
+
# # => {type: :sql, uri: 'sqlite3://uri'}
|
902
|
+
def adapter(options = {})
|
903
|
+
if !options.empty?
|
904
|
+
@adapter = options
|
905
|
+
else
|
906
|
+
@adapter
|
907
|
+
end
|
908
|
+
end
|
909
|
+
|
486
910
|
# Set a format as default fallback for all the requests without a strict
|
487
911
|
# requirement for the mime type.
|
488
912
|
#
|
489
913
|
# The given format must be coercible to a symbol, and be a valid mime type
|
490
|
-
# alias. If it isn't, at the runtime the framework will raise a
|
914
|
+
# alias. If it isn't, at the runtime the framework will raise a
|
491
915
|
# `Lotus::Controller::UnknownFormatError`.
|
492
916
|
#
|
493
917
|
# By default this value is `:html`.
|
@@ -590,6 +1014,17 @@ module Lotus
|
|
590
1014
|
end
|
591
1015
|
end
|
592
1016
|
|
1017
|
+
# Check if the application uses SSL
|
1018
|
+
#
|
1019
|
+
# @return [FalseClass,TrueClass] the result of the check
|
1020
|
+
#
|
1021
|
+
# @since 0.2.0
|
1022
|
+
#
|
1023
|
+
# @see Lotus::Configuration#scheme
|
1024
|
+
def ssl?
|
1025
|
+
scheme == SSL_SCHEME
|
1026
|
+
end
|
1027
|
+
|
593
1028
|
# The URI host for this application.
|
594
1029
|
# This is used by the router helpers to generate absolute URLs.
|
595
1030
|
#
|
@@ -637,18 +1072,14 @@ module Lotus
|
|
637
1072
|
if value
|
638
1073
|
@host = value
|
639
1074
|
else
|
640
|
-
@host ||=
|
1075
|
+
@host ||= @env.host
|
641
1076
|
end
|
642
1077
|
end
|
643
1078
|
|
644
1079
|
# The URI port for this application.
|
645
1080
|
# This is used by the router helpers to generate absolute URLs.
|
646
1081
|
#
|
647
|
-
# By default this value is `
|
648
|
-
# `scheme` is `"https"`.
|
649
|
-
#
|
650
|
-
# This is optional, you should set this value only if your application
|
651
|
-
# listens on a port not listed above.
|
1082
|
+
# By default this value is `2300`.
|
652
1083
|
#
|
653
1084
|
# This is part of a DSL, for this reason when this method is called with
|
654
1085
|
# an argument, it will set the corresponding instance variable. When
|
@@ -675,7 +1106,7 @@ module Lotus
|
|
675
1106
|
# end
|
676
1107
|
# end
|
677
1108
|
#
|
678
|
-
# Bookshelf::Application.configuration.port # =>
|
1109
|
+
# Bookshelf::Application.configuration.port # => 2300
|
679
1110
|
#
|
680
1111
|
# @example Setting the value
|
681
1112
|
# require 'lotus'
|
@@ -683,21 +1114,17 @@ module Lotus
|
|
683
1114
|
# module Bookshelf
|
684
1115
|
# class Application < Lotus::Application
|
685
1116
|
# configure do
|
686
|
-
# port
|
1117
|
+
# port 8080
|
687
1118
|
# end
|
688
1119
|
# end
|
689
1120
|
# end
|
690
1121
|
#
|
691
|
-
# Bookshelf::Application.configuration.port # =>
|
1122
|
+
# Bookshelf::Application.configuration.port # => 8080
|
692
1123
|
def port(value = nil)
|
693
1124
|
if value
|
694
1125
|
@port = Integer(value)
|
695
1126
|
else
|
696
|
-
@port ||
|
697
|
-
case scheme
|
698
|
-
when 'http' then 80
|
699
|
-
when 'https' then 443
|
700
|
-
end
|
1127
|
+
@port || @env.port
|
701
1128
|
end
|
702
1129
|
end
|
703
1130
|
|
@@ -957,5 +1384,236 @@ module Lotus
|
|
957
1384
|
@view_pattern ||= 'Views::%{controller}::%{action}'
|
958
1385
|
end
|
959
1386
|
end
|
1387
|
+
|
1388
|
+
# Decide if handle exceptions with an HTTP status or let them uncaught
|
1389
|
+
#
|
1390
|
+
# If this value is set to `true`, the configured exceptions will return
|
1391
|
+
# the specified HTTP status, the rest of them with `500`.
|
1392
|
+
#
|
1393
|
+
# If this value is set to `false`, the exceptions won't be caught.
|
1394
|
+
#
|
1395
|
+
# This is part of a DSL, for this reason when this method is called with
|
1396
|
+
# an argument, it will set the corresponding instance variable. When
|
1397
|
+
# called without, it will return the already set value, or the default.
|
1398
|
+
#
|
1399
|
+
# @overload handle_exceptions(value)
|
1400
|
+
# Sets the given value
|
1401
|
+
# @param value [TrueClass, FalseClass] true or false, default to true
|
1402
|
+
#
|
1403
|
+
# @overload handle_exceptions
|
1404
|
+
# Gets the value
|
1405
|
+
# @return [TrueClass, FalseClass]
|
1406
|
+
#
|
1407
|
+
# @since 0.2.0
|
1408
|
+
#
|
1409
|
+
# @see http://rdoc.info/gems/lotus-controller/Lotus/Controller/Configuration:handle_exceptions
|
1410
|
+
# @see http://httpstatus.es/500
|
1411
|
+
#
|
1412
|
+
# @example Enabled (default)
|
1413
|
+
# require 'lotus'
|
1414
|
+
#
|
1415
|
+
# module Bookshelf
|
1416
|
+
# class Application < Lotus::Application
|
1417
|
+
# configure do
|
1418
|
+
# routes do
|
1419
|
+
# get '/error', to: 'error#index'
|
1420
|
+
# end
|
1421
|
+
# end
|
1422
|
+
#
|
1423
|
+
# load!
|
1424
|
+
# end
|
1425
|
+
#
|
1426
|
+
# module Controllers::Error
|
1427
|
+
# include Bookshelf::Controller
|
1428
|
+
#
|
1429
|
+
# action 'Index' do
|
1430
|
+
# def call(params)
|
1431
|
+
# raise ArgumentError
|
1432
|
+
# end
|
1433
|
+
# end
|
1434
|
+
# end
|
1435
|
+
# end
|
1436
|
+
#
|
1437
|
+
# # GET '/error' # => 500 - Internal Server Error
|
1438
|
+
#
|
1439
|
+
# @example Disabled
|
1440
|
+
# require 'lotus'
|
1441
|
+
#
|
1442
|
+
# module Bookshelf
|
1443
|
+
# class Application < Lotus::Application
|
1444
|
+
# configure do
|
1445
|
+
# handle_exceptions false
|
1446
|
+
#
|
1447
|
+
# routes do
|
1448
|
+
# get '/error', to: 'error#index'
|
1449
|
+
# end
|
1450
|
+
# end
|
1451
|
+
#
|
1452
|
+
# load!
|
1453
|
+
# end
|
1454
|
+
#
|
1455
|
+
# module Controllers::Error
|
1456
|
+
# include Bookshelf::Controller
|
1457
|
+
#
|
1458
|
+
# action 'Index' do
|
1459
|
+
# def call(params)
|
1460
|
+
# raise ArgumentError
|
1461
|
+
# end
|
1462
|
+
# end
|
1463
|
+
# end
|
1464
|
+
# end
|
1465
|
+
#
|
1466
|
+
# # GET '/error' # => raises ArgumentError
|
1467
|
+
def handle_exceptions(value = nil)
|
1468
|
+
if value.nil?
|
1469
|
+
@handle_exceptions
|
1470
|
+
else
|
1471
|
+
@handle_exceptions = value
|
1472
|
+
end
|
1473
|
+
end
|
1474
|
+
|
1475
|
+
# It lazily collects all the low level settings for Lotus::Model's
|
1476
|
+
# configuration and applies them when the application is loaded.
|
1477
|
+
#
|
1478
|
+
# NOTE: This forwards all the configurations to Lotus::Model, without
|
1479
|
+
# checking them. Before to use this feature, please have a look at the
|
1480
|
+
# current Lotus::Model version installed.
|
1481
|
+
#
|
1482
|
+
# NOTE: This may override some configurations of your application.
|
1483
|
+
#
|
1484
|
+
# @return [Lotus::Config::FrameworkConfiguration] the configuration
|
1485
|
+
#
|
1486
|
+
# @since 0.2.0
|
1487
|
+
#
|
1488
|
+
# @see http://www.rubydoc.info/gems/lotus-model/Lotus/Model/Configuration
|
1489
|
+
#
|
1490
|
+
# @example Define a setting
|
1491
|
+
# require 'lotus'
|
1492
|
+
# require 'lotus/model'
|
1493
|
+
#
|
1494
|
+
# module Bookshelf
|
1495
|
+
# class Application < Lotus::Application
|
1496
|
+
# configure do
|
1497
|
+
# model.adapter type: :memory, uri: 'memory://localhost/database'
|
1498
|
+
# end
|
1499
|
+
# end
|
1500
|
+
# end
|
1501
|
+
#
|
1502
|
+
# @example Override a setting
|
1503
|
+
# require 'lotus'
|
1504
|
+
# require 'lotus/model'
|
1505
|
+
#
|
1506
|
+
# module Bookshelf
|
1507
|
+
# class Application < Lotus::Application
|
1508
|
+
# configure do
|
1509
|
+
# adapter type: :sql, uri: 'postgres://localhost/database'
|
1510
|
+
# model.adapter type: :memory, uri: 'memory://localhost/database'
|
1511
|
+
# end
|
1512
|
+
# end
|
1513
|
+
# end
|
1514
|
+
#
|
1515
|
+
# # The memory adapter will override the SQL one
|
1516
|
+
def model
|
1517
|
+
@model ||= Config::FrameworkConfiguration.new
|
1518
|
+
end
|
1519
|
+
|
1520
|
+
# It lazily collects all the low level settings for Lotus::Controller's
|
1521
|
+
# configuration and applies them when the application is loaded.
|
1522
|
+
#
|
1523
|
+
# NOTE: This forwards all the configurations to Lotus::Controller, without
|
1524
|
+
# checking them. Before to use this feature, please have a look at the
|
1525
|
+
# current Lotus::Controller version installed.
|
1526
|
+
#
|
1527
|
+
# NOTE: This may override some configurations of your application.
|
1528
|
+
#
|
1529
|
+
# @return [Lotus::Config::FrameworkConfiguration] the configuration
|
1530
|
+
#
|
1531
|
+
# @since 0.2.0
|
1532
|
+
#
|
1533
|
+
# @see http://www.rubydoc.info/gems/lotus-controller/Lotus/Controller/Configuration
|
1534
|
+
#
|
1535
|
+
# @example Define a setting
|
1536
|
+
# require 'lotus'
|
1537
|
+
#
|
1538
|
+
# module Bookshelf
|
1539
|
+
# class Application < Lotus::Application
|
1540
|
+
# configure do
|
1541
|
+
# controller.default_format :json
|
1542
|
+
# end
|
1543
|
+
# end
|
1544
|
+
# end
|
1545
|
+
#
|
1546
|
+
# @example Override a setting
|
1547
|
+
# require 'lotus'
|
1548
|
+
#
|
1549
|
+
# module Bookshelf
|
1550
|
+
# class Application < Lotus::Application
|
1551
|
+
# configure do
|
1552
|
+
# handle_exceptions false
|
1553
|
+
# controller.handle_exceptions true
|
1554
|
+
# end
|
1555
|
+
# end
|
1556
|
+
# end
|
1557
|
+
#
|
1558
|
+
# # Exceptions will be handled
|
1559
|
+
def controller
|
1560
|
+
@controller ||= Config::FrameworkConfiguration.new
|
1561
|
+
end
|
1562
|
+
|
1563
|
+
# It lazily collects all the low level settings for Lotus::View's
|
1564
|
+
# configuration and applies them when the application is loaded.
|
1565
|
+
#
|
1566
|
+
# NOTE: This forwards all the configurations to Lotus::View, without
|
1567
|
+
# checking them. Before to use this feature, please have a look at the
|
1568
|
+
# current Lotus::View version installed.
|
1569
|
+
#
|
1570
|
+
# NOTE: This may override some configurations of your application.
|
1571
|
+
#
|
1572
|
+
# @return [Lotus::Config::FrameworkConfiguration] the configuration
|
1573
|
+
#
|
1574
|
+
# @since 0.2.0
|
1575
|
+
#
|
1576
|
+
# @see http://www.rubydoc.info/gems/lotus-view/Lotus/View/Configuration
|
1577
|
+
#
|
1578
|
+
# @example Define a setting
|
1579
|
+
# require 'lotus'
|
1580
|
+
#
|
1581
|
+
# module Bookshelf
|
1582
|
+
# class Application < Lotus::Application
|
1583
|
+
# configure do
|
1584
|
+
# view.layout :application
|
1585
|
+
# end
|
1586
|
+
# end
|
1587
|
+
# end
|
1588
|
+
#
|
1589
|
+
# @example Override a setting
|
1590
|
+
# require 'lotus'
|
1591
|
+
#
|
1592
|
+
# module Bookshelf
|
1593
|
+
# class Application < Lotus::Application
|
1594
|
+
# configure do
|
1595
|
+
# layout :application
|
1596
|
+
# view.layout :backend
|
1597
|
+
# end
|
1598
|
+
# end
|
1599
|
+
# end
|
1600
|
+
#
|
1601
|
+
# # It will use `:backend` layout
|
1602
|
+
def view
|
1603
|
+
@view ||= Config::FrameworkConfiguration.new
|
1604
|
+
end
|
1605
|
+
|
1606
|
+
private
|
1607
|
+
# @since 0.2.0
|
1608
|
+
# @api private
|
1609
|
+
def evaluate_configurations!
|
1610
|
+
configurations.each { |c| instance_eval(&c) }
|
1611
|
+
end
|
1612
|
+
|
1613
|
+
# @since 0.2.0
|
1614
|
+
# @api private
|
1615
|
+
def configurations
|
1616
|
+
[ @blk ] + @configurations[@env.environment]
|
1617
|
+
end
|
960
1618
|
end
|
961
1619
|
end
|