lotusrb 0.2.1 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (36) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +20 -3
  3. data/FEATURES.md +94 -0
  4. data/README.md +73 -22
  5. data/lib/lotus/cli.rb +24 -5
  6. data/lib/lotus/commands/db/console.rb +54 -0
  7. data/lib/lotus/commands/db.rb +27 -0
  8. data/lib/lotus/commands/generate.rb +70 -0
  9. data/lib/lotus/config/cookies.rb +47 -0
  10. data/lib/lotus/config/security.rb +58 -0
  11. data/lib/lotus/configuration.rb +65 -24
  12. data/lib/lotus/environment.rb +3 -1
  13. data/lib/lotus/generators/action/action.rb.tt +8 -0
  14. data/lib/lotus/generators/action/action_spec.minitest.tt +12 -0
  15. data/lib/lotus/generators/action/action_spec.rspec.tt +12 -0
  16. data/lib/lotus/generators/action/template.tt +0 -0
  17. data/lib/lotus/generators/action/view.rb.tt +5 -0
  18. data/lib/lotus/generators/action/view_spec.minitest.tt +12 -0
  19. data/lib/lotus/generators/action/view_spec.rspec.tt +12 -0
  20. data/lib/lotus/generators/action.rb +149 -0
  21. data/lib/lotus/generators/application/container/Gemfile.tt +7 -2
  22. data/lib/lotus/generators/application/container/config/.env.development.tt +1 -1
  23. data/lib/lotus/generators/application/container/config/.env.test.tt +1 -1
  24. data/lib/lotus/generators/application/container/gitignore.tt +2 -0
  25. data/lib/lotus/generators/application/container/lib/app_name.rb.tt +4 -2
  26. data/lib/lotus/generators/application/container/lotusrc.tt +3 -0
  27. data/lib/lotus/generators/application/container.rb +78 -8
  28. data/lib/lotus/generators/slice/application.rb.tt +63 -11
  29. data/lib/lotus/generators/slice/config/mapping.rb.tt +4 -1
  30. data/lib/lotus/loader.rb +10 -2
  31. data/lib/lotus/lotusrc.rb +146 -0
  32. data/lib/lotus/middleware.rb +2 -2
  33. data/lib/lotus/routes.rb +62 -6
  34. data/lib/lotus/version.rb +1 -1
  35. data/lotusrb.gemspec +6 -5
  36. metadata +41 -28
@@ -7,6 +7,8 @@ require 'lotus/config/routes'
7
7
  require 'lotus/config/mapping'
8
8
  require 'lotus/config/sessions'
9
9
  require 'lotus/config/configure'
10
+ require 'lotus/config/security'
11
+ require 'lotus/config/cookies'
10
12
 
11
13
  module Lotus
12
14
  # Configuration for a Lotus application
@@ -35,7 +37,6 @@ module Lotus
35
37
  # set a path for the specific environment.
36
38
  #
37
39
  # @param environment [Symbol,nil] the configuration environment name
38
- # @param environment [String,nil] the configuration path of a specific environment
39
40
  # @param blk [Proc] the configuration block
40
41
  #
41
42
  # @return [self]
@@ -69,6 +70,44 @@ module Lotus
69
70
  self
70
71
  end
71
72
 
73
+ # Returns the security policy
74
+ #
75
+ # @return [Lotus::Config::Security]
76
+ #
77
+ # @since 0.3.0
78
+ #
79
+ # @see Lotus::Config::Security
80
+ #
81
+ # @example Getting values
82
+ # require 'lotus'
83
+ #
84
+ # module Bookshelf
85
+ # class Application < Lotus::Application
86
+ # configure do
87
+ # security.x_frame_options "ALLOW ALL"
88
+ # security.content_security_policy "script-src 'self' https://apis.example.com"
89
+ # end
90
+ # end
91
+ # end
92
+ #
93
+ # Bookshelf::Application.configuration.security.x_frame_options # => "ALLOW ALL"
94
+ # Bookshelf::Application.configuration.security.content_security_policy # => "script-src 'self' https://apis.example.com"
95
+ #
96
+ # @example Setting values
97
+ # require 'lotus'
98
+ #
99
+ # module Bookshelf
100
+ # class Application < Lotus::Application
101
+ # configure do
102
+ # security.x_frame_options "ALLOW ALL"
103
+ # security.content_security_policy "script-src 'self' https://apis.example.com"
104
+ # end
105
+ # end
106
+ # end
107
+ def security
108
+ @security ||= Config::Security.new
109
+ end
110
+
72
111
  # The root of the application
73
112
  #
74
113
  # By default it returns the current directory, for this reason, **all the
@@ -426,13 +465,14 @@ module Lotus
426
465
  # an argument, it will set the corresponding instance variable. When
427
466
  # called without, it will return the already set value, or the default.
428
467
  #
429
- # @overload cookies(value)
430
- # Sets the given value.
468
+ # @overload cookies(value, options)
469
+ # Sets the given value with their options.
431
470
  # @param value [TrueClass, FalseClass]
471
+ # @param options [Hash]
432
472
  #
433
473
  # @overload cookies
434
474
  # Gets the value.
435
- # @return [TrueClass, FalseClass]
475
+ # @return [Lotus::Config::Cookies]
436
476
  #
437
477
  # @example Getting the value
438
478
  # require 'lotus'
@@ -443,7 +483,7 @@ module Lotus
443
483
  # end
444
484
  #
445
485
  # Bookshelf::Application.configuration.cookies
446
- # # => false
486
+ # # => #<Lotus::Config::Cookies:0x0000000329f880 @enabled=false, @default_options={:httponly=>true}>
447
487
  #
448
488
  # @example Setting the value
449
489
  # require 'lotus'
@@ -451,13 +491,13 @@ module Lotus
451
491
  # module Bookshelf
452
492
  # class Application < Lotus::Application
453
493
  # configure do
454
- # cookies true
494
+ # cookies true, { domain: 'lotusrb.org' }
455
495
  # end
456
496
  # end
457
497
  # end
458
498
  #
459
499
  # Bookshelf::Application.configuration.cookies
460
- # # => true
500
+ # # => #<Lotus::Config::Cookies:0x0000000329f880 @enabled=true, @default_options={:domain=>'lotusrb.org', :httponly=>true}>
461
501
  #
462
502
  # @example Setting a new value after one is set.
463
503
  # require 'lotus'
@@ -472,13 +512,13 @@ module Lotus
472
512
  # end
473
513
  #
474
514
  # Bookshelf::Application.configuration.cookies
475
- # # => true
515
+ # # => #<Lotus::Config::Cookies:0x0000000329f880 @enabled=true, @default_options={:httponly=>true}>
476
516
  #
477
- def cookies(value = nil)
517
+ def cookies(value = nil, options = {})
478
518
  if value.nil?
479
- @cookies || false
519
+ @cookies ||= Config::Cookies.new
480
520
  else
481
- @cookies = value
521
+ @cookies = Config::Cookies.new(value, options)
482
522
  end
483
523
  end
484
524
 
@@ -1134,14 +1174,15 @@ module Lotus
1134
1174
  # setting helps to understand the namespace where to find applications'
1135
1175
  # controllers and actions.
1136
1176
  #
1137
- # By default this equals to `"Controllers::%{controller}::%{action}"`
1177
+ # By default this equals to <tt>"Controllers::%{controller}::%{action}"</tt>
1138
1178
  # That means controllers must be structured like this:
1139
- # `Bookshelf::Controllers::Dashboard::Index`, where `Bookshelf` is the
1140
- # application module, `Controllers` is the first value specified in the
1141
- # pattern, `Dashboard` the controller and `Index` the action.
1179
+ # <tt>Bookshelf::Controllers::Dashboard::Index</tt>, where <tt>Bookshelf</tt>
1180
+ # is the application module, <tt>Controllers</tt> is the first value
1181
+ # specified in the pattern, <tt>Dashboard</tt> the controller and
1182
+ # <tt>Index</tt> the action.
1142
1183
  #
1143
- # This pattern MUST always contain `"%{controller}"` and `%{action}`.
1144
- # This pattern SHOULD be used accordingly to `#view_pattern` value.
1184
+ # This pattern MUST always contain <tt>"%{controller}"</tt> and <tt>%{action}</tt>.
1185
+ # This pattern SHOULD be used accordingly to <tt>#view_pattern</tt> value.
1145
1186
  #
1146
1187
  # This is part of a DSL, for this reason when this method is called with
1147
1188
  # an argument, it will set the corresponding instance variable. When
@@ -1267,15 +1308,15 @@ module Lotus
1267
1308
  # setting helps to understand the namespace where to find applications'
1268
1309
  # views:.
1269
1310
  #
1270
- # By default this equals to `"Views::%{controller}::%{action}"`
1311
+ # By default this equals to <tt>"Views::%{controller}::%{action}"</tt>
1271
1312
  # That means views must be structured like this:
1272
- # `Bookshelf::Views::Dashboard::Index`, where `Bookshelf` is the
1273
- # application module, `Views` is the first value specified in the
1274
- # pattern, `Dashboard` a module corresponding to the controller name
1275
- # and `Index` the view, corresponding to the action name.
1313
+ # <tt>Bookshelf::Views::Dashboard::Index</tt>, where <tt>Bookshelf</tt> is
1314
+ # the application module, <tt>Views</tt> is the first value specified in the
1315
+ # pattern, <tt>Dashboard</tt> a module corresponding to the controller name
1316
+ # and <tt>Index</tt> the view, corresponding to the action name.
1276
1317
  #
1277
- # This pattern MUST always contain `"%{controller}"` and `%{action}`.
1278
- # This pattern SHOULD be used accordingly to `#controller_pattern` value.
1318
+ # This pattern MUST always contain <tt>"%{controller}"</tt> and <tt>%{action}</tt>.
1319
+ # This pattern SHOULD be used accordingly to <tt>#controller_pattern</tt> value.
1279
1320
  #
1280
1321
  # This is part of a DSL, for this reason when this method is called with
1281
1322
  # an argument, it will set the corresponding instance variable. When
@@ -2,6 +2,7 @@ require 'thread'
2
2
  require 'pathname'
3
3
  require 'dotenv'
4
4
  require 'lotus/utils/hash'
5
+ require 'lotus/lotusrc'
5
6
 
6
7
  module Lotus
7
8
  # Define and expose information about the Lotus environment.
@@ -155,7 +156,8 @@ module Lotus
155
156
  # # the one defined in the parent (eg `FOO` is overwritten). All the
156
157
  # # other settings (eg `XYZ`) will be left untouched.
157
158
  def initialize(options = {})
158
- @options = Utils::Hash.new(options).symbolize!.freeze
159
+ @options = Lotus::Lotusrc.new(root).read
160
+ @options.merge! Utils::Hash.new(options).symbolize!
159
161
  @mutex = Mutex.new
160
162
  @mutex.synchronize { set_env_vars! }
161
163
  end
@@ -0,0 +1,8 @@
1
+ module <%= config[:app] %>::Controllers::<%= config[:controller] %>
2
+ class <%= config[:action] %>
3
+ include <%= config[:app] %>::Action
4
+
5
+ def call(params)
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,12 @@
1
+ require 'spec_helper'
2
+ require_relative '../../../../<%= config[:action_path] %>'
3
+
4
+ describe <%= config[:app] %>::Controllers::<%= config[:controller] %>::<%= config[:action] %> do
5
+ let(:action) { <%= config[:app] %>::Controllers::<%= config[:controller] %>::<%= config[:action] %>.new }
6
+ let(:params) { Hash[] }
7
+
8
+ it "is successful" do
9
+ response = action.call(params)
10
+ response[0].must_equal 200
11
+ end
12
+ end
@@ -0,0 +1,12 @@
1
+ require 'spec_helper'
2
+ require_relative '../../../../<%= config[:action_path] %>'
3
+
4
+ describe <%= config[:app] %>::Controllers::<%= config[:controller] %>::<%= config[:action] %> do
5
+ let(:action) { <%= config[:app] %>::Controllers::<%= config[:controller] %>::<%= config[:action] %>.new }
6
+ let(:params) { Hash[] }
7
+
8
+ it "is successful" do
9
+ response = action.call(params)
10
+ expect(response[0]).to eq 200
11
+ end
12
+ end
File without changes
@@ -0,0 +1,5 @@
1
+ module <%= config[:app] %>::Views::<%= config[:controller] %>
2
+ class <%= config[:action] %>
3
+ include <%= config[:app] %>::View
4
+ end
5
+ end
@@ -0,0 +1,12 @@
1
+ require 'spec_helper'
2
+ require_relative '../../../../<%= config[:view_path] %>'
3
+
4
+ describe <%= config[:app] %>::Views::<%= config[:controller] %>::<%= config[:action] %> do
5
+ let(:exposures) { Hash[foo: 'bar'] }
6
+ let(:template) { Lotus::View::Template.new('<%= config[:template_path] %>') }
7
+ let(:view) { <%= config[:app] %>::Views::<%= config[:controller] %>::<%= config[:action] %>.new(template, exposures) }
8
+
9
+ it "exposes #foo" do
10
+ view.foo.must_equal exposures.fetch(:foo)
11
+ end
12
+ end
@@ -0,0 +1,12 @@
1
+ require 'spec_helper'
2
+ require_relative '../../../../<%= config[:view_path] %>'
3
+
4
+ describe <%= config[:app] %>::Views::<%= config[:controller] %>::<%= config[:action] %> do
5
+ let(:exposures) { Hash[foo: 'bar'] }
6
+ let(:template) { Lotus::View::Template.new('<%= config[:template_path] %>') }
7
+ let(:view) { <%= config[:app] %>::Views::<%= config[:controller] %>::<%= config[:action] %>.new(template, exposures) }
8
+
9
+ it "exposes #foo" do
10
+ expect(view.foo).to eq exposures.fetch(:foo)
11
+ end
12
+ end
@@ -0,0 +1,149 @@
1
+ require 'lotus/generators/abstract'
2
+ require 'lotus/utils/string'
3
+
4
+ module Lotus
5
+ module Generators
6
+ # @since 0.3.0
7
+ # @api private
8
+ class Action < Abstract
9
+ # @since 0.3.0
10
+ # @api private
11
+ ACTION_SEPARATOR = /\/|\#/
12
+
13
+ # @since 0.3.0
14
+ # @api private
15
+ SUFFIX = '.rb'.freeze
16
+
17
+ # @since 0.3.0
18
+ # @api private
19
+ TEMPLATE_SUFFIX = '.html.'.freeze
20
+
21
+ # @since 0.3.0
22
+ # @api private
23
+ DEFAULT_TEMPLATE = 'erb'.freeze
24
+
25
+ # @since 0.3.0
26
+ # @api private
27
+ def initialize(command)
28
+ super
29
+
30
+ @controller, @action = name.split(ACTION_SEPARATOR)
31
+ @controller_name = Utils::String.new(@controller).classify
32
+ @action_name = Utils::String.new(@action).classify
33
+
34
+ cli.class.source_root(source)
35
+ end
36
+
37
+ # @since 0.3.0
38
+ # @api private
39
+ def start
40
+ assert_existing_app!
41
+
42
+ opts = {
43
+ app: app,
44
+ controller: @controller_name,
45
+ action: @action_name,
46
+ action_path: _action_path_without_suffix,
47
+ view_path: _view_path_without_suffix,
48
+ template_path: _template_path,
49
+ }
50
+
51
+ templates = {
52
+ 'action.rb.tt' => _action_path,
53
+ 'view.rb.tt' => _view_path,
54
+ 'template.tt' => _template_path
55
+ }
56
+
57
+ case options[:test]
58
+ when 'rspec'
59
+ templates.merge!({
60
+ 'action_spec.rspec.tt' => _action_spec_path,
61
+ 'view_spec.rspec.tt' => _view_spec_path,
62
+ })
63
+ else
64
+ templates.merge!({
65
+ 'action_spec.minitest.tt' => _action_spec_path,
66
+ 'view_spec.minitest.tt' => _view_spec_path,
67
+ })
68
+ end
69
+
70
+ generate_route
71
+
72
+ templates.each do |src, dst|
73
+ cli.template(source.join(src), target.join(dst), opts)
74
+ end
75
+ end
76
+
77
+ private
78
+ # @since 0.3.0
79
+ # @api private
80
+ def assert_existing_app!
81
+ unless target.join(app_root).exist?
82
+ raise Lotus::Commands::Generate::Error.new("Unknown app: `#{ app_name }'")
83
+ end
84
+ end
85
+
86
+ # @since 0.3.0
87
+ # @api private
88
+ def generate_route
89
+ path = target.join(_routes_path)
90
+ path.dirname.mkpath
91
+
92
+ FileUtils.touch(path)
93
+
94
+ # Insert at the top of the file
95
+ cli.insert_into_file _routes_path, before: /\A(.*)/ do
96
+ "get '/#{ @controller }', to: '#{ name }'\n"
97
+ end
98
+ end
99
+
100
+ # @since 0.3.0
101
+ # @api private
102
+ def _routes_path
103
+ app_root.join("config", "routes#{ SUFFIX }")
104
+ end
105
+
106
+ # @since 0.3.0
107
+ # @api private
108
+ def _action_path
109
+ _action_path_without_suffix.to_s + SUFFIX
110
+ end
111
+
112
+ # @since 0.3.0
113
+ # @api private
114
+ def _view_path
115
+ _view_path_without_suffix.to_s + SUFFIX
116
+ end
117
+
118
+ # @since 0.3.0
119
+ # @api private
120
+ def _action_path_without_suffix
121
+ app_root.join("controllers", @controller, "#{ @action }")
122
+ end
123
+
124
+ # @since 0.3.0
125
+ # @api private
126
+ def _view_path_without_suffix
127
+ app_root.join("views", @controller, "#{ @action }")
128
+ end
129
+
130
+ # @since 0.3.0
131
+ # @api private
132
+ def _template_path
133
+ app_root.join("templates", @controller, "#{ @action }#{ TEMPLATE_SUFFIX }#{ options.fetch(:template) { DEFAULT_TEMPLATE } }")
134
+ end
135
+
136
+ # @since 0.3.0
137
+ # @api private
138
+ def _action_spec_path
139
+ spec_root.join(app_name, 'controllers', @controller, "#{ @action }_spec#{ SUFFIX }")
140
+ end
141
+
142
+ # @since 0.3.0
143
+ # @api private
144
+ def _view_spec_path
145
+ spec_root.join(app_name, 'views', @controller, "#{ @action }_spec#{ SUFFIX }")
146
+ end
147
+ end
148
+ end
149
+ end
@@ -7,13 +7,18 @@ gem 'rake'
7
7
  gem 'lotus-utils', require: false, github: 'lotus/utils'
8
8
  gem 'lotus-router', require: false, github: 'lotus/router'
9
9
  gem 'lotus-validations', require: false, github: 'lotus/validations'
10
+ gem 'lotus-helpers', require: false, github: 'lotus/helpers'
10
11
  gem 'lotus-controller', require: false, github: 'lotus/controller'
11
12
  gem 'lotus-view', require: false, github: 'lotus/view'
12
13
  gem 'lotus-model', require: false, github: 'lotus/model'
13
14
  gem 'lotusrb', github: 'lotus/lotus'
14
15
  <%- else -%>
15
- gem 'lotusrb', '<%= Lotus::VERSION %>'
16
- gem 'lotus-model', '<%= config[:lotus_model_version] %>'
16
+ gem 'lotusrb', '<%= Lotus::VERSION %>'
17
+ gem 'lotus-model', '<%= config[:lotus_model_version] %>'
18
+ <%- end -%>
19
+
20
+ <%- if config[:database_config][:gem] %>
21
+ gem '<%= config[:database_config][:gem] %>'
17
22
  <%- end -%>
18
23
 
19
24
  group :test do
@@ -1,2 +1,2 @@
1
1
  # Define ENV variables for development environment
2
- <%= config[:app_name].to_env_s %>_DATABASE_URL="file:///db/<%= config[:app_name] %>_development"
2
+ <%= config[:app_name].to_env_s %>_DATABASE_URL="<%= config[:database_config][:uri][:development] %>"
@@ -1,2 +1,2 @@
1
1
  # Define ENV variables for test environment
2
- <%= config[:app_name].to_env_s %>_DATABASE_URL="file:///db/<%= config[:app_name] %>_test"
2
+ <%= config[:app_name].to_env_s %>_DATABASE_URL="<%= config[:database_config][:uri][:test] %>"
@@ -0,0 +1,2 @@
1
+ /db/<%= config[:app_name] %>_development
2
+ /db/<%= config[:app_name] %>_test
@@ -10,15 +10,17 @@ Lotus::Model.configure do
10
10
  # adapter type: :memory, uri: 'memory://localhost/<%= config[:app_name] %>_development'
11
11
  #
12
12
  # * SQL adapter
13
- # adapter type: :sql, uri: 'sqlite://db/<%= config[:app_name] %>_development.db'
13
+ # adapter type: :sql, uri: 'sqlite://db/<%= config[:app_name] %>_development.sqlite3'
14
14
  # adapter type: :sql, uri: 'postgres://localhost/<%= config[:app_name] %>_development'
15
15
  # adapter type: :sql, uri: 'mysql://localhost/<%= config[:app_name] %>_development'
16
16
  #
17
- adapter type: :file_system, uri: ENV['<%= config[:app_name].to_env_s %>_DATABASE_URL']
17
+ adapter type: :<%= config[:database_config][:type] %>, uri: ENV['<%= config[:app_name].to_env_s %>_DATABASE_URL']
18
18
 
19
19
  ##
20
20
  # Database mapping
21
21
  #
22
+ # Intended for specifying application wide mappings.
23
+ #
22
24
  # You can specify mapping file to load with:
23
25
  #
24
26
  # mapping "#{__dir__}/config/mapping"
@@ -0,0 +1,3 @@
1
+ architecture=container
2
+ test=<%= config[:test] %>
3
+ template=erb
@@ -1,3 +1,4 @@
1
+ require 'shellwords'
1
2
  require 'lotus/generators/abstract'
2
3
  require 'lotus/generators/slice'
3
4
 
@@ -8,10 +9,11 @@ module Lotus
8
9
  def initialize(command)
9
10
  super
10
11
 
11
- @slice_generator = Slice.new(command)
12
- @lotus_head = options.fetch(:lotus_head)
13
- @test = options[:test]
14
- @lotus_model_version = '~> 0.2'
12
+ @slice_generator = Slice.new(command)
13
+ @lotus_head = options.fetch(:lotus_head)
14
+ @test = options[:test]
15
+ @database = options[:database]
16
+ @lotus_model_version = '~> 0.3'
15
17
 
16
18
  cli.class.source_root(source)
17
19
  end
@@ -19,13 +21,16 @@ module Lotus
19
21
  def start
20
22
 
21
23
  opts = {
22
- app_name: app_name,
23
- lotus_head: @lotus_head,
24
- test: @test,
25
- lotus_model_version: @lotus_model_version
24
+ app_name: app_name,
25
+ lotus_head: @lotus_head,
26
+ test: @test,
27
+ database: @database,
28
+ database_config: database_config,
29
+ lotus_model_version: @lotus_model_version,
26
30
  }
27
31
 
28
32
  templates = {
33
+ 'lotusrc.tt' => '.lotusrc',
29
34
  'Gemfile.tt' => 'Gemfile',
30
35
  'config.ru.tt' => 'config.ru',
31
36
  'config/environment.rb.tt' => 'config/environment.rb',
@@ -74,8 +79,73 @@ module Lotus
74
79
  cli.template(source.join(gitkeep), target.join(dir, gitkeep), opts)
75
80
  end
76
81
 
82
+ unless git_dir_present?
83
+ cli.template(source.join('gitignore.tt'), target.join('.gitignore'), opts)
84
+ cli.run("git init #{Shellwords.escape(target)}", capture: true)
85
+ end
86
+
77
87
  @slice_generator.start
78
88
  end
89
+
90
+ private
91
+
92
+ def git_dir_present?
93
+ File.directory?(source.join('.git'))
94
+ end
95
+
96
+ def database_config
97
+ {
98
+ gem: database_gem,
99
+ uri: database_uri,
100
+ type: database_type
101
+ }
102
+ end
103
+
104
+ def database_gem
105
+ {
106
+ 'mysql' => 'mysql',
107
+ 'mysql2' => 'mysql2',
108
+ 'postgresql' => 'pg',
109
+ 'postgres' => 'pg',
110
+ 'sqlite' => 'sqlite3',
111
+ 'sqlite3' => 'sqlite3'
112
+ }[@database]
113
+ end
114
+
115
+ def database_type
116
+ case @database
117
+ when 'mysql', 'mysql2', 'postgresql', 'postgres', 'sqlite', 'sqlite3'
118
+ :sql
119
+ when 'filesystem'
120
+ :file_system
121
+ when 'memory'
122
+ :memory
123
+ end
124
+ end
125
+
126
+ def database_uri
127
+ {
128
+ development: "#{database_base_uri}_development",
129
+ test: "#{database_base_uri}_test"
130
+ }
131
+ end
132
+
133
+ def database_base_uri
134
+ case @database
135
+ when 'mysql'
136
+ "mysql://localhost/#{app_name}"
137
+ when 'mysql2'
138
+ "mysql2://localhost/#{app_name}"
139
+ when 'postgresql', 'postgres'
140
+ "postgres://localhost/#{app_name}"
141
+ when 'sqlite', 'sqlite3'
142
+ "sqlite://db/#{Shellwords.escape(app_name)}"
143
+ when 'memory'
144
+ "memory://localhost/#{app_name}"
145
+ else
146
+ "file:///db/#{app_name}"
147
+ end
148
+ end
79
149
  end
80
150
  end
81
151
  end