plutonium 0.13.3 → 0.14.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (35) hide show
  1. checksums.yaml +4 -4
  2. data/lib/generators/pu/core/assets/assets_generator.rb +2 -2
  3. data/lib/generators/pu/core/install/install_generator.rb +0 -3
  4. data/lib/generators/pu/core/install/templates/config/initializers/plutonium.rb +10 -0
  5. data/lib/generators/pu/lib/plutonium_generators/concerns/actions.rb +19 -0
  6. data/lib/generators/pu/pkg/app/templates/config/routes.rb.tt +5 -6
  7. data/lib/generators/pu/pkg/app/templates/lib/engine.rb.tt +0 -4
  8. data/lib/generators/pu/res/conn/conn_generator.rb +4 -4
  9. data/lib/plutonium/application/controller.rb +1 -1
  10. data/lib/plutonium/application/dynamic_controllers.rb +108 -0
  11. data/lib/plutonium/auth/rodauth.rb +1 -1
  12. data/lib/plutonium/concerns/resource_validatable.rb +34 -0
  13. data/lib/plutonium/config/overlayed_hash.rb +86 -0
  14. data/lib/plutonium/configuration.rb +138 -0
  15. data/lib/plutonium/core/autodiscovery/association_renderer_discoverer.rb +1 -1
  16. data/lib/plutonium/core/autodiscovery/input_discoverer.rb +1 -1
  17. data/lib/plutonium/core/autodiscovery/renderer_discoverer.rb +1 -1
  18. data/lib/plutonium/core/controllers/entity_scoping.rb +84 -26
  19. data/lib/plutonium/helpers/assets_helper.rb +73 -20
  20. data/lib/plutonium/pkg/app.rb +3 -115
  21. data/lib/plutonium/pkg/concerns/resource_validatable.rb +36 -0
  22. data/lib/plutonium/railtie.rb +53 -30
  23. data/lib/plutonium/reloader.rb +66 -24
  24. data/lib/plutonium/resource/controller.rb +1 -1
  25. data/lib/plutonium/resource_register.rb +83 -0
  26. data/lib/plutonium/routing/mapper_extensions.rb +127 -0
  27. data/lib/plutonium/routing/resource_registration.rb +16 -0
  28. data/lib/plutonium/routing/route_set_extensions.rb +132 -0
  29. data/lib/plutonium/smart_cache.rb +151 -0
  30. data/lib/plutonium/version.rb +1 -1
  31. data/lib/plutonium.rb +41 -27
  32. data/sig/.keep +0 -0
  33. metadata +13 -4
  34. data/lib/generators/pu/rodauth/templates/app/rodauth/account_rodauth_plugin.rb.tt +0 -270
  35. data/sig/plutonium.rbs +0 -12
data/lib/plutonium.rb CHANGED
@@ -1,57 +1,71 @@
1
- require "zeitwerk"
2
-
3
- # Zeitwerk loader setup for the Plutonium gem
4
- loader = Zeitwerk::Loader.for_gem(warn_on_extra_files: false)
5
- loader.ignore("#{__dir__}/generators")
6
- loader.ignore("#{__dir__}/plutonium/railtie.rb")
7
- loader.enable_reloading if defined?(Rails.env) && Rails.env.development?
8
- loader.setup
1
+ # frozen_string_literal: true
9
2
 
10
- require_relative "plutonium/railtie" if defined?(Rails::Railtie)
3
+ require "zeitwerk"
4
+ require_relative "plutonium/configuration"
11
5
 
6
+ # Plutonium module
7
+ #
8
+ # This module provides the main functionality for the Plutonium gem.
9
+ # It sets up autoloading using Zeitwerk and provides utility methods
10
+ # for accessing gem-related information.
12
11
  module Plutonium
13
- # Custom error class for the Plutonium module
12
+ # Custom error class for Plutonium-specific exceptions
14
13
  class Error < StandardError; end
15
14
 
15
+ # Set up Zeitwerk loader for the Plutonium gem
16
+ # @return [Zeitwerk::Loader] configured Zeitwerk loader instance
17
+ ZEITWERK_LOADER = Zeitwerk::Loader.for_gem(warn_on_extra_files: false).tap do |loader|
18
+ loader.ignore("#{__dir__}/generators")
19
+ loader.ignore("#{__dir__}/plutonium/railtie.rb")
20
+ loader.enable_reloading if defined?(Rails.env) && Rails.env.development?
21
+ loader.setup
22
+ end
23
+
16
24
  class << self
17
- # @return [Pathname] the root directory of the gem
25
+ # Get the root directory of the gem
26
+ #
27
+ # @return [Pathname] the root directory path
18
28
  def root
19
- Pathname.new(File.expand_path("..", __dir__))
29
+ @root ||= Pathname.new(File.expand_path("..", __dir__))
20
30
  end
21
31
 
22
- # @return [Pathname] the root directory of the lib folder of the gem
32
+ # Get the root directory of the lib folder of the gem
33
+ #
34
+ # @return [Pathname] the lib root directory path
23
35
  def lib_root
24
- root.join("lib", "plutonium")
36
+ @lib_root ||= root.join("lib", "plutonium")
25
37
  end
26
38
 
27
- # @return [Logger] the Rails logger
39
+ # Get the Rails logger
40
+ #
41
+ # @return [Logger] the Rails logger instance
28
42
  def logger
29
43
  Rails.logger
30
44
  end
31
45
 
32
- # @return [String] the name of the application
46
+ # Get the name of the application
47
+ #
48
+ # @return [String] the application name
33
49
  def application_name
34
50
  @application_name || Rails.application.class.module_parent_name
35
51
  end
36
52
 
37
- # @param [String] application_name the name of the application
38
- # @return [void]
53
+ # Set the name of the application
54
+ #
55
+ # @param [String] name the name of the application
39
56
  attr_writer :application_name
40
57
 
41
- # @return [Boolean] whether the gem is in development mode
42
- def development?
43
- ActiveModel::Type::Boolean.new.cast(ENV["PLUTONIUM_DEV"]).present?
44
- end
45
-
46
- # Eager loads Rails application if not already eager loaded
58
+ # Eager load Rails application if not already eager loaded
59
+ #
47
60
  # @return [void]
48
61
  def eager_load_rails!
49
- return if Rails.env.production? && defined?(@rails_eager_loaded)
62
+ return if @rails_eager_loaded || Rails.application.config.eager_load
50
63
 
51
- Rails.application.eager_load! unless Rails.application.config.eager_load
64
+ Rails.application.eager_load!
52
65
  @rails_eager_loaded = true
53
66
  end
54
67
  end
55
68
  end
56
69
 
57
- Plutonium::ZEITWERK_LOADER = loader
70
+ # Load Railtie if Rails is defined
71
+ require_relative "plutonium/railtie" if defined?(Rails::Railtie)
data/sig/.keep ADDED
File without changes
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: plutonium
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.13.3
4
+ version: 0.14.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stefan Froelich
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-07-08 00:00:00.000000000 Z
11
+ date: 2024-07-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: zeitwerk
@@ -1095,7 +1095,6 @@ files:
1095
1095
  - lib/generators/pu/rodauth/templates/app/mailers/account_mailer.rb.tt
1096
1096
  - lib/generators/pu/rodauth/templates/app/mailers/rodauth_mailer.rb.tt
1097
1097
  - lib/generators/pu/rodauth/templates/app/models/account.rb.tt
1098
- - lib/generators/pu/rodauth/templates/app/rodauth/account_rodauth_plugin.rb.tt
1099
1098
  - lib/generators/pu/rodauth/templates/app/rodauth/rodauth_app.rb.tt
1100
1099
  - lib/generators/pu/rodauth/templates/app/rodauth/rodauth_plugin.rb.tt
1101
1100
  - lib/generators/pu/rodauth/templates/app/views/rodauth_mailer/email_auth.text.erb
@@ -1120,13 +1119,17 @@ files:
1120
1119
  - lib/generators/pu/service/sidekiq/templates/config/sidekiq.yml
1121
1120
  - lib/plutonium.rb
1122
1121
  - lib/plutonium/application/controller.rb
1122
+ - lib/plutonium/application/dynamic_controllers.rb
1123
1123
  - lib/plutonium/auth.rb
1124
1124
  - lib/plutonium/auth/public.rb
1125
1125
  - lib/plutonium/auth/rodauth.rb
1126
1126
  - lib/plutonium/builders/menus/sidebar_menu.rb.bk
1127
1127
  - lib/plutonium/builders/menus/sidebar_menu_item.rb.bk
1128
1128
  - lib/plutonium/component_registry.rb
1129
+ - lib/plutonium/concerns/resource_validatable.rb
1129
1130
  - lib/plutonium/config.rb
1131
+ - lib/plutonium/config/overlayed_hash.rb
1132
+ - lib/plutonium/configuration.rb
1130
1133
  - lib/plutonium/core/.DS_Store
1131
1134
  - lib/plutonium/core/action.rb
1132
1135
  - lib/plutonium/core/actions/basic_action.rb
@@ -1195,6 +1198,7 @@ files:
1195
1198
  - lib/plutonium/lib/bit_flags.rb
1196
1199
  - lib/plutonium/pkg/app.rb
1197
1200
  - lib/plutonium/pkg/base.rb
1201
+ - lib/plutonium/pkg/concerns/resource_validatable.rb
1198
1202
  - lib/plutonium/pkg/feature.rb
1199
1203
  - lib/plutonium/policy/initializer.rb
1200
1204
  - lib/plutonium/policy/scope.rb
@@ -1213,9 +1217,14 @@ files:
1213
1217
  - lib/plutonium/resource/presenter.rb
1214
1218
  - lib/plutonium/resource/query_object.rb
1215
1219
  - lib/plutonium/resource/record.rb
1220
+ - lib/plutonium/resource_register.rb
1216
1221
  - lib/plutonium/rodauth/controller_methods.rb
1222
+ - lib/plutonium/routing/mapper_extensions.rb
1223
+ - lib/plutonium/routing/resource_registration.rb
1224
+ - lib/plutonium/routing/route_set_extensions.rb
1217
1225
  - lib/plutonium/simple_form/attachment_component.rb
1218
1226
  - lib/plutonium/simple_form/input_group_component.rb
1227
+ - lib/plutonium/smart_cache.rb
1219
1228
  - lib/plutonium/version.rb
1220
1229
  - lib/tasks/create_rodauth_admin.rake
1221
1230
  - package-lock.json
@@ -1229,7 +1238,7 @@ files:
1229
1238
  - public/plutonium-assets/plutonium-logo-white.png
1230
1239
  - public/plutonium-assets/plutonium-logo.png
1231
1240
  - public/plutonium-assets/plutonium.ico
1232
- - sig/plutonium.rbs
1241
+ - sig/.keep
1233
1242
  - src/.npmignore
1234
1243
  - src/css/plutonium.css
1235
1244
  - src/js/controllers/color_mode_controller.js
@@ -1,270 +0,0 @@
1
- require "sequel/core"
2
-
3
- class <%= account_path.classify %>RodauthPlugin < RodauthPlugin
4
- configure do
5
- # This block is running inside of
6
- # plugin :rodauth do
7
- # ...
8
- # end
9
-
10
- # ==> Features
11
- # See the Rodauth documentation for the list of available config options:
12
- # http://rodauth.jeremyevans.net/documentation.html
13
-
14
- # List of authentication features that are loaded.
15
- enable <%= selected_features.map(&:inspect).join ', ' %>
16
-
17
- # ==> General
18
-
19
- # Change prefix of table and foreign key column names from default "account"
20
- # accounts_table: 'players'
21
-
22
- # The secret key used for hashing public-facing tokens for various features.
23
- # Defaults to Rails `secret_key_base`, but you can use your own secret key.
24
- # hmac_secret "<SECRET_KEY>"
25
-
26
- # Use path prefix for all routes.
27
- <%= '# ' if primary? %>prefix "/<%= account_path.pluralize %>"
28
- <% unless separate_passwords? -%>
29
-
30
- # Store password hash in a column instead of a separate table.
31
- account_password_hash_column :password_hash
32
- <% end -%>
33
-
34
- # Specify the controller used for view rendering, CSRF, and callbacks.
35
- rails_controller { Rodauth::<%= account_path.classify %>Controller }
36
-
37
- # Specify the model to be used.
38
- rails_account_model { <%= account_path.classify %> }
39
- <% if verify_account? -%>
40
-
41
- # Set password password during create account.
42
- # verify_account_set_password? false
43
- <% end -%>
44
-
45
- # Change some default param keys.
46
- # login_param "email"
47
- # password_confirm_param "confirm_password"
48
- <% if login? -%>
49
-
50
- # Redirect back to originally requested location after authentication.
51
- login_return_to_requested_location? true
52
- <% end -%>
53
- # two_factor_auth_return_to_requested_location? true # if using MFA
54
-
55
- # Autologin the user after they have reset their password.
56
- # reset_password_autologin? true
57
-
58
- # Delete the account record when the user has closed their account.
59
- # delete_account_on_close? true
60
-
61
- # Redirect to the app from login and registration pages if already logged in.
62
- # already_logged_in { redirect login_redirect }
63
- <% if jwt? -%>
64
-
65
- # ==> JWT
66
-
67
- # Set JWT secret, which is used to cryptographically protect the token.
68
- jwt_secret Rails.application.credentials.secret_key_base
69
- <% end -%>
70
- <% if only_json? -%>
71
-
72
- # ==> Api only
73
-
74
- # Accept only JSON requests.
75
- only_json? true
76
-
77
- # Handle login and password confirmation fields on the client side.
78
- require_password_confirmation? false
79
- require_login_confirmation? false
80
- <% else -%>
81
-
82
- # Accept both api and form requests
83
- # Requires the JSON feature
84
- <%= '# ' unless json? %>only_json? false
85
- <% end -%>
86
- <% if mails? -%>
87
-
88
- # ==> Emails
89
- # Use a custom mailer for delivering authentication emails.
90
- <% if reset_password? -%>
91
-
92
- create_reset_password_email do
93
- Rodauth::<%= account_path.classify %>Mailer.reset_password(self.class.configuration_name, account_id, reset_password_key_value)
94
- end
95
- <% end -%>
96
- <% if verify_account? -%>
97
-
98
- create_verify_account_email do
99
- Rodauth::<%= account_path.classify %>Mailer.verify_account(self.class.configuration_name, account_id, verify_account_key_value)
100
- end
101
- <% end -%>
102
- <% if verify_login_change? -%>
103
-
104
- create_verify_login_change_email do |_login|
105
- Rodauth::<%= account_path.classify %>Mailer.verify_login_change(self.class.configuration_name, account_id, verify_login_change_key_value)
106
- end
107
- <% end -%>
108
- <% if change_password_notify? -%>
109
-
110
- create_password_changed_email do
111
- Rodauth::<%= account_path.classify %>Mailer.change_password_notify(self.class.configuration_name, account_id)
112
- end
113
- <% end -%>
114
- <% if reset_password_notify? -%>
115
-
116
- create_reset_password_notify_email do
117
- Rodauth::<%= account_path.classify %>Mailer.reset_password_notify(self.class.configuration_name, account_id)
118
- end
119
- <% end -%>
120
- <% if email_auth? -%>
121
-
122
- create_email_auth_email do
123
- Rodauth::<%= account_path.classify %>Mailer.email_auth(self.class.configuration_name, account_id, email_auth_key_value)
124
- end
125
- <% end -%>
126
- <% if lockout? -%>
127
-
128
- create_unlock_account_email do
129
- Rodauth::<%= account_path.classify %>Mailer.unlock_account(self.class.configuration_name, account_id, unlock_account_key_value)
130
- end
131
- <% end -%>
132
-
133
- send_email do |email|
134
- # queue email delivery on the mailer after the transaction commits
135
- db.after_commit { email.deliver_later }
136
- end
137
- <% end -%>
138
- <% unless only_json? -%>
139
-
140
- # ==> Flash
141
- # Does not work with only_json?
142
-
143
- # Match flash keys with ones already used in the Rails app.
144
- # flash_notice_key :success # default is :notice
145
- # flash_error_key :error # default is :alert
146
-
147
- # Override default flash messages.
148
- # create_account_notice_flash "Your account has been created. Please verify your account by visiting the confirmation link sent to your email address."
149
- # require_login_error_flash "Login is required for accessing this page"
150
- # login_notice_flash nil
151
- <% end -%>
152
-
153
- # ==> Validation
154
- # Override default validation error messages.
155
- # no_matching_login_message "user with this email address doesn't exist"
156
- # already_an_account_with_this_login_message "user with this email address already exists"
157
- # password_too_short_message { "needs to have at least #{password_minimum_length} characters" }
158
- # login_does_not_meet_requirements_message { "invalid email#{", #{login_requirement_message}" if login_requirement_message}" }
159
-
160
- # ==> Passwords
161
-
162
- # Passwords shorter than 8 characters are considered weak according to OWASP.
163
- <%= '# ' unless login? %>password_minimum_length 8
164
-
165
- # Custom password complexity requirements (alternative to password_complexity feature).
166
- # password_meets_requirements? do |password|
167
- # super(password) && password_complex_enough?(password)
168
- # end
169
- # auth_class_eval do
170
- # def password_complex_enough?(password)
171
- # return true if password.match?(/\d/) && password.match?(/[^a-zA-Z\d]/)
172
- # set_password_requirement_error_message(:password_simple, "requires one number and one special character")
173
- # false
174
- # end
175
- # end
176
- <% unless argon2? -%>
177
-
178
- # = bcrypt
179
-
180
- # bcrypt has a maximum input length of 72 bytes, truncating any extra bytes.
181
- password_maximum_bytes 72 if respond_to?(:password_maximum_bytes)
182
- <% else -%>
183
-
184
- # = argon2
185
-
186
- # Use a rotatable password pepper when hashing passwords with Argon2.
187
- argon2_secret "TODO: <SECRET_KEY>"
188
-
189
- # Since we're using argon2, prevent loading the bcrypt gem to save memory.
190
- require_bcrypt? false
191
-
192
- # Having a maximum password length set prevents long password DoS attacks.
193
- password_maximum_length 64 if respond_to?(:password_maximum_length)
194
- <% end -%>
195
- <% if remember? -%>
196
-
197
- # ==> Remember Feature
198
-
199
- # Remember all logged in users.
200
- after_login { remember_login }
201
-
202
- # Or only remember users that have ticked a "Remember Me" checkbox on login.
203
- # after_login { remember_login if param_or_nil("remember") }
204
-
205
- # Extend user's remember period when remembered via a cookie
206
- extend_remember_deadline? true
207
-
208
- # Store the user's remember cookie under a namespace
209
- remember_cookie_key "_<%= table_prefix %>_remember"
210
- <% end -%>
211
-
212
- # ==> Hooks
213
-
214
- # Validate custom fields in the create account form.
215
- # before_create_account do
216
- # throw_error_status(422, "name", "must be present") if param("name").empty?
217
- # end
218
-
219
- # Perform additional actions after the account is created.
220
- # after_create_account do
221
- # Profile.create!(account_id: account_id, name: param("name"))
222
- # end
223
-
224
- # Do additional cleanup after the account is closed.
225
- # after_close_account do
226
- # Profile.find_by!(account_id: account_id).destroy
227
- # end
228
- <% unless only_json? -%>
229
-
230
- # ==> Redirects
231
- <% if create_account? -%>
232
-
233
- # Redirect to home after login.
234
- create_account_redirect "/"
235
- <% end -%>
236
- <% if login? -%>
237
-
238
- # Redirect to home after login.
239
- login_redirect "/"
240
- <% end -%>
241
- <% if logout? -%>
242
-
243
- # Redirect to home page after logout.
244
- logout_redirect "/"
245
- <% end -%>
246
- <% if verify_account? -%>
247
-
248
- # Redirect to wherever login redirects to after account verification.
249
- verify_account_redirect { login_redirect }
250
- <% end -%>
251
- <% if reset_password? -%>
252
-
253
- # Redirect to login page after password reset.
254
- reset_password_redirect { login_path }
255
- <% end -%>
256
-
257
- # Ensure requiring login follows login route changes.
258
- require_login_redirect { login_path }
259
- <% end -%>
260
-
261
- # ==> Deadlines
262
- # Change default deadlines for some actions.
263
- # verify_account_grace_period 3.days.to_i
264
- # reset_password_deadline_interval Hash[hours: 6]
265
- # verify_login_change_deadline_interval Hash[days: 2]
266
- <% unless only_json? -%>
267
- # remember_deadline_interval Hash[days: 30]
268
- <% end -%>
269
- end
270
- end
data/sig/plutonium.rbs DELETED
@@ -1,12 +0,0 @@
1
- # plutonium.rbs
2
- module Plutonium
3
- class Error < StandardError; end
4
-
5
- def self.root: () -> Pathname
6
- def self.lib_root: () -> Pathname
7
- def self.logger: () -> Logger
8
- def self.application_name: () -> String
9
- def self.application_name=: (String) -> void
10
- def self.development?: () -> bool
11
- def self.eager_load_rails!: () -> void
12
- end