elaine_crud 0.1.1 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8422f897a50d387ca5fb4b12d7bccc7cfe61e82348cf0c86894bc7120a536ccf
4
- data.tar.gz: 2166f5cea579ab4dd3e48853103cf578368b7dd4bdf28d6d1ea550756ddab63e
3
+ metadata.gz: b047d248b9f239b4d39561e232c3540f8da4a4fa94f09ef9a6354b6c8feab0b6
4
+ data.tar.gz: 9fd66a40fd55e0fd3728e74066f2fbf8587f9cb6b988654c89b7e401ab517a52
5
5
  SHA512:
6
- metadata.gz: f35092763acc33ef341b3970e9d9382d41d0a901352e22697bc33d92f33d44c7dff36ce55a6aeba1918dcc5b8bea7752398e283ff193ddf11e70e87e6d6783db
7
- data.tar.gz: 9086537d4951063611ba3dd25e90da626c761b08a2b1ca59e0ac22afe27bd79295451d0b285a7014fbb63bf25349e278d8cc43983d7a61ec63e6287c704dcf1f
6
+ metadata.gz: 47fc98e1ea24bb5823989afe05992e45425fb389c1b95ae9ea641b7cc6c929b5e8c183e1192be6156d61255293a9f38bc6e561e28bb00626ffc7a61a6e46ec4e
7
+ data.tar.gz: ed9867a8cfccba6a7bfc7e060216c5e7f985d845d5de63b8efb4a0bebd2f57d8ec38a2519d5a89ab3c36428bf9ea94c61fbe1f74f76860d5b114dcc25f20f369
@@ -30,6 +30,10 @@ module ElaineCrud
30
30
  protect_from_forgery with: :exception
31
31
  # No layout specified - host app controllers should set their own layout
32
32
 
33
+ # Run deferred auto-configuration on first request
34
+ # This defers database access until runtime, allowing asset precompilation without a database
35
+ before_action :ensure_auto_configuration
36
+
33
37
  # Handle record not found errors with custom 404 page
34
38
  rescue_from ActiveRecord::RecordNotFound, with: :record_not_found
35
39
 
@@ -207,6 +211,12 @@ module ElaineCrud
207
211
 
208
212
  private
209
213
 
214
+ # Run deferred auto-configuration if needed
215
+ # This allows the controller to be loaded without database access during asset precompilation
216
+ def ensure_auto_configuration
217
+ self.class.run_deferred_auto_configuration
218
+ end
219
+
210
220
  # Check if the request is coming from a Turbo Frame
211
221
  def turbo_frame_request?
212
222
  request.headers['Turbo-Frame'].present?
@@ -9,13 +9,17 @@ module ElaineCrud
9
9
  included do
10
10
  class_attribute :crud_model, :permitted_attributes, :column_configurations,
11
11
  :field_configurations, :default_sort_column, :default_sort_direction,
12
- :disable_turbo_frames, :show_view_action_button, :max_export_records
12
+ :disable_turbo_frames, :show_view_action_button, :max_export_records,
13
+ :needs_auto_configuration
13
14
 
14
15
  # Default: View button is disabled
15
16
  self.show_view_action_button = false
16
17
 
17
18
  # Default: Max 10,000 records for export
18
19
  self.max_export_records = 10_000
20
+
21
+ # Default: No auto-configuration pending
22
+ self.needs_auto_configuration = false
19
23
  end
20
24
 
21
25
  class_methods do
@@ -23,16 +27,30 @@ module ElaineCrud
23
27
  # @param model_class [Class] The ActiveRecord model class
24
28
  def model(model_class)
25
29
  self.crud_model = model_class
30
+ # Mark that auto-configuration needs to run at request time
31
+ # This defers database access until runtime, avoiding issues during asset precompilation
32
+ self.needs_auto_configuration = true
33
+ end
34
+
35
+ # Run deferred auto-configuration (called at request time, not class load time)
36
+ # This allows asset precompilation to work without database access
37
+ def run_deferred_auto_configuration
38
+ return unless needs_auto_configuration
39
+ return unless crud_model
40
+
26
41
  # Auto-configure foreign key fields after setting the model
27
- auto_configure_foreign_keys if model_class
42
+ auto_configure_foreign_keys
28
43
  # Auto-configure has_many relationships
29
- auto_configure_has_many_relationships if model_class
44
+ auto_configure_has_many_relationships
30
45
  # Auto-configure has_one relationships
31
- auto_configure_has_one_relationships if model_class
46
+ auto_configure_has_one_relationships
32
47
  # Auto-configure has_and_belongs_to_many relationships
33
- auto_configure_habtm_relationships if model_class
48
+ auto_configure_habtm_relationships
34
49
  # Re-run permit_params to include foreign keys if it was called before model was set
35
50
  refresh_permitted_attributes
51
+
52
+ # Mark as configured so we don't run again
53
+ self.needs_auto_configuration = false
36
54
  end
37
55
 
38
56
  # Specify permitted parameters for strong params
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ElaineCrud
4
- VERSION = '0.1.1'
4
+ VERSION = '0.1.2'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: elaine_crud
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Garo