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,578 +0,0 @@
1
- require "hanami/cli/commands/generate/app"
2
-
3
- module Hanami
4
- # Hanami CLI
5
- #
6
- # @since 1.1.0
7
- class CLI
8
- module Commands
9
- # @since 1.1.0
10
- # @api private
11
- class New < Command # rubocop:disable Metrics/ClassLength
12
- # @since 1.1.0
13
- # @api private
14
- class DatabaseConfig
15
- # @since 1.1.0
16
- # @api private
17
- SUPPORTED_ENGINES = {
18
- 'mysql' => { type: :sql, mri: 'mysql2', jruby: 'jdbc-mysql' },
19
- 'mysql2' => { type: :sql, mri: 'mysql2', jruby: 'jdbc-mysql' },
20
- 'postgresql' => { type: :sql, mri: 'pg', jruby: 'jdbc-postgres' },
21
- 'postgres' => { type: :sql, mri: 'pg', jruby: 'jdbc-postgres' },
22
- 'sqlite' => { type: :sql, mri: 'sqlite3', jruby: 'jdbc-sqlite3' },
23
- 'sqlite3' => { type: :sql, mri: 'sqlite3', jruby: 'jdbc-sqlite3' }
24
- }.freeze
25
-
26
- # @since 1.1.0
27
- # @api private
28
- DEFAULT_ENGINE = 'sqlite'.freeze
29
-
30
- # @since 1.1.0
31
- # @api private
32
- attr_reader :engine
33
-
34
- # @since 1.1.0
35
- # @api private
36
- attr_reader :name
37
-
38
- # @since 1.1.0
39
- # @api private
40
- def initialize(engine, name)
41
- @engine = engine
42
- @name = name
43
-
44
- unless SUPPORTED_ENGINES.key?(engine.to_s) # rubocop:disable Style/GuardClause
45
- warn %(`#{engine}' is not a valid database engine)
46
- exit(1)
47
- end
48
- end
49
-
50
- # @since 1.1.0
51
- # @api private
52
- def to_hash
53
- {
54
- gem: gem,
55
- uri: uri,
56
- type: type
57
- }
58
- end
59
-
60
- # @since 1.1.0
61
- # @api private
62
- def type
63
- SUPPORTED_ENGINES[engine][:type]
64
- end
65
-
66
- # @since 1.1.0
67
- # @api private
68
- def sql?
69
- type == :sql
70
- end
71
-
72
- # @since 1.1.0
73
- # @api private
74
- def sqlite?
75
- %w[sqlite sqlite3].include?(engine)
76
- end
77
-
78
- private
79
-
80
- # @since 1.1.0
81
- # @api private
82
- def platform
83
- Hanami::Utils.jruby? ? :jruby : :mri
84
- end
85
-
86
- # @since 1.1.0
87
- # @api private
88
- def platform_prefix
89
- 'jdbc:'.freeze if Hanami::Utils.jruby?
90
- end
91
-
92
- # @since 1.1.0
93
- # @api private
94
- def uri
95
- {
96
- development: environment_uri(:development),
97
- test: environment_uri(:test)
98
- }
99
- end
100
-
101
- # @since 1.1.0
102
- # @api private
103
- def gem
104
- SUPPORTED_ENGINES[engine][platform]
105
- end
106
-
107
- # @since 1.1.0
108
- # @api private
109
- def base_uri # rubocop:disable Metrics/MethodLength
110
- case engine
111
- when 'mysql', 'mysql2'
112
- if Hanami::Utils.jruby?
113
- "mysql://localhost/#{name}"
114
- else
115
- "mysql2://localhost/#{name}"
116
- end
117
- when 'postgresql', 'postgres'
118
- "postgresql://localhost/#{name}"
119
- when 'sqlite', 'sqlite3'
120
- "sqlite://db/#{Shellwords.escape(name)}"
121
- end
122
- end
123
-
124
- # @since 1.1.0
125
- # @api private
126
- def environment_uri(environment)
127
- case engine
128
- when 'sqlite', 'sqlite3'
129
- "#{platform_prefix}#{base_uri}_#{environment}.sqlite"
130
- else
131
- "#{platform_prefix if sql?}#{base_uri}_#{environment}"
132
- end
133
- end
134
- end
135
-
136
- # @since 1.1.0
137
- # @api private
138
- class TestFramework
139
- # @since 1.1.0
140
- # @api private
141
- RSPEC = 'rspec'.freeze
142
-
143
- # @since 1.1.0
144
- # @api private
145
- MINITEST = 'minitest'.freeze
146
-
147
- # @since 1.1.0
148
- # @api private
149
- VALID_FRAMEWORKS = [RSPEC, MINITEST].freeze
150
-
151
- # @since 1.1.0
152
- # @api private
153
- attr_reader :framework
154
-
155
- # @since 1.1.0
156
- # @api private
157
- def initialize(hanamirc, framework)
158
- @framework = (framework || hanamirc.options.fetch(:test))
159
- assert_framework!
160
- end
161
-
162
- # @since 1.1.0
163
- # @api private
164
- def rspec?
165
- framework == RSPEC
166
- end
167
-
168
- # @since 1.1.0
169
- # @api private
170
- def minitest?
171
- framework == MINITEST
172
- end
173
-
174
- private
175
-
176
- # @since 1.1.0
177
- # @api private
178
- def assert_framework!
179
- unless supported_framework? # rubocop:disable Style/GuardClause
180
- warn "`#{framework}' is not a valid test framework. Please use one of: #{valid_test_frameworks.join(', ')}"
181
- exit(1)
182
- end
183
- end
184
-
185
- # @since 1.1.0
186
- # @api private
187
- def valid_test_frameworks
188
- VALID_FRAMEWORKS.map { |name| "`#{name}'" }
189
- end
190
-
191
- # @since 1.1.0
192
- # @api private
193
- def supported_framework?
194
- VALID_FRAMEWORKS.include?(framework)
195
- end
196
- end
197
-
198
- # @since 1.1.0
199
- # @api private
200
- class TemplateEngine
201
- # @since 1.1.0
202
- # @api private
203
- class UnsupportedTemplateEngine < ::StandardError
204
- end
205
-
206
- # @since 1.1.0
207
- # @api private
208
- SUPPORTED_ENGINES = %w[erb haml slim].freeze
209
-
210
- # @since 1.1.0
211
- # @api private
212
- DEFAULT_ENGINE = 'erb'.freeze
213
-
214
- # @since 1.1.0
215
- # @api private
216
- attr_reader :name
217
-
218
- # @since 1.1.0
219
- # @api private
220
- def initialize(hanamirc, engine)
221
- @name = (engine || hanamirc.options.fetch(:template))
222
- assert_engine!
223
- end
224
-
225
- private
226
-
227
- # @since 1.1.0
228
- # @api private
229
- def assert_engine!
230
- unless supported_engine? # rubocop:disable Style/GuardClause
231
- warn "`#{name}' is not a valid template engine. Please use one of: #{valid_template_engines.join(', ')}"
232
- exit(1)
233
- end
234
- end
235
-
236
- # @since 1.1.0
237
- # @api private
238
- def valid_template_engines
239
- SUPPORTED_ENGINES.map { |name| "`#{name}'" }
240
- end
241
-
242
- # @since 1.1.0
243
- # @api private
244
- def supported_engine?
245
- SUPPORTED_ENGINES.include?(@name.to_s)
246
- end
247
- end
248
-
249
- # @since 1.1.0
250
- # @api private
251
- DEFAULT_APPLICATION_NAME = 'web'.freeze
252
-
253
- # @since 1.1.0
254
- # @api private
255
- DEFAULT_APPLICATION_BASE_URL = '/'.freeze
256
-
257
- # @since 1.1.0
258
- # @api private
259
- attr_reader :target_path
260
-
261
- desc "Generate a new Hanami project"
262
- argument :project, required: true, desc: "The project name"
263
-
264
- option :database, desc: "Database (#{DatabaseConfig::SUPPORTED_ENGINES.keys.join('/')})", default: DatabaseConfig::DEFAULT_ENGINE, aliases: ["-d"]
265
- option :application_name, desc: "App name", default: DEFAULT_APPLICATION_NAME
266
- option :application_base_url, desc: "App base URL", default: DEFAULT_APPLICATION_BASE_URL
267
- option :template, desc: "Template engine (#{TemplateEngine::SUPPORTED_ENGINES.join('/')})", default: TemplateEngine::DEFAULT_ENGINE
268
- option :test, desc: "Project testing framework (#{TestFramework::VALID_FRAMEWORKS.join('/')})", default: Hanami::Hanamirc::DEFAULT_TEST_SUITE
269
- option :hanami_head, desc: "Use Hanami HEAD (true/false)", type: :boolean, default: false
270
-
271
- example [
272
- "bookshelf # Basic usage",
273
- "bookshelf --test=rspec # Setup RSpec testing framework",
274
- "bookshelf --database=postgres # Setup Postgres database",
275
- "bookshelf --template=slim # Setup Slim template engine",
276
- "bookshelf --hanami-head # Use Hanami HEAD"
277
- ]
278
-
279
- # @since 1.1.0
280
- # @api private
281
- #
282
- # rubocop:disable Metrics/AbcSize
283
- # rubocop:disable Metrics/MethodLength
284
- def call(project:, **options)
285
- project_name = project
286
- pwd = ::File.basename(Dir.pwd) if project == "."
287
- project = Utils::String.underscore(pwd || project)
288
- database_config = DatabaseConfig.new(options[:database], project)
289
- test_framework = TestFramework.new(hanamirc, options[:test])
290
- template_engine = TemplateEngine.new(hanamirc, options[:template])
291
- options[:project] = project
292
-
293
- context = Context.new(
294
- project: project,
295
- database: database_config.type,
296
- database_config_hash: database_config.to_hash,
297
- database_config: database_config,
298
- test_framework: test_framework,
299
- template_engine: template_engine,
300
- test: options.fetch(:test),
301
- application_name: options.fetch(:application_name),
302
- application_base_url: options.fetch(:application_base_url),
303
- hanami_head: options.fetch(:hanami_head),
304
- hanami_model_version: '~> 1.3',
305
- code_reloading: code_reloading?,
306
- hanami_version: hanami_version,
307
- project_module: Utils::String.classify(project),
308
- options: options
309
- )
310
-
311
- assert_project_name!(context)
312
-
313
- directory = project_directory(project_name, project)
314
- files.mkdir(directory)
315
-
316
- Dir.chdir(directory) do
317
- generate_application_templates(context)
318
- generate_empty_directories(context)
319
- generate_test_templates(context)
320
- generate_sql_templates(context)
321
- generate_git_templates(context)
322
-
323
- init_git
324
-
325
- generate_app(context)
326
- end
327
- end
328
- # rubocop:enable Metrics/MethodLength
329
- # rubocop:enable Metrics/AbcSize
330
-
331
- private
332
-
333
- # @since 1.1.0
334
- # @api private
335
- def assert_project_name!(context)
336
- if context.project.include?(File::SEPARATOR) # rubocop:disable Style/GuardClause
337
- raise ArgumentError.new("PROJECT must not contain #{File::SEPARATOR}.")
338
- end
339
- end
340
-
341
- # @since 1.1.0
342
- # @api private
343
- #
344
- # rubocop:disable Metrics/AbcSize
345
- # rubocop:disable Metrics/MethodLength
346
- def generate_application_templates(context)
347
- source = templates.find("hanamirc.erb")
348
- destination = project.hanamirc(context)
349
- generate_file(source, destination, context)
350
-
351
- source = templates.find(".env.development.erb")
352
- destination = project.env(context, "development")
353
- generate_file(source, destination, context)
354
-
355
- source = templates.find(".env.test.erb")
356
- destination = project.env(context, "test")
357
- generate_file(source, destination, context)
358
-
359
- source = templates.find("README.md.erb")
360
- destination = project.readme(context)
361
- generate_file(source, destination, context)
362
-
363
- source = templates.find("Gemfile.erb")
364
- destination = project.gemfile(context)
365
- generate_file(source, destination, context)
366
-
367
- source = templates.find("config.ru.erb")
368
- destination = project.config_ru(context)
369
- generate_file(source, destination, context)
370
-
371
- source = templates.find("config", "boot.erb")
372
- destination = project.boot(context)
373
- generate_file(source, destination, context)
374
-
375
- source = templates.find("config", "environment.erb")
376
- destination = project.environment(context)
377
- generate_file(source, destination, context)
378
-
379
- source = templates.find("lib", "project.erb")
380
- destination = project.project(context)
381
- generate_file(source, destination, context)
382
- end
383
- # rubocop:enable Metrics/MethodLength
384
- # rubocop:enable Metrics/AbcSize
385
-
386
- # rubocop:disable Metrics/AbcSize
387
- # rubocop:disable Metrics/MethodLength
388
- def generate_empty_directories(context)
389
- source = templates.find(".gitkeep.erb")
390
-
391
- destination = project.keep(project.public_directory(context))
392
- generate_file(source, destination, context)
393
-
394
- destination = project.keep(project.initializers(context))
395
- generate_file(source, destination, context)
396
-
397
- destination = project.keep(project.entities(context))
398
- generate_file(source, destination, context)
399
-
400
- destination = project.keep(project.repositories(context))
401
- generate_file(source, destination, context)
402
-
403
- destination = project.keep(project.mailers(context))
404
- generate_file(source, destination, context)
405
-
406
- destination = project.keep(project.mailers_templates(context))
407
- generate_file(source, destination, context)
408
-
409
- destination = project.keep(project.entities_spec(context))
410
- generate_file(source, destination, context)
411
-
412
- destination = project.keep(project.repositories_spec(context))
413
- generate_file(source, destination, context)
414
-
415
- destination = project.keep(project.mailers_spec(context))
416
- generate_file(source, destination, context)
417
-
418
- destination = project.keep(project.support_spec(context))
419
- generate_file(source, destination, context)
420
-
421
- if context.database_config.sql? # rubocop:disable Style/ConditionalAssignment
422
- destination = project.keep(project.migrations(context))
423
- else
424
- destination = project.keep(project.db(context))
425
- end
426
-
427
- generate_file(source, destination, context)
428
- end
429
- # rubocop:enable Metrics/MethodLength
430
- # rubocop:enable Metrics/AbcSize
431
-
432
- # rubocop:disable Metrics/AbcSize
433
- # rubocop:disable Metrics/MethodLength
434
- # rubocop:disable Style/IdenticalConditionalBranches
435
- def generate_test_templates(context)
436
- if context.test_framework.rspec?
437
- source = templates.find("rspec", "Rakefile.erb")
438
- destination = project.rakefile(context)
439
- generate_file(source, destination, context)
440
-
441
- source = templates.find("rspec", "rspec.erb")
442
- destination = project.dotrspec(context)
443
- generate_file(source, destination, context)
444
-
445
- source = templates.find("rspec", "spec_helper.erb")
446
- destination = project.spec_helper(context)
447
- generate_file(source, destination, context)
448
-
449
- source = templates.find("rspec", "features_helper.erb")
450
- destination = project.features_helper(context)
451
- generate_file(source, destination, context)
452
-
453
- source = templates.find("rspec", "capybara.erb")
454
- destination = project.capybara(context)
455
- generate_file(source, destination, context)
456
- else # minitest (default)
457
- source = templates.find("minitest", "Rakefile.erb")
458
- destination = project.rakefile(context)
459
- generate_file(source, destination, context)
460
-
461
- source = templates.find("minitest", "spec_helper.erb")
462
- destination = project.spec_helper(context)
463
- generate_file(source, destination, context)
464
-
465
- source = templates.find("minitest", "features_helper.erb")
466
- destination = project.features_helper(context)
467
- generate_file(source, destination, context)
468
- end
469
- end
470
- # rubocop:enable Style/IdenticalConditionalBranches
471
- # rubocop:enable Metrics/MethodLength
472
- # rubocop:enable Metrics/AbcSize
473
-
474
- # @since 1.1.0
475
- # @api private
476
- def generate_sql_templates(context)
477
- return unless context.database_config.sql?
478
-
479
- source = templates.find("schema.sql.erb")
480
- destination = project.db_schema(context)
481
- generate_file(source, destination, context)
482
- end
483
-
484
- # @since 1.1.0
485
- # @api private
486
- def generate_git_templates(context)
487
- return if git_dir_present?
488
-
489
- source = context.database_config.sqlite? ? 'gitignore_with_sqlite.erb' : 'gitignore.erb'
490
- source = templates.find(source)
491
- destination = project.gitignore(context)
492
-
493
- generate_file(source, destination, context)
494
- end
495
-
496
- # @since 1.1.0
497
- # @api private
498
- def target_path
499
- Pathname.pwd
500
- end
501
-
502
- # @since 1.1.0
503
- # @api private
504
- def generate_app(context)
505
- Hanami::CLI::Commands::New::App.new(command_name: "generate app", out: @out, files: @files).call(app: context.application_name, application_base_url: context.application_base_url, **context.options)
506
- end
507
-
508
- # @since 1.1.0
509
- # @api private
510
- def init_git
511
- return if git_dir_present?
512
-
513
- say(:run, "git init . from \".\"")
514
- system("git init #{Shellwords.escape(target)}", out: File::NULL)
515
- end
516
-
517
- # @since 1.1.0
518
- # @api private
519
- def git_dir_present?
520
- files.directory?('.git')
521
- end
522
-
523
- # @since 1.1.0
524
- # @api private
525
- def target
526
- Pathname.new('.')
527
- end
528
-
529
- # @since 1.1.0
530
- # @api private
531
- def hanamirc
532
- @hanamirc ||= Hanamirc.new(Pathname.new('.'))
533
- end
534
-
535
- # @since 1.1.0
536
- # @api private
537
- def project_directory(project_name, project)
538
- return Dir.pwd if project_name == '.'
539
- project
540
- end
541
-
542
- # @since 1.1.0
543
- # @api private
544
- def code_reloading?
545
- !Hanami::Utils.jruby?
546
- end
547
-
548
- # @since 1.1.0
549
- # @api private
550
- def hanami_version
551
- Hanami::Version.gem_requirement
552
- end
553
-
554
- # @since 1.1.0
555
- # @api private
556
- def generate_file(source, destination, context)
557
- super
558
- say(:create, destination)
559
- end
560
-
561
- # @since 1.1.0
562
- # @api private
563
- class App < Commands::Generate::App
564
- requirements.clear
565
-
566
- # @since 1.1.0
567
- # @api private
568
- def initialize(*)
569
- super
570
- @templates = Templates.new(self.class.superclass)
571
- end
572
- end
573
- end
574
- end
575
-
576
- register "new", Commands::New
577
- end
578
- end