hanami 1.3.5 → 2.0.0.alpha1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (147) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +51 -41
  3. data/FEATURES.md +2 -12
  4. data/LICENSE.md +1 -1
  5. data/README.md +5 -8
  6. data/bin/hanami +6 -4
  7. data/hanami.gemspec +24 -28
  8. data/lib/hanami/application.rb +44 -176
  9. data/lib/hanami/boot.rb +6 -0
  10. data/lib/hanami/cli/commands/command.rb +21 -29
  11. data/lib/hanami/cli/commands/server.rb +63 -14
  12. data/lib/hanami/cli/commands.rb +5 -42
  13. data/lib/hanami/configuration/cookies.rb +24 -0
  14. data/lib/hanami/configuration/middleware.rb +8 -28
  15. data/lib/hanami/configuration/security.rb +141 -0
  16. data/lib/hanami/configuration/sessions.rb +50 -0
  17. data/lib/hanami/configuration.rb +181 -191
  18. data/lib/hanami/container.rb +107 -0
  19. data/lib/hanami/frameworks.rb +24 -18
  20. data/lib/hanami/routes.rb +17 -205
  21. data/lib/hanami/server.rb +5 -69
  22. data/lib/hanami/version.rb +3 -1
  23. data/lib/hanami.rb +39 -243
  24. metadata +36 -233
  25. data/lib/hanami/action/csrf_protection.rb +0 -211
  26. data/lib/hanami/action/routing_helpers.rb +0 -40
  27. data/lib/hanami/app.rb +0 -96
  28. data/lib/hanami/application_configuration.rb +0 -1495
  29. data/lib/hanami/application_name.rb +0 -108
  30. data/lib/hanami/application_namespace.rb +0 -14
  31. data/lib/hanami/assets/asset.rb +0 -72
  32. data/lib/hanami/assets/static.rb +0 -102
  33. data/lib/hanami/cli/commands/assets/precompile.rb +0 -42
  34. data/lib/hanami/cli/commands/assets.rb +0 -16
  35. data/lib/hanami/cli/commands/console.rb +0 -95
  36. data/lib/hanami/cli/commands/db/apply.rb +0 -32
  37. data/lib/hanami/cli/commands/db/console.rb +0 -44
  38. data/lib/hanami/cli/commands/db/create.rb +0 -32
  39. data/lib/hanami/cli/commands/db/drop.rb +0 -32
  40. data/lib/hanami/cli/commands/db/migrate.rb +0 -39
  41. data/lib/hanami/cli/commands/db/prepare.rb +0 -32
  42. data/lib/hanami/cli/commands/db/rollback.rb +0 -59
  43. data/lib/hanami/cli/commands/db/version.rb +0 -32
  44. data/lib/hanami/cli/commands/db.rb +0 -32
  45. data/lib/hanami/cli/commands/destroy/action.rb +0 -137
  46. data/lib/hanami/cli/commands/destroy/app.rb +0 -159
  47. data/lib/hanami/cli/commands/destroy/mailer.rb +0 -74
  48. data/lib/hanami/cli/commands/destroy/migration.rb +0 -51
  49. data/lib/hanami/cli/commands/destroy/model.rb +0 -84
  50. data/lib/hanami/cli/commands/destroy.rb +0 -26
  51. data/lib/hanami/cli/commands/generate/action/action.erb +0 -7
  52. data/lib/hanami/cli/commands/generate/action/action_spec.minitest.erb +0 -11
  53. data/lib/hanami/cli/commands/generate/action/action_spec.rspec.erb +0 -9
  54. data/lib/hanami/cli/commands/generate/action/action_without_view.erb +0 -7
  55. data/lib/hanami/cli/commands/generate/action/view.erb +0 -7
  56. data/lib/hanami/cli/commands/generate/action/view_spec.minitest.erb +0 -12
  57. data/lib/hanami/cli/commands/generate/action/view_spec.rspec.erb +0 -10
  58. data/lib/hanami/cli/commands/generate/action.rb +0 -321
  59. data/lib/hanami/cli/commands/generate/app/application.erb +0 -313
  60. data/lib/hanami/cli/commands/generate/app/favicon.ico +0 -0
  61. data/lib/hanami/cli/commands/generate/app/gitkeep.erb +0 -0
  62. data/lib/hanami/cli/commands/generate/app/layout.erb +0 -7
  63. data/lib/hanami/cli/commands/generate/app/layout_spec.minitest.erb +0 -10
  64. data/lib/hanami/cli/commands/generate/app/layout_spec.rspec.erb +0 -10
  65. data/lib/hanami/cli/commands/generate/app/routes.erb +0 -5
  66. data/lib/hanami/cli/commands/generate/app/template.erb.erb +0 -10
  67. data/lib/hanami/cli/commands/generate/app/template.haml.erb +0 -7
  68. data/lib/hanami/cli/commands/generate/app/template.slim.erb +0 -8
  69. data/lib/hanami/cli/commands/generate/app.rb +0 -243
  70. data/lib/hanami/cli/commands/generate/mailer/mailer.erb +0 -9
  71. data/lib/hanami/cli/commands/generate/mailer/mailer_spec.minitest.erb +0 -7
  72. data/lib/hanami/cli/commands/generate/mailer/mailer_spec.rspec.erb +0 -5
  73. data/lib/hanami/cli/commands/generate/mailer.rb +0 -104
  74. data/lib/hanami/cli/commands/generate/migration/migration.erb +0 -4
  75. data/lib/hanami/cli/commands/generate/migration.rb +0 -41
  76. data/lib/hanami/cli/commands/generate/model/entity.erb +0 -2
  77. data/lib/hanami/cli/commands/generate/model/entity_spec.minitest.erb +0 -5
  78. data/lib/hanami/cli/commands/generate/model/entity_spec.rspec.erb +0 -3
  79. data/lib/hanami/cli/commands/generate/model/migration.erb +0 -10
  80. data/lib/hanami/cli/commands/generate/model/repository.erb +0 -5
  81. data/lib/hanami/cli/commands/generate/model/repository_spec.minitest.erb +0 -5
  82. data/lib/hanami/cli/commands/generate/model/repository_spec.rspec.erb +0 -3
  83. data/lib/hanami/cli/commands/generate/model.rb +0 -125
  84. data/lib/hanami/cli/commands/generate/secret.rb +0 -48
  85. data/lib/hanami/cli/commands/generate.rb +0 -28
  86. data/lib/hanami/cli/commands/new/.env.development.erb +0 -3
  87. data/lib/hanami/cli/commands/new/.env.test.erb +0 -3
  88. data/lib/hanami/cli/commands/new/.gitkeep.erb +0 -0
  89. data/lib/hanami/cli/commands/new/Gemfile.erb +0 -57
  90. data/lib/hanami/cli/commands/new/README.md.erb +0 -33
  91. data/lib/hanami/cli/commands/new/config/boot.erb +0 -2
  92. data/lib/hanami/cli/commands/new/config/environment.erb +0 -49
  93. data/lib/hanami/cli/commands/new/config.ru.erb +0 -3
  94. data/lib/hanami/cli/commands/new/gitignore.erb +0 -4
  95. data/lib/hanami/cli/commands/new/gitignore_with_sqlite.erb +0 -5
  96. data/lib/hanami/cli/commands/new/hanamirc.erb +0 -3
  97. data/lib/hanami/cli/commands/new/lib/project.erb +0 -2
  98. data/lib/hanami/cli/commands/new/minitest/Rakefile.erb +0 -12
  99. data/lib/hanami/cli/commands/new/minitest/features_helper.erb +0 -11
  100. data/lib/hanami/cli/commands/new/minitest/spec_helper.erb +0 -7
  101. data/lib/hanami/cli/commands/new/rspec/Rakefile.erb +0 -9
  102. data/lib/hanami/cli/commands/new/rspec/capybara.erb +0 -8
  103. data/lib/hanami/cli/commands/new/rspec/features_helper.erb +0 -12
  104. data/lib/hanami/cli/commands/new/rspec/rspec.erb +0 -2
  105. data/lib/hanami/cli/commands/new/rspec/spec_helper.erb +0 -103
  106. data/lib/hanami/cli/commands/new/schema.sql.erb +0 -0
  107. data/lib/hanami/cli/commands/new.rb +0 -578
  108. data/lib/hanami/cli/commands/project.rb +0 -421
  109. data/lib/hanami/cli/commands/routes.rb +0 -21
  110. data/lib/hanami/cli/commands/templates.rb +0 -31
  111. data/lib/hanami/cli/commands/version.rb +0 -19
  112. data/lib/hanami/common_logger.rb +0 -109
  113. data/lib/hanami/components/app/assets.rb +0 -59
  114. data/lib/hanami/components/app/controller.rb +0 -74
  115. data/lib/hanami/components/app/routes.rb +0 -59
  116. data/lib/hanami/components/app/view.rb +0 -44
  117. data/lib/hanami/components/component.rb +0 -182
  118. data/lib/hanami/components/components.rb +0 -479
  119. data/lib/hanami/components/routes_inspector.rb +0 -72
  120. data/lib/hanami/components.rb +0 -156
  121. data/lib/hanami/config/cookies.rb +0 -69
  122. data/lib/hanami/config/framework_configuration.rb +0 -43
  123. data/lib/hanami/config/load_paths.rb +0 -46
  124. data/lib/hanami/config/mapper.rb +0 -47
  125. data/lib/hanami/config/routes.rb +0 -20
  126. data/lib/hanami/config/security.rb +0 -110
  127. data/lib/hanami/config/sessions.rb +0 -119
  128. data/lib/hanami/configuration/app.rb +0 -21
  129. data/lib/hanami/early_hints.rb +0 -129
  130. data/lib/hanami/env.rb +0 -69
  131. data/lib/hanami/environment.rb +0 -541
  132. data/lib/hanami/environment_application_configurations.rb +0 -37
  133. data/lib/hanami/hanamirc.rb +0 -169
  134. data/lib/hanami/mailer/glue.rb +0 -27
  135. data/lib/hanami/middleware_stack.rb +0 -172
  136. data/lib/hanami/rake_helper.rb +0 -78
  137. data/lib/hanami/rake_tasks.rb +0 -3
  138. data/lib/hanami/rendering_policy.rb +0 -94
  139. data/lib/hanami/routing/default.rb +0 -32
  140. data/lib/hanami/setup.rb +0 -3
  141. data/lib/hanami/static.rb +0 -63
  142. data/lib/hanami/templates/default.html.erb +0 -30
  143. data/lib/hanami/templates/welcome.html.erb +0 -52
  144. data/lib/hanami/views/default.rb +0 -37
  145. data/lib/hanami/views/default_template_finder.rb +0 -22
  146. data/lib/hanami/views/null_view.rb +0 -15
  147. data/lib/hanami/welcome.rb +0 -41
@@ -1,10 +0,0 @@
1
- require "spec_helper"
2
-
3
- RSpec.describe <%= app.classify %>::Views::ApplicationLayout, type: :view do
4
- let(:layout) { <%= app.classify %>::Views::ApplicationLayout.new({ format: :html }, "contents") }
5
- let(:rendered) { layout.render }
6
-
7
- it 'contains application name' do
8
- expect(rendered).to include('<%= app.classify %>')
9
- end
10
- end
@@ -1,5 +0,0 @@
1
- # Configure your routes here
2
- # See: https://guides.hanamirb.org/routing/overview
3
- #
4
- # Example:
5
- # get '/hello', to: ->(env) { [200, {}, ['Hello from Hanami!']] }
@@ -1,10 +0,0 @@
1
- <!DOCTYPE html>
2
- <html>
3
- <head>
4
- <title><%= app.classify %></title>
5
- <%%= favicon %>
6
- </head>
7
- <body>
8
- <%%= yield %>
9
- </body>
10
- </html>
@@ -1,7 +0,0 @@
1
- !!!
2
- %html
3
- %head
4
- %title <%= app.classify %>
5
- = favicon
6
- %body
7
- = yield
@@ -1,8 +0,0 @@
1
- doctype html
2
- html
3
- head
4
- title
5
- | <%= app.classify %>
6
- = favicon
7
- body
8
- = yield
@@ -1,243 +0,0 @@
1
- module Hanami
2
- class CLI
3
- module Commands
4
- module Generate
5
- # @since 1.1.0
6
- # @api private
7
- class App < Command # rubocop:disable Metrics/ClassLength
8
- requires "environment"
9
-
10
- desc "Generate an app"
11
-
12
- argument :app, required: true, desc: "The application name (eg. `web`)"
13
- option :application_base_url, desc: "The app base URL (eg. `/api/v1`)"
14
-
15
- example [
16
- "admin # Generate `admin` app",
17
- "api --application-base-url=/api/v1 # Generate `api` app and mount at `/api/v1`"
18
- ]
19
-
20
- # @since 1.1.0
21
- # @api private
22
- #
23
- # rubocop:disable Metrics/AbcSize
24
- # rubocop:disable Metrics/MethodLength
25
- def call(app:, application_base_url: nil, **options)
26
- app = Utils::String.underscore(app)
27
- template = options.fetch(:template)
28
- base_url = application_base_url || "/#{app}"
29
- context = Context.new(app: app, base_url: base_url, test: options.fetch(:test), template: template, options: options)
30
-
31
- assert_valid_base_url!(context)
32
-
33
- generate_app(context)
34
- generate_routes(context)
35
- generate_layout(context)
36
- generate_template(context)
37
- generate_favicon(context)
38
-
39
- create_controllers_directory(context)
40
- create_assets_images_directory(context)
41
- create_assets_javascripts_directory(context)
42
- create_assets_stylesheets_directory(context)
43
-
44
- create_spec_features_directory(context)
45
- create_spec_controllers_directory(context)
46
- generate_layout_spec(context)
47
-
48
- inject_require_app(context)
49
- inject_mount_app(context)
50
-
51
- append_development_http_session_secret(context)
52
- append_test_http_session_secret(context)
53
- end
54
- # rubocop:enable Metrics/MethodLength
55
- # rubocop:enable Metrics/AbcSize
56
-
57
- private
58
-
59
- # @since 1.1.0
60
- # @api private
61
- def assert_valid_base_url!(context)
62
- if Utils::Blank.blank?(context.base_url) # rubocop:disable Style/GuardClause
63
- warn "`' is not a valid URL"
64
- exit(1)
65
- end
66
- end
67
-
68
- # @since 1.1.0
69
- # @api private
70
- def generate_app(context)
71
- source = templates.find("application.erb")
72
- destination = project.app_application(context)
73
-
74
- generate_file(source, destination, context)
75
- say(:create, destination)
76
- end
77
-
78
- # @since 1.1.0
79
- # @api private
80
- def generate_routes(context)
81
- source = templates.find("routes.erb")
82
- destination = project.app_routes(context)
83
-
84
- generate_file(source, destination, context)
85
- say(:create, destination)
86
- end
87
-
88
- # @since 1.1.0
89
- # @api private
90
- def generate_layout(context)
91
- source = templates.find("layout.erb")
92
- destination = project.app_layout(context)
93
-
94
- generate_file(source, destination, context)
95
- say(:create, destination)
96
- end
97
-
98
- # @since 1.1.0
99
- # @api private
100
- def generate_template(context)
101
- source = templates.find("template.#{context.template}.erb")
102
- destination = project.app_template(context)
103
-
104
- generate_file(source, destination, context)
105
- say(:create, destination)
106
- end
107
-
108
- # @since 1.1.0
109
- # @api private
110
- def generate_favicon(context)
111
- source = templates.find("favicon.ico")
112
- destination = project.app_favicon(context)
113
-
114
- files.cp(source, destination)
115
- say(:create, destination)
116
- end
117
-
118
- # @since 1.1.0
119
- # @api private
120
- def create_controllers_directory(context)
121
- source = templates.find("gitkeep.erb")
122
- destination = project.keep(project.controllers(context))
123
-
124
- generate_file(source, destination, context)
125
- say(:create, destination)
126
- end
127
-
128
- # @since 1.1.0
129
- # @api private
130
- def create_assets_images_directory(context)
131
- source = templates.find("gitkeep.erb")
132
- destination = project.keep(project.images(context))
133
-
134
- generate_file(source, destination, context)
135
- say(:create, destination)
136
- end
137
-
138
- # @since 1.1.0
139
- # @api private
140
- def create_assets_javascripts_directory(context)
141
- source = templates.find("gitkeep.erb")
142
- destination = project.keep(project.javascripts(context))
143
-
144
- generate_file(source, destination, context)
145
- say(:create, destination)
146
- end
147
-
148
- # @since 1.1.0
149
- # @api private
150
- def create_assets_stylesheets_directory(context)
151
- source = templates.find("gitkeep.erb")
152
- destination = project.keep(project.stylesheets(context))
153
-
154
- generate_file(source, destination, context)
155
- say(:create, destination)
156
- end
157
-
158
- # @since 1.1.0
159
- # @api private
160
- def create_spec_features_directory(context)
161
- source = templates.find("gitkeep.erb")
162
- destination = project.keep(project.features_spec(context))
163
-
164
- generate_file(source, destination, context)
165
- say(:create, destination)
166
- end
167
-
168
- # @since 1.1.0
169
- # @api private
170
- def create_spec_controllers_directory(context)
171
- source = templates.find("gitkeep.erb")
172
- destination = project.keep(project.controllers_spec(context))
173
-
174
- generate_file(source, destination, context)
175
- say(:create, destination)
176
- end
177
-
178
- # @since 1.1.0
179
- # @api private
180
- def generate_layout_spec(context)
181
- source = templates.find("layout_spec.#{context.options.fetch(:test)}.erb")
182
- destination = project.app_layout_spec(context)
183
-
184
- generate_file(source, destination, context)
185
- say(:create, destination)
186
- end
187
-
188
- # @since 1.1.0
189
- # @api private
190
- def inject_require_app(context)
191
- content = "require_relative '../apps/#{context.app}/application'"
192
- destination = project.environment(context)
193
-
194
- req_regex = /^\s*require .*$/
195
- rel_regex = /^\s*require_relative .*$/
196
-
197
- case File.read(destination)
198
- when rel_regex
199
- files.inject_line_after_last(destination, rel_regex, content)
200
- when req_regex
201
- files.inject_line_after_last(destination, req_regex, content)
202
- else
203
- raise "No require found"
204
- end
205
- say(:insert, destination)
206
- end
207
-
208
- # @since 1.1.0
209
- # @api private
210
- def inject_mount_app(context)
211
- content = " mount #{context.app.classify}::Application, at: '#{context.base_url}'"
212
- destination = project.environment(context)
213
-
214
- files.inject_line_after(destination, /Hanami.configure do/, content)
215
- say(:insert, destination)
216
- end
217
-
218
- # @since 1.1.0
219
- # @api private
220
- def append_development_http_session_secret(context)
221
- append_env_to_http_session_secret(context, "development")
222
- end
223
-
224
- # @since 1.1.0
225
- # @api private
226
- def append_test_http_session_secret(context)
227
- append_env_to_http_session_secret(context, "test")
228
- end
229
-
230
- private
231
-
232
- def append_env_to_http_session_secret(context, env)
233
- content = %(#{context.app.upcase}_SESSIONS_SECRET="#{project.app_sessions_secret}")
234
- destination = project.env(context, env)
235
-
236
- files.append(destination, content)
237
- say(:append, destination)
238
- end
239
- end
240
- end
241
- end
242
- end
243
- end
@@ -1,9 +0,0 @@
1
- module Mailers
2
- class <%= mailer.classify %>
3
- include Hanami::Mailer
4
-
5
- from '<%= from %>'
6
- to '<%= to %>'
7
- subject '<%= subject %>'
8
- end
9
- end
@@ -1,7 +0,0 @@
1
- require_relative '../../spec_helper'
2
-
3
- describe Mailers::<%= mailer.classify %> do
4
- it 'delivers email' do
5
- mail = Mailers::<%= mailer.classify %>.deliver
6
- end
7
- end
@@ -1,5 +0,0 @@
1
- RSpec.describe Mailers::<%= mailer.classify %>, type: :mailer do
2
- it 'delivers email' do
3
- mail = Mailers::<%= mailer.classify %>.deliver
4
- end
5
- end
@@ -1,104 +0,0 @@
1
- module Hanami
2
- class CLI
3
- module Commands
4
- module Generate
5
- # @since 1.1.0
6
- # @api private
7
- class Mailer < Command
8
- requires "environment"
9
-
10
- desc "Generate a mailer"
11
-
12
- argument :mailer, required: true, desc: "The mailer name (eg. `welcome`)"
13
-
14
- option :from, desc: "The default `from` field of the mail"
15
- option :to, desc: "The default `to` field of the mail"
16
- option :subject, desc: "The mail subject"
17
-
18
- example [
19
- "welcome # Basic usage",
20
- 'welcome --from="noreply@example.com" # Generate with default `from` value',
21
- 'announcement --to="users@example.com" # Generate with default `to` value',
22
- 'forgot_password --subject="Your password reset" # Generate with default `subject`'
23
- ]
24
-
25
- # @since 1.1.0
26
- # @api private
27
- def call(mailer:, **options)
28
- from = clean_option(options.fetch(:from, DEFAULT_FROM))
29
- to = clean_option(options.fetch(:to, DEFAULT_TO))
30
- subject = clean_option(options.fetch(:subject, DEFAULT_SUBJECT))
31
- context = Context.new(mailer: mailer, test: options.fetch(:test), from: from, to: to, subject: subject, options: options)
32
-
33
- generate_mailer(context)
34
- generate_mailer_spec(context)
35
- generate_text_template(context)
36
- generate_html_template(context)
37
- end
38
-
39
- private
40
-
41
- # @since 1.1.0
42
- # @api private
43
- DEFAULT_FROM = "<from>".freeze
44
-
45
- # @since 1.1.0
46
- # @api private
47
- DEFAULT_TO = "<to>".freeze
48
-
49
- # @since 1.1.0
50
- # @api private
51
- DEFAULT_SUBJECT = "Hello".freeze
52
-
53
- # @since 1.1.1
54
- # @api private
55
- QUOTES_REGEX = /^("|')|("|')$/
56
-
57
- # @since 1.1.0
58
- # @api private
59
- def generate_mailer(context)
60
- source = templates.find("mailer.erb")
61
- destination = project.mailer(context)
62
-
63
- generate_file(source, destination, context)
64
- say(:create, destination)
65
- end
66
-
67
- # @since 1.1.0
68
- # @api private
69
- def generate_mailer_spec(context)
70
- source = templates.find("mailer_spec.#{context.test}.erb")
71
- destination = project.mailer_spec(context)
72
-
73
- generate_file(source, destination, context)
74
- say(:create, destination)
75
- end
76
-
77
- # @since 1.1.0
78
- # @api private
79
- def generate_text_template(context)
80
- destination = project.mailer_template(context, "txt")
81
-
82
- files.touch(destination)
83
- say(:create, destination)
84
- end
85
-
86
- # @since 1.1.0
87
- # @api private
88
- def generate_html_template(context)
89
- destination = project.mailer_template(context, "html")
90
-
91
- files.touch(destination)
92
- say(:create, destination)
93
- end
94
-
95
- # @since 1.1.1
96
- # @api private
97
- def clean_option(option)
98
- option.gsub(QUOTES_REGEX, '')
99
- end
100
- end
101
- end
102
- end
103
- end
104
- end
@@ -1,4 +0,0 @@
1
- Hanami::Model.migration do
2
- change do
3
- end
4
- end
@@ -1,41 +0,0 @@
1
- module Hanami
2
- class CLI
3
- module Commands
4
- module Generate
5
- # @since 1.1.0
6
- # @api private
7
- class Migration < Command
8
- requires "environment"
9
- desc "Generate a migration"
10
-
11
- argument :migration, required: true, desc: "The migration name (eg. `create_users`)"
12
-
13
- example [
14
- "create_users # Generate `db/migrations/#{Project.migration_timestamp}_create_users.rb`"
15
- ]
16
-
17
- # @since 1.1.0
18
- # @api private
19
- def call(migration:, **options)
20
- migration = Utils::String.underscore(migration)
21
- context = Context.new(migration: migration, options: options)
22
-
23
- generate_migration(context)
24
- end
25
-
26
- private
27
-
28
- # @since 1.1.0
29
- # @api private
30
- def generate_migration(context)
31
- source = templates.find("migration.erb")
32
- destination = project.migration(context)
33
-
34
- generate_file(source, destination, context)
35
- say(:create, destination)
36
- end
37
- end
38
- end
39
- end
40
- end
41
- end
@@ -1,2 +0,0 @@
1
- class <%= model.classify %> < Hanami::Entity
2
- end
@@ -1,5 +0,0 @@
1
- require_relative '../../spec_helper'
2
-
3
- describe <%= model.classify %> do
4
- # place your tests here
5
- end
@@ -1,3 +0,0 @@
1
- RSpec.describe <%= model.classify %>, type: :entity do
2
- # place your tests here
3
- end
@@ -1,10 +0,0 @@
1
- Hanami::Model.migration do
2
- change do
3
- create_table :<%= relation %> do
4
- primary_key :id
5
-
6
- column :created_at, DateTime, null: false
7
- column :updated_at, DateTime, null: false
8
- end
9
- end
10
- end
@@ -1,5 +0,0 @@
1
- class <%= model.classify %>Repository < Hanami::Repository
2
- <%- if override_relation_name -%>
3
- self.relation = :<%= relation %>
4
- <%- end -%>
5
- end
@@ -1,5 +0,0 @@
1
- require_relative '../../spec_helper'
2
-
3
- describe <%= model.classify %>Repository do
4
- # place your tests here
5
- end
@@ -1,3 +0,0 @@
1
- RSpec.describe <%= model.classify %>Repository, type: :repository do
2
- # place your tests here
3
- end
@@ -1,125 +0,0 @@
1
- module Hanami
2
- class CLI
3
- module Commands
4
- module Generate
5
- # @since 1.1.0
6
- # @api private
7
- class Model < Command
8
- requires "environment"
9
-
10
- desc "Generate a model"
11
-
12
- argument :model, required: true, desc: "Model name (eg. `user`)"
13
- option :skip_migration, type: :boolean, default: false, desc: "Skip migration"
14
- option :relation, type: :string, desc: "Name of the database relation, default: pluralized model name"
15
-
16
- example [
17
- "user # Generate `User` entity, `UserRepository` repository, and the migration",
18
- "user --skip-migration # Generate `User` entity and `UserRepository` repository",
19
- "user --relation=accounts # Generate `User` entity, `UserRepository` and migration to create `accounts` table"
20
- ]
21
-
22
- # @since 1.1.0
23
- # @api private
24
- def call(model:, **options)
25
- model = Utils::String.underscore(model)
26
- relation = relation_name(options, model)
27
- migration = "create_#{relation}"
28
- context = Context.new(model: model, relation: relation, migration: migration, test: options.fetch(:test), override_relation_name: override_relation_name?(options), options: options)
29
-
30
- assert_valid_relation!(context)
31
-
32
- generate_entity(context)
33
- generate_repository(context)
34
- generate_migration(context)
35
- generate_entity_spec(context)
36
- generate_repository_spec(context)
37
- end
38
-
39
- private
40
-
41
- def assert_valid_relation!(context)
42
- if Utils::Blank.blank?(context.relation)
43
- warn "`#{context.relation}' is not a valid relation name"
44
- exit(1)
45
- end
46
- end
47
-
48
- # @since 1.1.0
49
- # @api private
50
- def generate_entity(context)
51
- source = templates.find("entity.erb")
52
- destination = project.entity(context)
53
-
54
- generate_file(source, destination, context)
55
- say(:create, destination)
56
- end
57
-
58
- # @since 1.1.0
59
- # @api private
60
- def generate_repository(context)
61
- source = templates.find("repository.erb")
62
- destination = project.repository(context)
63
-
64
- generate_file(source, destination, context)
65
- say(:create, destination)
66
- end
67
-
68
- # @since 1.1.0
69
- # @api private
70
- def generate_migration(context)
71
- return if skip_migration?(context)
72
-
73
- source = templates.find("migration.erb")
74
- destination = project.migration(context)
75
-
76
- generate_file(source, destination, context)
77
- say(:create, destination)
78
- end
79
-
80
- # @since 1.1.0
81
- # @api private
82
- def generate_entity_spec(context)
83
- source = templates.find("entity_spec.#{context.test}.erb")
84
- destination = project.entity_spec(context)
85
-
86
- generate_file(source, destination, context)
87
- say(:create, destination)
88
- end
89
-
90
- # @since 1.1.0
91
- # @api private
92
- def generate_repository_spec(context)
93
- source = templates.find("repository_spec.#{context.test}.erb")
94
- destination = project.repository_spec(context)
95
-
96
- generate_file(source, destination, context)
97
- say(:create, destination)
98
- end
99
-
100
- # @since 1.1.0
101
- # @api private
102
- def skip_migration?(context)
103
- context.options.fetch(:skip_migration, false)
104
- end
105
-
106
- # @since 1.1.0
107
- # @api private
108
- def relation_name(options, model)
109
- if override_relation_name?(options)
110
- Utils::String.underscore(options[:relation])
111
- else
112
- Utils::String.pluralize(model)
113
- end
114
- end
115
-
116
- # @since 1.1.0
117
- # @api private
118
- def override_relation_name?(options)
119
- !options.fetch(:relation, nil).nil?
120
- end
121
- end
122
- end
123
- end
124
- end
125
- end
@@ -1,48 +0,0 @@
1
- require "hanami/utils/blank"
2
- require "securerandom"
3
-
4
- module Hanami
5
- class CLI
6
- module Commands
7
- module Generate
8
- # @since 1.1.0
9
- # @api private
10
- class Secret < Command
11
- requires "environment"
12
-
13
- desc "Generate session secret"
14
-
15
- argument :app, desc: "The application name (eg. `web`)"
16
-
17
- example [
18
- " # Prints secret (eg. `#{Project.app_sessions_secret}`)",
19
- "web # Prints session secret (eg. `WEB_SESSIONS_SECRET=#{Project.app_sessions_secret}`)"
20
- ]
21
-
22
- # @since 1.1.0
23
- # @api private
24
- def call(app: nil, **options)
25
- context = Context.new(app: app, options: options)
26
-
27
- generate_secret(context)
28
- end
29
-
30
- private
31
-
32
- # @since 1.1.0
33
- # @api private
34
- def generate_secret(context)
35
- secret = project.app_sessions_secret
36
-
37
- if Hanami::Utils::Blank.blank?(context.app)
38
- puts secret
39
- else
40
- puts "Set the following environment variable to provide the secret token:"
41
- puts %(#{context.app.upcase}_SESSIONS_SECRET="#{secret}")
42
- end
43
- end
44
- end
45
- end
46
- end
47
- end
48
- end