svelte-on-rails 18.5.3 → 19.0.0
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 +4 -4
- data/lib/svelte_on_rails/active_record_extensions.rb +63 -0
- data/lib/svelte_on_rails/railtie.rb +8 -9
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 6b284e11f440211f67f51444cb124baf8e2877f0e3bf3f61b2d9c8da091a1167
|
|
4
|
+
data.tar.gz: f8ba49f78fcb374c85aa2c99d26de8f33b5c308855a60c4d4284c6c7f7104090
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 0c7cfed392c0ddb72e2780fa622eea2b5aa2400ff247e353b04d0c521a10094e3e4f491f92919b7981df233ba550f5cc5f876bcf7cf098543f633951705d435a
|
|
7
|
+
data.tar.gz: 31ddd13fcc562b8d9642ecd33a2295acb95b93c35ef4ea93b0291cdc54f00f0a0266bb8496271392ccecebaa9b90047bebc0d1d25c62fe6771aa97630c49cb89
|
|
@@ -71,4 +71,67 @@ module SvelteOnRails
|
|
|
71
71
|
|
|
72
72
|
end
|
|
73
73
|
|
|
74
|
+
module ActiveRecordOptIn
|
|
75
|
+
|
|
76
|
+
# Opt this model in to Svelte serialization.
|
|
77
|
+
#
|
|
78
|
+
# class Article < ApplicationRecord
|
|
79
|
+
# exposes_to_svelte
|
|
80
|
+
# end
|
|
81
|
+
#
|
|
82
|
+
# After this call, instances, the class itself, and relations on this
|
|
83
|
+
# model respond to `to_svelte(*attributes, **associations)`.
|
|
84
|
+
def exposes_to_svelte
|
|
85
|
+
return if exposes_to_svelte?
|
|
86
|
+
|
|
87
|
+
# Instance- and class-level methods on the model itself.
|
|
88
|
+
include SvelteOnRails::ActiveRecordExtensions
|
|
89
|
+
extend SvelteOnRails::ActiveRecordClassExtensions
|
|
90
|
+
|
|
91
|
+
# Mark this class as opted in (used by `exposes_to_svelte?`).
|
|
92
|
+
singleton_class.define_method(:exposes_to_svelte?) { true }
|
|
93
|
+
|
|
94
|
+
if abstract_class?
|
|
95
|
+
# Abstract classes have no relation delegate of their own, so we
|
|
96
|
+
# cascade to every concrete subclass. We hook `inherited` for
|
|
97
|
+
# future subclasses, and run the same block for already-loaded
|
|
98
|
+
# subclasses once, here and now.
|
|
99
|
+
opt_in_block = lambda do |concrete|
|
|
100
|
+
next if concrete.abstract_class?
|
|
101
|
+
[
|
|
102
|
+
ActiveRecord::Relation,
|
|
103
|
+
ActiveRecord::AssociationRelation,
|
|
104
|
+
ActiveRecord::Associations::CollectionProxy
|
|
105
|
+
].each do |base|
|
|
106
|
+
concrete.relation_delegate_class(base)
|
|
107
|
+
.include(SvelteOnRails::ActiveRecordRelationExtensions)
|
|
108
|
+
end
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
# Pick up subclasses that were already loaded.
|
|
112
|
+
descendants.each(&opt_in_block)
|
|
113
|
+
|
|
114
|
+
# And catch every future subclass exactly once.
|
|
115
|
+
define_singleton_method(:inherited) do |subclass|
|
|
116
|
+
super(subclass)
|
|
117
|
+
opt_in_block.call(subclass)
|
|
118
|
+
end
|
|
119
|
+
else
|
|
120
|
+
# Concrete model: inject directly into its own relation delegates.
|
|
121
|
+
[
|
|
122
|
+
ActiveRecord::Relation,
|
|
123
|
+
ActiveRecord::AssociationRelation,
|
|
124
|
+
ActiveRecord::Associations::CollectionProxy
|
|
125
|
+
].each do |base|
|
|
126
|
+
relation_delegate_class(base)
|
|
127
|
+
.include(SvelteOnRails::ActiveRecordRelationExtensions)
|
|
128
|
+
end
|
|
129
|
+
end
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
# Default answer for models that did NOT opt in.
|
|
133
|
+
def exposes_to_svelte?
|
|
134
|
+
false
|
|
135
|
+
end
|
|
136
|
+
end
|
|
74
137
|
end
|
|
@@ -11,24 +11,23 @@ module SvelteOnRails
|
|
|
11
11
|
SvelteOnRails::Configuration.instance
|
|
12
12
|
end
|
|
13
13
|
|
|
14
|
-
# initializer "svelte-on-rails.initialize_cache_warmer" do
|
|
15
|
-
# SvelteOnRails::Lib::CacheWarmer.instance
|
|
16
|
-
# end
|
|
17
|
-
|
|
18
14
|
initializer "svelte-on-rails.initialize_ssr_client" do
|
|
19
15
|
SvelteOnRails::SsrServer.instance
|
|
20
16
|
end
|
|
21
17
|
|
|
22
18
|
initializer 'svelte_on_rails.active_record_extensions' do
|
|
23
19
|
ActiveSupport.on_load(:active_record) do
|
|
24
|
-
# Include instance-level extensions for ActiveRecord instances (e.g., @article)
|
|
25
|
-
include SvelteOnRails::ActiveRecordExtensions
|
|
26
20
|
|
|
27
|
-
|
|
28
|
-
|
|
21
|
+
ActiveRecord::Base.extend SvelteOnRails::ActiveRecordOptIn
|
|
22
|
+
|
|
23
|
+
# # Include instance-level extensions for ActiveRecord instances (e.g., @article)
|
|
24
|
+
# include SvelteOnRails::ActiveRecordExtensions
|
|
25
|
+
#
|
|
26
|
+
# # Extend ActiveRecord::Base with class-level extensions (e.g., Article)
|
|
27
|
+
# ActiveRecord::Base.extend SvelteOnRails::ActiveRecordClassExtensions
|
|
29
28
|
|
|
30
29
|
# This also extends ActiveRecord::Relation (e.g., @articles)
|
|
31
|
-
ActiveRecord::Relation.include SvelteOnRails::ActiveRecordRelationExtensions
|
|
30
|
+
#ActiveRecord::Relation.include SvelteOnRails::ActiveRecordRelationExtensions
|
|
32
31
|
end
|
|
33
32
|
end
|
|
34
33
|
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: svelte-on-rails
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version:
|
|
4
|
+
version: 19.0.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Christian Sedlmair
|
|
@@ -136,7 +136,7 @@ licenses:
|
|
|
136
136
|
- MIT
|
|
137
137
|
metadata:
|
|
138
138
|
homepage_uri: https://svelte-on-rails.dev
|
|
139
|
-
source_code_uri: https://svelte-on-rails
|
|
139
|
+
source_code_uri: https://gitlab.com/sedl/svelte-on-rails
|
|
140
140
|
changelog_uri: https://svelte-on-rails.dev
|
|
141
141
|
post_install: ruby -r svelte_on_rails/install -e 'SvelteOnRails::Install.run'
|
|
142
142
|
rdoc_options: []
|