lotusrb 0.5.0 → 0.6.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 +57 -14
- data/FEATURES.md +21 -0
- data/LICENSE.md +1 -1
- data/README.md +8 -7
- data/bin/lotus +1 -0
- data/lib/lotus.rb +6 -0
- data/lib/lotus/action/csrf_protection.rb +1 -1
- data/lib/lotus/application.rb +4 -4
- data/lib/lotus/application_name.rb +8 -6
- data/lib/lotus/cli.rb +75 -66
- data/lib/lotus/cli_sub_commands/assets.rb +29 -0
- data/lib/lotus/{commands → cli_sub_commands}/db.rb +24 -29
- data/lib/lotus/cli_sub_commands/destroy.rb +102 -0
- data/lib/lotus/cli_sub_commands/generate.rb +127 -0
- data/lib/lotus/commands/assets/precompile.rb +35 -0
- data/lib/lotus/commands/console.rb +28 -8
- data/lib/lotus/commands/db/abstract.rb +6 -2
- data/lib/lotus/commands/db/console.rb +5 -5
- data/lib/lotus/commands/generate/abstract.rb +63 -0
- data/lib/lotus/commands/generate/action.rb +262 -0
- data/lib/lotus/commands/generate/app.rb +116 -0
- data/lib/lotus/commands/generate/mailer.rb +118 -0
- data/lib/lotus/commands/generate/migration.rb +63 -0
- data/lib/lotus/commands/generate/model.rb +96 -0
- data/lib/lotus/commands/new/abstract.rb +128 -0
- data/lib/lotus/commands/new/app.rb +116 -0
- data/lib/lotus/commands/new/container.rb +102 -0
- data/lib/lotus/commands/routes.rb +19 -2
- data/lib/lotus/commands/server.rb +16 -2
- data/lib/lotus/config/framework_configuration.rb +13 -1
- data/lib/lotus/configuration.rb +24 -76
- data/lib/lotus/container.rb +15 -2
- data/lib/lotus/environment.rb +43 -4
- data/lib/lotus/frameworks.rb +1 -0
- data/lib/lotus/generators/action/action_spec.minitest.tt +1 -1
- data/lib/lotus/generators/action/action_spec.rspec.tt +1 -1
- data/lib/lotus/generators/action/view_spec.minitest.tt +1 -1
- data/lib/lotus/generators/action/view_spec.rspec.tt +1 -1
- data/lib/lotus/generators/{slice → app}/.gitkeep.tt +0 -0
- data/lib/lotus/generators/{slice → app}/application.rb.tt +61 -23
- data/lib/lotus/generators/app/config/initializers/.gitkeep +0 -0
- data/lib/lotus/generators/{slice → app}/config/routes.rb.tt +0 -0
- data/lib/lotus/generators/app/favicon.ico +0 -0
- data/lib/lotus/generators/{slice → app}/templates/application.html.erb.tt +2 -1
- data/lib/lotus/generators/app/views/application_layout.rb.tt +7 -0
- data/lib/lotus/generators/application/app/.env.development.tt +1 -0
- data/lib/lotus/generators/application/app/.env.test.tt +1 -0
- data/lib/lotus/generators/application/app/Gemfile.tt +1 -0
- data/lib/lotus/generators/application/app/Rakefile.minitest.tt +1 -0
- data/lib/lotus/generators/application/app/Rakefile.rspec.tt +1 -0
- data/lib/lotus/generators/application/app/config/application.rb.tt +56 -18
- data/lib/lotus/generators/application/app/config/initializers/.gitkeep +0 -0
- data/lib/lotus/generators/application/app/favicon.ico +0 -0
- data/lib/lotus/generators/application/app/gitignore.tt +2 -0
- data/lib/lotus/generators/application/app/lotusrc.tt +3 -3
- data/lib/lotus/generators/application/app/spec_helper.rb.rspec.tt +5 -1
- data/lib/lotus/generators/application/app/templates/application.html.erb.tt +1 -0
- data/lib/lotus/generators/application/container/.env.development.tt +1 -0
- data/lib/lotus/generators/application/container/.env.test.tt +1 -0
- data/lib/lotus/generators/application/container/Gemfile.tt +1 -1
- data/lib/lotus/generators/application/container/Rakefile.minitest.tt +1 -0
- data/lib/lotus/generators/application/container/Rakefile.rspec.tt +1 -0
- data/lib/lotus/generators/application/container/config/initializers/.gitkeep +0 -0
- data/lib/lotus/generators/application/container/gitignore.tt +2 -0
- data/lib/lotus/generators/application/container/lib/chirp/mailers/.gitkeep +0 -0
- data/lib/lotus/generators/application/container/lib/chirp/mailers/templates/.gitkeep +0 -0
- data/lib/lotus/generators/application/container/lotusrc.tt +3 -3
- data/lib/lotus/generators/application/container/spec_helper.rb.rspec.tt +5 -1
- data/lib/lotus/generators/database_config.rb +17 -4
- data/lib/lotus/generators/generatable.rb +51 -0
- data/lib/lotus/generators/generator.rb +35 -0
- data/lib/lotus/generators/test_framework.rb +42 -0
- data/lib/lotus/loader.rb +43 -0
- data/lib/lotus/lotusrc.rb +50 -49
- data/lib/lotus/middleware.rb +28 -10
- data/lib/lotus/rake_helper.rb +68 -0
- data/lib/lotus/rake_tasks.rb +2 -0
- data/lib/lotus/rendering_policy.rb +2 -2
- data/lib/lotus/repositories/car_repository.rb +3 -0
- data/lib/lotus/repositories/name_repository.rb +3 -0
- data/lib/lotus/setup.rb +1 -3
- data/lib/lotus/static.rb +77 -0
- data/lib/lotus/templates/welcome.html.erb +7 -4
- data/lib/lotus/version.rb +1 -1
- data/lib/lotus/views/default.rb +2 -1
- data/lib/lotus/views/default_template_finder.rb +4 -3
- data/lotusrb.gemspec +11 -9
- metadata +79 -60
- data/lib/lotus/commands/generate.rb +0 -97
- data/lib/lotus/commands/new.rb +0 -43
- data/lib/lotus/config/assets.rb +0 -81
- data/lib/lotus/generators/abstract.rb +0 -31
- data/lib/lotus/generators/action.rb +0 -235
- data/lib/lotus/generators/app.rb +0 -39
- data/lib/lotus/generators/app/.gitkeep +0 -1
- data/lib/lotus/generators/application/app.rb +0 -129
- data/lib/lotus/generators/application/container.rb +0 -111
- data/lib/lotus/generators/mailer.rb +0 -112
- data/lib/lotus/generators/migration.rb +0 -58
- data/lib/lotus/generators/model.rb +0 -90
- data/lib/lotus/generators/slice.rb +0 -94
- data/lib/lotus/generators/slice/views/application_layout.rb.tt +0 -7
@@ -0,0 +1,102 @@
|
|
1
|
+
require 'lotus/commands/generate/app'
|
2
|
+
require 'lotus/commands/new/abstract'
|
3
|
+
|
4
|
+
module Lotus
|
5
|
+
module Commands
|
6
|
+
class New
|
7
|
+
class Container < Abstract
|
8
|
+
|
9
|
+
DEFAULT_APPLICATION_NAME = 'web'.freeze
|
10
|
+
|
11
|
+
def map_templates
|
12
|
+
add_application_templates
|
13
|
+
add_empty_directories
|
14
|
+
add_test_templates
|
15
|
+
add_sql_templates
|
16
|
+
add_git_templates
|
17
|
+
end
|
18
|
+
|
19
|
+
def template_options
|
20
|
+
{
|
21
|
+
app_name: app_name,
|
22
|
+
lotus_head: lotus_head?,
|
23
|
+
test: test_framework.framework,
|
24
|
+
database: database_config.type,
|
25
|
+
database_config: database_config.to_hash,
|
26
|
+
lotus_model_version: lotus_model_version,
|
27
|
+
}
|
28
|
+
end
|
29
|
+
|
30
|
+
def post_process_templates
|
31
|
+
init_git
|
32
|
+
generate_app
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
def add_application_templates
|
38
|
+
add_mapping('lotusrc.tt', '.lotusrc')
|
39
|
+
add_mapping('.env.tt', '.env')
|
40
|
+
add_mapping('.env.development.tt', '.env.development')
|
41
|
+
add_mapping('.env.test.tt', '.env.test')
|
42
|
+
add_mapping('Gemfile.tt', 'Gemfile')
|
43
|
+
add_mapping('config.ru.tt', 'config.ru')
|
44
|
+
add_mapping('config/environment.rb.tt', 'config/environment.rb')
|
45
|
+
add_mapping('lib/app_name.rb.tt', "lib/#{ app_name }.rb")
|
46
|
+
add_mapping('lib/config/mapping.rb.tt', 'lib/config/mapping.rb')
|
47
|
+
end
|
48
|
+
|
49
|
+
def add_test_templates
|
50
|
+
if test_framework.rspec?
|
51
|
+
add_mapping('Rakefile.rspec.tt', 'Rakefile')
|
52
|
+
add_mapping('rspec.rspec.tt', '.rspec')
|
53
|
+
add_mapping('spec_helper.rb.rspec.tt', 'spec/spec_helper.rb')
|
54
|
+
add_mapping('features_helper.rb.rspec.tt', 'spec/features_helper.rb')
|
55
|
+
add_mapping('capybara.rb.rspec.tt', 'spec/support/capybara.rb')
|
56
|
+
else # minitest (default)
|
57
|
+
add_mapping('Rakefile.minitest.tt', 'Rakefile')
|
58
|
+
add_mapping('spec_helper.rb.minitest.tt', 'spec/spec_helper.rb')
|
59
|
+
add_mapping('features_helper.rb.minitest.tt', 'spec/features_helper.rb')
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def add_empty_directories
|
64
|
+
add_mapping('.gitkeep', 'public/.gitkeep')
|
65
|
+
add_mapping('.gitkeep', 'config/initializers/.gitkeep')
|
66
|
+
add_mapping('.gitkeep', "lib/#{ app_name }/entities/.gitkeep")
|
67
|
+
add_mapping('.gitkeep', "lib/#{ app_name }/repositories/.gitkeep")
|
68
|
+
add_mapping('.gitkeep', "lib/#{ app_name }/mailers/.gitkeep")
|
69
|
+
add_mapping('.gitkeep', "lib/#{ app_name }/mailers/templates/.gitkeep")
|
70
|
+
add_mapping('.gitkeep', "spec/#{ app_name }/entities/.gitkeep")
|
71
|
+
add_mapping('.gitkeep', "spec/#{ app_name }/repositories/.gitkeep")
|
72
|
+
add_mapping('.gitkeep', "spec/#{ app_name }/mailers/.gitkeep")
|
73
|
+
add_mapping('.gitkeep', 'spec/support/.gitkeep')
|
74
|
+
|
75
|
+
if database_config.sql?
|
76
|
+
add_mapping('.gitkeep', 'db/migrations/.gitkeep')
|
77
|
+
else
|
78
|
+
add_mapping('.gitkeep', 'db/.gitkeep')
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
def generate_app
|
83
|
+
Lotus::Commands::Generate::App.new(app_options, app_slice_name).start
|
84
|
+
end
|
85
|
+
|
86
|
+
def app_options
|
87
|
+
{
|
88
|
+
application_base_url: application_base_url
|
89
|
+
}
|
90
|
+
end
|
91
|
+
|
92
|
+
def app_slice_name
|
93
|
+
options.fetch(:application_name, DEFAULT_APPLICATION_NAME)
|
94
|
+
end
|
95
|
+
|
96
|
+
def template_source_path
|
97
|
+
Pathname.new(::File.dirname(__FILE__)).join('..', '..', 'generators', 'application', 'container').realpath
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
@@ -1,17 +1,34 @@
|
|
1
1
|
module Lotus
|
2
2
|
module Commands
|
3
|
+
# Display application/container routes.
|
4
|
+
#
|
5
|
+
# It is run with:
|
6
|
+
#
|
7
|
+
# `bundle exec lotus routes`
|
8
|
+
#
|
9
|
+
# @since 0.1.0
|
10
|
+
# @api private
|
3
11
|
class Routes
|
4
|
-
|
5
|
-
|
12
|
+
# @param options [Hash] Environment's options
|
13
|
+
#
|
14
|
+
# @since 0.1.0
|
15
|
+
# @see Lotus::Environment#initialize
|
16
|
+
def initialize(options)
|
17
|
+
@environment = Lotus::Environment.new(options)
|
6
18
|
@environment.require_application_environment
|
7
19
|
end
|
8
20
|
|
21
|
+
# Display to STDOUT application routes
|
22
|
+
#
|
23
|
+
# @since 0.1.0
|
9
24
|
def start
|
10
25
|
puts app.routes.inspector.to_s
|
11
26
|
end
|
12
27
|
|
13
28
|
private
|
14
29
|
|
30
|
+
# @since 0.1.0
|
31
|
+
# @api private
|
15
32
|
def app
|
16
33
|
if @environment.container?
|
17
34
|
Lotus::Container.new
|
@@ -19,8 +19,12 @@ module Lotus
|
|
19
19
|
class Server < ::Rack::Server
|
20
20
|
attr_reader :options
|
21
21
|
|
22
|
-
|
23
|
-
|
22
|
+
# @param options [Hash] Environment's options
|
23
|
+
#
|
24
|
+
# @since 0.1.0
|
25
|
+
# @see Lotus::Environment#initialize
|
26
|
+
def initialize(options)
|
27
|
+
@_env = Lotus::Environment.new(options)
|
24
28
|
@options = _extract_options(@_env)
|
25
29
|
|
26
30
|
if code_reloading?
|
@@ -31,6 +35,8 @@ module Lotus
|
|
31
35
|
|
32
36
|
# Primarily this removes the ::Rack::Chunked middleware
|
33
37
|
# which is the cause of Safari content-length bugs.
|
38
|
+
#
|
39
|
+
# @since 0.1.0
|
34
40
|
def middleware
|
35
41
|
mw = Hash.new { |e, m| e[m] = [] }
|
36
42
|
mw["deployment"].concat([::Rack::ContentLength, ::Rack::CommonLogger])
|
@@ -38,6 +44,9 @@ module Lotus
|
|
38
44
|
mw
|
39
45
|
end
|
40
46
|
|
47
|
+
# Kickstart shotgun preloader if code reloading is supported
|
48
|
+
#
|
49
|
+
# @since 0.1.0
|
41
50
|
def start
|
42
51
|
if code_reloading?
|
43
52
|
Shotgun.enable_copy_on_write
|
@@ -48,6 +57,9 @@ module Lotus
|
|
48
57
|
end
|
49
58
|
|
50
59
|
private
|
60
|
+
|
61
|
+
# @since 0.1.0
|
62
|
+
# @api private
|
51
63
|
def _extract_options(env)
|
52
64
|
env.to_options.merge(
|
53
65
|
config: env.rackup.to_s,
|
@@ -57,6 +69,8 @@ module Lotus
|
|
57
69
|
)
|
58
70
|
end
|
59
71
|
|
72
|
+
# @since 0.1.0
|
73
|
+
# @api private
|
60
74
|
def code_reloading?
|
61
75
|
@_env.code_reloading?
|
62
76
|
end
|
@@ -8,18 +8,30 @@ module Lotus
|
|
8
8
|
class FrameworkConfiguration < BasicObject
|
9
9
|
# @since 0.2.0
|
10
10
|
# @api private
|
11
|
-
def initialize
|
11
|
+
def initialize(&blk)
|
12
|
+
@blocks = [blk || ::Proc.new { }]
|
12
13
|
@settings = []
|
13
14
|
end
|
14
15
|
|
15
16
|
# @since 0.2.0
|
16
17
|
# @api private
|
17
18
|
def __apply(configuration)
|
19
|
+
@blocks.compact.each do |blk|
|
20
|
+
configuration.instance_eval(&blk)
|
21
|
+
end
|
22
|
+
|
18
23
|
@settings.each do |(m, args, blk)|
|
19
24
|
configuration.public_send(m, *args, &blk)
|
20
25
|
end
|
21
26
|
end
|
22
27
|
|
28
|
+
# @since 0.6.0
|
29
|
+
# @api private
|
30
|
+
def __add(&blk)
|
31
|
+
@blocks << blk
|
32
|
+
self
|
33
|
+
end
|
34
|
+
|
23
35
|
# @since 0.2.0
|
24
36
|
# @api private
|
25
37
|
def method_missing(m, *args, &blk)
|
data/lib/lotus/configuration.rb
CHANGED
@@ -3,7 +3,6 @@ require 'lotus/utils/deprecation'
|
|
3
3
|
require 'lotus/environment'
|
4
4
|
require 'lotus/config/framework_configuration'
|
5
5
|
require 'lotus/config/load_paths'
|
6
|
-
require 'lotus/config/assets'
|
7
6
|
require 'lotus/config/routes'
|
8
7
|
require 'lotus/config/mapping'
|
9
8
|
require 'lotus/config/sessions'
|
@@ -389,8 +388,6 @@ module Lotus
|
|
389
388
|
#
|
390
389
|
# @since 0.1.0
|
391
390
|
#
|
392
|
-
# @see Lotus::Configuration#serve_assets
|
393
|
-
#
|
394
391
|
# @example Getting the value
|
395
392
|
# require 'lotus'
|
396
393
|
#
|
@@ -408,69 +405,22 @@ module Lotus
|
|
408
405
|
# module Bookshelf
|
409
406
|
# class Application < Lotus::Application
|
410
407
|
# configure do
|
411
|
-
#
|
412
|
-
#
|
413
|
-
#
|
414
|
-
#
|
408
|
+
# assets do
|
409
|
+
# sources << [
|
410
|
+
# 'vendor/assets'
|
411
|
+
# ]
|
412
|
+
# end
|
415
413
|
# end
|
416
414
|
# end
|
417
415
|
# end
|
418
416
|
#
|
419
417
|
# Bookshelf::Application.configuration.assets
|
420
418
|
# # => #<Lotus::Config::Assets @root=#<Pathname:/root/path/assets>, @paths=["public"]>
|
421
|
-
|
422
|
-
|
423
|
-
|
424
|
-
end
|
425
|
-
|
426
|
-
# Configure serving of assets
|
427
|
-
# Enable static assets (disabled by default).
|
428
|
-
#
|
429
|
-
# This is part of a DSL, for this reason when this method is called with
|
430
|
-
# an argument, it will set the corresponding instance variable. When
|
431
|
-
# called without, it will return the already set value, or the default.
|
432
|
-
#
|
433
|
-
# @since 0.2.0
|
434
|
-
#
|
435
|
-
# @overload serve_assets(value)
|
436
|
-
# Sets the given value.
|
437
|
-
# @param value [TrueClass, FalseClass]
|
438
|
-
#
|
439
|
-
# @overload serve_assets
|
440
|
-
# Gets the value.
|
441
|
-
# @return [TrueClass, FalseClass]
|
442
|
-
#
|
443
|
-
# @see Lotus::Configuration#assets
|
444
|
-
#
|
445
|
-
# @example Getting serve assets configuration by default
|
446
|
-
# require 'lotus'
|
447
|
-
#
|
448
|
-
# module Bookshelf
|
449
|
-
# class Application < Lotus::Application
|
450
|
-
# end
|
451
|
-
# end
|
452
|
-
#
|
453
|
-
# Bookshelf::Application.configuration.serve_assets
|
454
|
-
# # => false
|
455
|
-
#
|
456
|
-
# @example Enabling static assets
|
457
|
-
# require 'lotus'
|
458
|
-
#
|
459
|
-
# module Bookshelf
|
460
|
-
# class Application < Lotus::Application
|
461
|
-
# configure do
|
462
|
-
# serve_assets true
|
463
|
-
# end
|
464
|
-
# end
|
465
|
-
# end
|
466
|
-
#
|
467
|
-
# Bookshelf::Application.configuration.serve_assets
|
468
|
-
# # => true
|
469
|
-
def serve_assets(value = nil)
|
470
|
-
if value.nil?
|
471
|
-
@serve_assets || false
|
419
|
+
def assets(&blk)
|
420
|
+
if @assets
|
421
|
+
@assets.__add(&blk)
|
472
422
|
else
|
473
|
-
@
|
423
|
+
@assets ||= Config::FrameworkConfiguration.new(&blk)
|
474
424
|
end
|
475
425
|
end
|
476
426
|
|
@@ -1277,14 +1227,12 @@ module Lotus
|
|
1277
1227
|
# end
|
1278
1228
|
# end
|
1279
1229
|
#
|
1280
|
-
# module Controllers
|
1281
|
-
#
|
1282
|
-
# include Bookshelf::
|
1230
|
+
# module Controllers::Dashboard
|
1231
|
+
# class Index
|
1232
|
+
# include Bookshelf::Action
|
1283
1233
|
#
|
1284
|
-
#
|
1285
|
-
#
|
1286
|
-
# # ...
|
1287
|
-
# end
|
1234
|
+
# def call(params)
|
1235
|
+
# # ...
|
1288
1236
|
# end
|
1289
1237
|
# end
|
1290
1238
|
# end
|
@@ -1312,9 +1260,9 @@ module Lotus
|
|
1312
1260
|
# end
|
1313
1261
|
#
|
1314
1262
|
# module DashboardController
|
1315
|
-
#
|
1263
|
+
# class Index
|
1264
|
+
# include Bookshelf::Action
|
1316
1265
|
#
|
1317
|
-
# action 'Index' do
|
1318
1266
|
# def call(params)
|
1319
1267
|
# end
|
1320
1268
|
# end
|
@@ -1345,9 +1293,9 @@ module Lotus
|
|
1345
1293
|
# end
|
1346
1294
|
#
|
1347
1295
|
# module DashboardController
|
1348
|
-
#
|
1296
|
+
# class Index
|
1297
|
+
# incude Bookshelf::Action
|
1349
1298
|
#
|
1350
|
-
# action 'Index' do
|
1351
1299
|
# def call(params)
|
1352
1300
|
# end
|
1353
1301
|
# end
|
@@ -1530,9 +1478,9 @@ module Lotus
|
|
1530
1478
|
# end
|
1531
1479
|
#
|
1532
1480
|
# module Controllers::Error
|
1533
|
-
#
|
1481
|
+
# class Index
|
1482
|
+
# include Bookshelf::Action
|
1534
1483
|
#
|
1535
|
-
# action 'Index' do
|
1536
1484
|
# def call(params)
|
1537
1485
|
# raise ArgumentError
|
1538
1486
|
# end
|
@@ -1559,9 +1507,9 @@ module Lotus
|
|
1559
1507
|
# end
|
1560
1508
|
#
|
1561
1509
|
# module Controllers::Error
|
1562
|
-
#
|
1510
|
+
# class Index
|
1511
|
+
# include Bookshelf::Action
|
1563
1512
|
#
|
1564
|
-
# action 'Index' do
|
1565
1513
|
# def call(params)
|
1566
1514
|
# raise ArgumentError
|
1567
1515
|
# end
|
@@ -1731,9 +1679,9 @@ module Lotus
|
|
1731
1679
|
# end
|
1732
1680
|
#
|
1733
1681
|
# module Controllers::Error
|
1734
|
-
#
|
1682
|
+
# class Index
|
1683
|
+
# include Bookshelf::Action
|
1735
1684
|
#
|
1736
|
-
# action 'Index' do
|
1737
1685
|
# def call(params)
|
1738
1686
|
# Bookshelf::Logger.info "Logging to STDOUT"
|
1739
1687
|
# end
|
data/lib/lotus/container.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'thread'
|
2
|
+
require 'rack/builder'
|
2
3
|
require 'lotus/router'
|
3
4
|
|
4
5
|
module Lotus
|
@@ -28,12 +29,12 @@ module Lotus
|
|
28
29
|
def initialize
|
29
30
|
Mutex.new.synchronize do
|
30
31
|
assert_configuration_presence!
|
31
|
-
|
32
|
+
prepare_middleware_stack!
|
32
33
|
end
|
33
34
|
end
|
34
35
|
|
35
36
|
def call(env)
|
36
|
-
@
|
37
|
+
@builder.call(env)
|
37
38
|
end
|
38
39
|
|
39
40
|
private
|
@@ -42,5 +43,17 @@ module Lotus
|
|
42
43
|
raise ArgumentError.new("#{ self.class } doesn't have any application mounted.")
|
43
44
|
end
|
44
45
|
end
|
46
|
+
|
47
|
+
def prepare_middleware_stack!
|
48
|
+
@builder = ::Rack::Builder.new
|
49
|
+
@routes = Router.new(&@@configuration)
|
50
|
+
|
51
|
+
if Lotus.environment.serve_static_assets?
|
52
|
+
require 'lotus/static'
|
53
|
+
@builder.use Lotus::Static
|
54
|
+
end
|
55
|
+
|
56
|
+
@builder.run @routes
|
57
|
+
end
|
45
58
|
end
|
46
59
|
end
|
data/lib/lotus/environment.rb
CHANGED
@@ -29,6 +29,18 @@ module Lotus
|
|
29
29
|
# @api private
|
30
30
|
DEFAULT_ENV = 'development'.freeze
|
31
31
|
|
32
|
+
# Production environment
|
33
|
+
#
|
34
|
+
# @since 0.6.0
|
35
|
+
# @api private
|
36
|
+
PRODUCTION_ENV = 'production'.freeze
|
37
|
+
|
38
|
+
# Rack production environment (aka deployment)
|
39
|
+
#
|
40
|
+
# @since 0.6.0
|
41
|
+
# @api private
|
42
|
+
RACK_ENV_DEPLOYMENT = 'deployment'.freeze
|
43
|
+
|
32
44
|
# Default `.env` file name
|
33
45
|
#
|
34
46
|
# @since 0.2.0
|
@@ -111,6 +123,14 @@ module Lotus
|
|
111
123
|
# @api private
|
112
124
|
APPLICATION_PATH = 'app'.freeze
|
113
125
|
|
126
|
+
# @since 0.4.0
|
127
|
+
# @api private
|
128
|
+
SERVE_STATIC_ASSETS = 'SERVE_STATIC_ASSETS'.freeze
|
129
|
+
|
130
|
+
# @since 0.4.0
|
131
|
+
# @api private
|
132
|
+
SERVE_STATIC_ASSETS_ENABLED = 'true'.freeze
|
133
|
+
|
114
134
|
# Initialize a Lotus environment
|
115
135
|
#
|
116
136
|
# It accepts an optional set of configurations from the CLI commands.
|
@@ -173,7 +193,7 @@ module Lotus
|
|
173
193
|
# # the one defined in the parent (eg `FOO` is overwritten). All the
|
174
194
|
# # other settings (eg `XYZ`) will be left untouched.
|
175
195
|
def initialize(options = {})
|
176
|
-
@options = Lotus::Lotusrc.new(root
|
196
|
+
@options = Lotus::Lotusrc.new(root).options
|
177
197
|
@options.merge! Utils::Hash.new(options.clone).symbolize!
|
178
198
|
@mutex = Mutex.new
|
179
199
|
@mutex.synchronize { set_env_vars! }
|
@@ -188,13 +208,15 @@ module Lotus
|
|
188
208
|
#
|
189
209
|
# If those are missing it falls back to the defalt one: `"development"`.
|
190
210
|
#
|
211
|
+
# Rack environment `"deployment"` is translated to Lotus `"production"`.
|
212
|
+
#
|
191
213
|
# @return [String] the current environment
|
192
214
|
#
|
193
215
|
# @since 0.1.0
|
194
216
|
#
|
195
217
|
# @see Lotus::Environment::DEFAULT_ENV
|
196
218
|
def environment
|
197
|
-
@environment ||= ENV[LOTUS_ENV] ||
|
219
|
+
@environment ||= ENV[LOTUS_ENV] || rack_env || DEFAULT_ENV
|
198
220
|
end
|
199
221
|
|
200
222
|
# @since 0.3.1
|
@@ -213,7 +235,7 @@ module Lotus
|
|
213
235
|
#
|
214
236
|
# @see http://bundler.io/v1.7/groups.html
|
215
237
|
def bundler_groups
|
216
|
-
[environment]
|
238
|
+
[:default, environment]
|
217
239
|
end
|
218
240
|
|
219
241
|
# Application's root
|
@@ -385,6 +407,12 @@ module Lotus
|
|
385
407
|
architecture == CONTAINER
|
386
408
|
end
|
387
409
|
|
410
|
+
# @since 0.6.0
|
411
|
+
# @api private
|
412
|
+
def serve_static_assets?
|
413
|
+
SERVE_STATIC_ASSETS_ENABLED == ENV[SERVE_STATIC_ASSETS]
|
414
|
+
end
|
415
|
+
|
388
416
|
# @since 0.4.0
|
389
417
|
# @api private
|
390
418
|
def apps_path
|
@@ -418,8 +446,8 @@ module Lotus
|
|
418
446
|
# @since 0.1.0
|
419
447
|
# @api private
|
420
448
|
def set_env_vars!
|
421
|
-
set_lotus_env_vars!
|
422
449
|
set_application_env_vars!
|
450
|
+
set_lotus_env_vars!
|
423
451
|
end
|
424
452
|
|
425
453
|
# @since 0.2.0
|
@@ -442,5 +470,16 @@ module Lotus
|
|
442
470
|
def default_host
|
443
471
|
environment == DEFAULT_ENV ? DEFAULT_HOST : LISTEN_ALL_HOST
|
444
472
|
end
|
473
|
+
|
474
|
+
# @since 0.6.0
|
475
|
+
# @api private
|
476
|
+
def rack_env
|
477
|
+
case ENV[RACK_ENV]
|
478
|
+
when RACK_ENV_DEPLOYMENT
|
479
|
+
PRODUCTION_ENV
|
480
|
+
else
|
481
|
+
ENV[RACK_ENV]
|
482
|
+
end
|
483
|
+
end
|
445
484
|
end
|
446
485
|
end
|