hanami 1.3.1 → 2.0.0.alpha2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (168) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +110 -6
  3. data/FEATURES.md +9 -1
  4. data/LICENSE.md +1 -1
  5. data/README.md +4 -5
  6. data/hanami.gemspec +26 -30
  7. data/lib/hanami.rb +40 -243
  8. data/lib/hanami/application.rb +338 -174
  9. data/lib/hanami/application/autoloader/inflector_adapter.rb +22 -0
  10. data/lib/hanami/application/container/boot/inflector.rb +7 -0
  11. data/lib/hanami/application/container/boot/logger.rb +8 -0
  12. data/lib/hanami/application/container/boot/rack_logger.rb +19 -0
  13. data/lib/hanami/application/container/boot/rack_monitor.rb +12 -0
  14. data/lib/hanami/application/container/boot/settings.rb +7 -0
  15. data/lib/hanami/application/router.rb +59 -0
  16. data/lib/hanami/application/routing/middleware/stack.rb +89 -0
  17. data/lib/hanami/application/routing/resolver.rb +82 -0
  18. data/lib/hanami/application/routing/resolver/node.rb +50 -0
  19. data/lib/hanami/application/routing/resolver/trie.rb +59 -0
  20. data/lib/hanami/application/settings.rb +23 -0
  21. data/lib/hanami/application/settings/definition.rb +26 -0
  22. data/lib/hanami/application/settings/loader.rb +97 -0
  23. data/lib/hanami/application/settings/struct.rb +65 -0
  24. data/lib/hanami/boot.rb +5 -0
  25. data/lib/hanami/cli/application/cli.rb +40 -0
  26. data/lib/hanami/cli/application/command.rb +47 -0
  27. data/lib/hanami/cli/application/commands.rb +16 -0
  28. data/lib/hanami/cli/application/commands/console.rb +81 -0
  29. data/lib/hanami/cli/base_command.rb +48 -0
  30. data/lib/hanami/cli/commands.rb +6 -42
  31. data/lib/hanami/cli/commands/command.rb +20 -30
  32. data/lib/hanami/cli/commands/server.rb +63 -14
  33. data/lib/hanami/configuration.rb +248 -190
  34. data/lib/hanami/configuration/middleware.rb +8 -28
  35. data/lib/hanami/configuration/router.rb +50 -0
  36. data/lib/hanami/configuration/sessions.rb +50 -0
  37. data/lib/hanami/init.rb +5 -0
  38. data/lib/hanami/server.rb +5 -69
  39. data/lib/hanami/setup.rb +8 -2
  40. data/lib/hanami/slice.rb +138 -0
  41. data/lib/hanami/version.rb +3 -1
  42. data/lib/hanami/web/rack_logger.rb +96 -0
  43. metadata +84 -228
  44. data/bin/hanami +0 -6
  45. data/lib/hanami/action/csrf_protection.rb +0 -211
  46. data/lib/hanami/action/routing_helpers.rb +0 -40
  47. data/lib/hanami/app.rb +0 -96
  48. data/lib/hanami/application_configuration.rb +0 -1495
  49. data/lib/hanami/application_name.rb +0 -108
  50. data/lib/hanami/application_namespace.rb +0 -14
  51. data/lib/hanami/assets/asset.rb +0 -72
  52. data/lib/hanami/assets/static.rb +0 -102
  53. data/lib/hanami/cli/commands/assets.rb +0 -16
  54. data/lib/hanami/cli/commands/assets/precompile.rb +0 -42
  55. data/lib/hanami/cli/commands/console.rb +0 -95
  56. data/lib/hanami/cli/commands/db.rb +0 -32
  57. data/lib/hanami/cli/commands/db/apply.rb +0 -32
  58. data/lib/hanami/cli/commands/db/console.rb +0 -44
  59. data/lib/hanami/cli/commands/db/create.rb +0 -32
  60. data/lib/hanami/cli/commands/db/drop.rb +0 -32
  61. data/lib/hanami/cli/commands/db/migrate.rb +0 -39
  62. data/lib/hanami/cli/commands/db/prepare.rb +0 -32
  63. data/lib/hanami/cli/commands/db/rollback.rb +0 -59
  64. data/lib/hanami/cli/commands/db/version.rb +0 -32
  65. data/lib/hanami/cli/commands/destroy.rb +0 -26
  66. data/lib/hanami/cli/commands/destroy/action.rb +0 -137
  67. data/lib/hanami/cli/commands/destroy/app.rb +0 -159
  68. data/lib/hanami/cli/commands/destroy/mailer.rb +0 -74
  69. data/lib/hanami/cli/commands/destroy/migration.rb +0 -51
  70. data/lib/hanami/cli/commands/destroy/model.rb +0 -84
  71. data/lib/hanami/cli/commands/generate.rb +0 -28
  72. data/lib/hanami/cli/commands/generate/action.rb +0 -321
  73. data/lib/hanami/cli/commands/generate/action/action.erb +0 -7
  74. data/lib/hanami/cli/commands/generate/action/action_spec.minitest.erb +0 -11
  75. data/lib/hanami/cli/commands/generate/action/action_spec.rspec.erb +0 -9
  76. data/lib/hanami/cli/commands/generate/action/action_without_view.erb +0 -7
  77. data/lib/hanami/cli/commands/generate/action/view.erb +0 -7
  78. data/lib/hanami/cli/commands/generate/action/view_spec.minitest.erb +0 -12
  79. data/lib/hanami/cli/commands/generate/action/view_spec.rspec.erb +0 -10
  80. data/lib/hanami/cli/commands/generate/app.rb +0 -243
  81. data/lib/hanami/cli/commands/generate/app/application.erb +0 -313
  82. data/lib/hanami/cli/commands/generate/app/favicon.ico +0 -0
  83. data/lib/hanami/cli/commands/generate/app/gitkeep.erb +0 -0
  84. data/lib/hanami/cli/commands/generate/app/layout.erb +0 -7
  85. data/lib/hanami/cli/commands/generate/app/layout_spec.minitest.erb +0 -10
  86. data/lib/hanami/cli/commands/generate/app/layout_spec.rspec.erb +0 -10
  87. data/lib/hanami/cli/commands/generate/app/routes.erb +0 -5
  88. data/lib/hanami/cli/commands/generate/app/template.erb.erb +0 -10
  89. data/lib/hanami/cli/commands/generate/app/template.haml.erb +0 -7
  90. data/lib/hanami/cli/commands/generate/app/template.slim.erb +0 -8
  91. data/lib/hanami/cli/commands/generate/mailer.rb +0 -104
  92. data/lib/hanami/cli/commands/generate/mailer/mailer.erb +0 -9
  93. data/lib/hanami/cli/commands/generate/mailer/mailer_spec.minitest.erb +0 -7
  94. data/lib/hanami/cli/commands/generate/mailer/mailer_spec.rspec.erb +0 -5
  95. data/lib/hanami/cli/commands/generate/migration.rb +0 -41
  96. data/lib/hanami/cli/commands/generate/migration/migration.erb +0 -4
  97. data/lib/hanami/cli/commands/generate/model.rb +0 -125
  98. data/lib/hanami/cli/commands/generate/model/entity.erb +0 -2
  99. data/lib/hanami/cli/commands/generate/model/entity_spec.minitest.erb +0 -5
  100. data/lib/hanami/cli/commands/generate/model/entity_spec.rspec.erb +0 -3
  101. data/lib/hanami/cli/commands/generate/model/migration.erb +0 -10
  102. data/lib/hanami/cli/commands/generate/model/repository.erb +0 -5
  103. data/lib/hanami/cli/commands/generate/model/repository_spec.minitest.erb +0 -5
  104. data/lib/hanami/cli/commands/generate/model/repository_spec.rspec.erb +0 -3
  105. data/lib/hanami/cli/commands/generate/secret.rb +0 -48
  106. data/lib/hanami/cli/commands/new.rb +0 -578
  107. data/lib/hanami/cli/commands/new/.env.development.erb +0 -3
  108. data/lib/hanami/cli/commands/new/.env.test.erb +0 -3
  109. data/lib/hanami/cli/commands/new/.gitkeep.erb +0 -0
  110. data/lib/hanami/cli/commands/new/Gemfile.erb +0 -58
  111. data/lib/hanami/cli/commands/new/README.md.erb +0 -33
  112. data/lib/hanami/cli/commands/new/config.ru.erb +0 -3
  113. data/lib/hanami/cli/commands/new/config/boot.erb +0 -2
  114. data/lib/hanami/cli/commands/new/config/environment.erb +0 -49
  115. data/lib/hanami/cli/commands/new/gitignore.erb +0 -2
  116. data/lib/hanami/cli/commands/new/gitignore_with_sqlite.erb +0 -3
  117. data/lib/hanami/cli/commands/new/hanamirc.erb +0 -3
  118. data/lib/hanami/cli/commands/new/lib/project.erb +0 -2
  119. data/lib/hanami/cli/commands/new/minitest/Rakefile.erb +0 -12
  120. data/lib/hanami/cli/commands/new/minitest/features_helper.erb +0 -11
  121. data/lib/hanami/cli/commands/new/minitest/spec_helper.erb +0 -7
  122. data/lib/hanami/cli/commands/new/rspec/Rakefile.erb +0 -9
  123. data/lib/hanami/cli/commands/new/rspec/capybara.erb +0 -8
  124. data/lib/hanami/cli/commands/new/rspec/features_helper.erb +0 -12
  125. data/lib/hanami/cli/commands/new/rspec/rspec.erb +0 -2
  126. data/lib/hanami/cli/commands/new/rspec/spec_helper.erb +0 -103
  127. data/lib/hanami/cli/commands/new/schema.sql.erb +0 -0
  128. data/lib/hanami/cli/commands/project.rb +0 -421
  129. data/lib/hanami/cli/commands/routes.rb +0 -21
  130. data/lib/hanami/cli/commands/templates.rb +0 -31
  131. data/lib/hanami/cli/commands/version.rb +0 -19
  132. data/lib/hanami/common_logger.rb +0 -93
  133. data/lib/hanami/components.rb +0 -156
  134. data/lib/hanami/components/app/assets.rb +0 -59
  135. data/lib/hanami/components/app/controller.rb +0 -74
  136. data/lib/hanami/components/app/routes.rb +0 -59
  137. data/lib/hanami/components/app/view.rb +0 -44
  138. data/lib/hanami/components/component.rb +0 -182
  139. data/lib/hanami/components/components.rb +0 -479
  140. data/lib/hanami/components/routes_inspector.rb +0 -72
  141. data/lib/hanami/config/cookies.rb +0 -69
  142. data/lib/hanami/config/framework_configuration.rb +0 -43
  143. data/lib/hanami/config/load_paths.rb +0 -46
  144. data/lib/hanami/config/mapper.rb +0 -47
  145. data/lib/hanami/config/routes.rb +0 -20
  146. data/lib/hanami/config/security.rb +0 -110
  147. data/lib/hanami/config/sessions.rb +0 -103
  148. data/lib/hanami/configuration/app.rb +0 -18
  149. data/lib/hanami/early_hints.rb +0 -129
  150. data/lib/hanami/env.rb +0 -69
  151. data/lib/hanami/environment.rb +0 -513
  152. data/lib/hanami/environment_application_configurations.rb +0 -37
  153. data/lib/hanami/frameworks.rb +0 -22
  154. data/lib/hanami/hanamirc.rb +0 -169
  155. data/lib/hanami/mailer/glue.rb +0 -27
  156. data/lib/hanami/middleware_stack.rb +0 -172
  157. data/lib/hanami/rake_helper.rb +0 -78
  158. data/lib/hanami/rake_tasks.rb +0 -2
  159. data/lib/hanami/rendering_policy.rb +0 -95
  160. data/lib/hanami/routes.rb +0 -219
  161. data/lib/hanami/routing/default.rb +0 -32
  162. data/lib/hanami/static.rb +0 -63
  163. data/lib/hanami/templates/default.html.erb +0 -30
  164. data/lib/hanami/templates/welcome.html.erb +0 -52
  165. data/lib/hanami/views/default.rb +0 -37
  166. data/lib/hanami/views/default_template_finder.rb +0 -22
  167. data/lib/hanami/views/null_view.rb +0 -15
  168. data/lib/hanami/welcome.rb +0 -36
@@ -1,37 +0,0 @@
1
- module Hanami
2
- # @api private
3
- class EnvironmentApplicationConfigurations
4
- # @api private
5
- ALL = :all
6
-
7
- # @api private
8
- def initialize
9
- @configurations = Concurrent::Hash.new { |k, v| k[v] = [] }
10
- end
11
-
12
- # @api private
13
- def add(environment, &blk)
14
- env = (environment || ALL).to_sym
15
- configurations[env].push(blk)
16
- end
17
-
18
- # @api private
19
- def each(environment, &blk)
20
- configurations.each do |env, blks|
21
- next unless matching_env?(environment, env)
22
- blks.each(&blk)
23
- end
24
- end
25
-
26
- private
27
-
28
- # @api private
29
- attr_reader :configurations
30
-
31
- # @api private
32
- def matching_env?(environment, env)
33
- environment.to_sym == env ||
34
- env == ALL
35
- end
36
- end
37
- end
@@ -1,22 +0,0 @@
1
- require 'hanami/utils'
2
- require 'hanami/validations'
3
- require 'hanami/router'
4
- require 'hanami/view'
5
- require 'hanami/controller'
6
- require 'hanami/action/glue'
7
- require 'hanami/action/csrf_protection'
8
- require 'hanami/mailer'
9
- require 'hanami/mailer/glue'
10
- require 'hanami/assets'
11
-
12
- Hanami::Controller.configure do
13
- prepare do
14
- include Hanami::Action::Glue
15
- end
16
- end
17
-
18
- Hanami::Controller::MissingSessionError.class_eval do
19
- def initialize(session_method)
20
- super("To use `#{session_method}', please enable sessions for the current app.")
21
- end
22
- end
@@ -1,169 +0,0 @@
1
- require 'pathname'
2
- require 'hanami/utils/hash'
3
-
4
- module Hanami
5
- # Read the .hanamirc file in the root of the application
6
- #
7
- # @since 0.3.0
8
- # @api private
9
- class Hanamirc
10
- # Hanamirc name file
11
- #
12
- # @since 0.3.0
13
- # @api private
14
- #
15
- # @see Hanami::Hanamirc#path_file
16
- FILE_NAME = '.hanamirc'.freeze
17
-
18
- # Project name for writing the hanamirc file
19
- #
20
- # @since 0.8.0
21
- # @api private
22
- #
23
- # @see Hanami::Hanamirc#default_options
24
- PROJECT_NAME = 'project'.freeze
25
-
26
- # Test suite default value
27
- #
28
- # @since 0.3.0
29
- # @api private
30
- #
31
- # @see Hanami::Hanamirc#default_options
32
- DEFAULT_TEST_SUITE = 'rspec'.freeze
33
-
34
- # Test suite key for writing the hanamirc file
35
- #
36
- # @since 0.3.0
37
- # @api private
38
- #
39
- # @see Hanami::Hanamirc#default_options
40
- TEST_KEY = 'test'.freeze
41
-
42
- # Template default value
43
- #
44
- # @since 0.3.0
45
- # @api private
46
- #
47
- # @see Hanami::Hanamirc#default_options
48
- DEFAULT_TEMPLATE = 'erb'.freeze
49
-
50
- # Template key for writing the hanamirc file
51
- #
52
- # @since 0.3.0
53
- # @api private
54
- #
55
- # @see Hanami::Hanamirc#default_options
56
- TEMPLATE_KEY = 'template'.freeze
57
-
58
- # Key/value separator in hanamirc file
59
- #
60
- # @since 0.8.0
61
- # @api private
62
- SEPARATOR = '='.freeze
63
-
64
- # Initialize Hanamirc class with application's root and environment options.
65
- #
66
- # @param root [Pathname] Application's root
67
- #
68
- # @see Hanami::Environment#initialize
69
- def initialize(root)
70
- @root = root
71
- end
72
-
73
- # Read hanamirc file (if exists) and parse it's values or return default.
74
- #
75
- # @return [::Hash] parsed values
76
- #
77
- # @example Default values if file doesn't exist
78
- # Hanami::Hanamirc.new(Pathname.new(Dir.pwd)).options
79
- # # => { test: 'minitest', template: 'erb' }
80
- #
81
- # @example Custom values if file doesn't exist
82
- # options = { test: 'rspec', template: 'slim' }
83
- # Hanami::Hanamirc.new(Pathname.new(Dir.pwd), options).options
84
- # # => { test: 'rspec', template: 'slim' }
85
- def options
86
- @options ||= symbolize(default_options.merge(file_options))
87
- end
88
-
89
- # Default values for writing the hanamirc file
90
- #
91
- # @since 0.5.1
92
- # @api private
93
- #
94
- # @see Hanami::Hanamirc#options
95
- def default_options
96
- @default_options ||= Utils::Hash.symbolize({
97
- PROJECT_NAME => project_name,
98
- TEST_KEY => DEFAULT_TEST_SUITE,
99
- TEMPLATE_KEY => DEFAULT_TEMPLATE
100
- }).freeze
101
- end
102
-
103
- # Check if hanamirc file exists
104
- #
105
- # @since 0.3.0
106
- # @api private
107
- #
108
- # @return [Boolean] hanamirc file's path existing
109
- def exists?
110
- path_file.exist?
111
- end
112
-
113
- private
114
-
115
- # @api private
116
- def symbolize(hash)
117
- Utils::Hash.symbolize(hash)
118
- end
119
-
120
- # Returns options from hanamirc file
121
- #
122
- # @since 0.6.0
123
- # @api private
124
- #
125
- # @return [Hash] hanamirc parsed values
126
- def file_options
127
- symbolize(exists? ? parse_file(path_file) : {})
128
- end
129
-
130
- # Read hanamirc file and parse it's values
131
- #
132
- # @since 0.8.0
133
- # @api private
134
- #
135
- # @return [Hash] hanamirc parsed values
136
- def parse_file(path)
137
- {}.tap do |hash|
138
- File.readlines(path).each do |line|
139
- key, value = line.split(SEPARATOR)
140
- hash[key] = value.strip
141
- end
142
- end
143
- end
144
-
145
- # Return the hanamirc file's path
146
- #
147
- # @since 0.3.0
148
- # @api private
149
- #
150
- # @return [Pathname] hanamirc file's path
151
- #
152
- # @see Hanami::Hanamirc::FILE_NAME
153
- def path_file
154
- @root.join FILE_NAME
155
- end
156
-
157
- # Generates a default project name based on the application directory
158
- #
159
- # @since 0.8.0
160
- # @api private
161
- #
162
- # @return [String] application_name
163
- #
164
- # @see Hanami::Hanamirc::PROJECT_NAME
165
- def project_name
166
- ::File.basename(@root)
167
- end
168
- end
169
- end
@@ -1,27 +0,0 @@
1
- # @api private
2
- module Hanami::Mailer
3
- # @since 0.5.0
4
- # @api private
5
- module Glue
6
- # @since 0.5.0
7
- # @api private
8
- def self.included(configuration)
9
- configuration.class_eval do
10
- alias_method :delivery, :delivery_method
11
- end
12
- end
13
- end
14
-
15
- Configuration.class_eval do
16
- include Glue
17
- end
18
- end
19
-
20
- # @since 0.5.0
21
- # @api private
22
- module Mailers
23
- end
24
-
25
- Hanami::Mailer.configure do
26
- namespace Mailers
27
- end
@@ -1,172 +0,0 @@
1
- require 'rack/builder'
2
- require 'hanami/utils/class'
3
-
4
- module Hanami
5
- # Rack middleware stack for an application
6
- #
7
- # @since 0.1.0
8
- # @api private
9
- class MiddlewareStack
10
- # Instantiate a middleware stack
11
- #
12
- # @param configuration [Hanami::ApplicationConfiguration] the application's configuration
13
- #
14
- # @return [Hanami::MiddlewareStack] the new stack
15
- #
16
- # @since 0.1.0
17
- # @api private
18
- #
19
- # @see Hanami::ApplicationConfiguration
20
- def initialize(configuration)
21
- @stack = []
22
- @configuration = configuration
23
- @builder = Rack::Builder.new
24
- end
25
-
26
- # Load the middleware stack
27
- #
28
- # @return [Hanami::MiddlewareStack] the loaded middleware stack
29
- #
30
- # @since 0.2.0
31
- # @api private
32
- #
33
- # @see http://rdoc.info/gems/rack/Rack/Builder
34
- def load!
35
- load_default_stack
36
- stack.each { |m, args, block| builder.use(load_middleware(m), *args, &block) }
37
- builder.run routes
38
-
39
- self
40
- end
41
-
42
- # Process a request.
43
- # This method makes the middleware stack compatible with the Rack protocol.
44
- #
45
- # @param env [Hash] a Rack env
46
- #
47
- # @return [Array] a serialized Rack response
48
- #
49
- # @since 0.1.0
50
- # @api private
51
- def call(env)
52
- builder.call(env)
53
- end
54
-
55
- # Append a middleware to the stack.
56
- #
57
- # @param middleware [Object] a Rack middleware
58
- # @param args [Array] optional arguments to pass to the Rack middleware
59
- # @param blk [Proc] an optional block to pass to the Rack middleware
60
- #
61
- # @return [Array] the middleware that was added
62
- #
63
- # @since 0.2.0
64
- #
65
- # @see Hanami::MiddlewareStack#prepend
66
- #
67
- # @example
68
- # # apps/web/application.rb
69
- # module Web
70
- # class Application < Hanami::Application
71
- # configure do
72
- # # ...
73
- # use MyRackMiddleware, foo: 'bar'
74
- # end
75
- # end
76
- # end
77
- def use(middleware, *args, &blk)
78
- stack.push [middleware, args, blk]
79
- stack.uniq!
80
- end
81
-
82
- # Prepend a middleware to the stack.
83
- #
84
- # @param middleware [Object] a Rack middleware
85
- # @param args [Array] optional arguments to pass to the Rack middleware
86
- # @param blk [Proc] an optional block to pass to the Rack middleware
87
- #
88
- # @return [Array] the middleware that was added
89
- #
90
- # @since 0.6.0
91
- #
92
- # @see Hanami::MiddlewareStack#use
93
- #
94
- # @example
95
- # # apps/web/application.rb
96
- # module Web
97
- # class Application < Hanami::Application
98
- # configure do
99
- # # ...
100
- # prepend MyRackMiddleware, foo: 'bar'
101
- # end
102
- # end
103
- # end
104
- def prepend(middleware, *args, &blk)
105
- stack.unshift [middleware, args, blk]
106
- stack.uniq!
107
- end
108
-
109
- private
110
-
111
- # @api private
112
- # @since 0.9.0
113
- attr_reader :stack
114
-
115
- # @api private
116
- # @since 0.9.0
117
- attr_reader :builder
118
-
119
- # @api private
120
- # @since 0.9.0
121
- attr_reader :configuration
122
-
123
- # @api private
124
- # @since 0.2.0
125
- def load_middleware(middleware)
126
- case middleware
127
- when String
128
- Utils::Class.load!(middleware)
129
- else
130
- middleware
131
- end
132
- end
133
-
134
- # @api private
135
- # @since 0.9.0
136
- def routes
137
- Components["#{configuration.app_name}.routes"]
138
- end
139
-
140
- # @api private
141
- # @since 0.2.0
142
- def load_default_stack
143
- @default_stack_loaded ||= begin
144
- _load_session_middleware
145
- _load_default_welcome_page
146
-
147
- true
148
- end
149
- end
150
-
151
- # Default welcome page
152
- #
153
- # @api private
154
- # @since 0.2.0
155
- def _load_default_welcome_page
156
- unless Hanami.env?(:test) || routes.defined?
157
- require 'hanami/welcome'
158
- use Hanami::Welcome
159
- end
160
- end
161
-
162
- # Add session middleware
163
- #
164
- # @api private
165
- # @since 0.2.0
166
- def _load_session_middleware
167
- if configuration.sessions.enabled?
168
- prepend(*configuration.sessions.middleware)
169
- end
170
- end
171
- end
172
- end
@@ -1,78 +0,0 @@
1
- require 'rake'
2
-
3
- module Hanami
4
- # Install Rake tasks in projects
5
- #
6
- # @since 0.6.0
7
- # @api private
8
- class RakeHelper
9
- include Rake::DSL
10
-
11
- # @since 0.6.0
12
- # @api private
13
- def self.install_tasks
14
- new.install
15
- end
16
-
17
- # @since 0.6.0
18
- # @api private
19
- #
20
- # rubocop:disable Metrics/MethodLength
21
- def install
22
- desc "Load the full project"
23
- task :environment do
24
- require 'hanami/environment'
25
- Hanami::Environment.new.require_project_environment
26
- Components.resolve('all')
27
- end
28
-
29
- # Ruby ecosystem compatibility
30
- #
31
- # Most of the SaaS automatic tasks are designed after Ruby on Rails.
32
- # They expect the following Rake tasks to be present:
33
- #
34
- # * db:migrate
35
- # * assets:precompile
36
- #
37
- # See https://github.com/heroku/heroku-buildpack-ruby/issues/442
38
- #
39
- # ===
40
- #
41
- # These Rake tasks aren't listed when someone runs `rake -T`, because we
42
- # want to encourage developers to use `hanami` commands.
43
- #
44
- # In order to migrate the database or precompile assets a developer should
45
- # use:
46
- #
47
- # * hanami db migrate
48
- # * hanami assets precompile
49
- #
50
- # This is the preferred way to run Hanami command line tasks.
51
- # Please use them when you're in control of your deployment environment.
52
- #
53
- # If you're not in control and your deployment requires these "standard"
54
- # Rake tasks, they are here to solve this only specific problem.
55
- namespace :db do
56
- task :migrate do
57
- run_hanami_command("db migrate")
58
- end
59
- end
60
-
61
- namespace :assets do
62
- task :precompile do
63
- run_hanami_command("assets precompile")
64
- end
65
- end
66
- end
67
-
68
- private
69
-
70
- # @since 1.1.0
71
- # @api private
72
- def run_hanami_command(command)
73
- require "hanami/cli/commands"
74
- Hanami::CLI.new(Hanami::CLI::Commands).call(arguments: command.split(/[[:space:]]/))
75
- end
76
- # rubocop:enable Metrics/MethodLength
77
- end
78
- end