svelte-on-rails 23.2.2 → 23.2.4
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/lib/to_svelte_schema.rb +24 -8
- data/lib/svelte_on_rails/lib/to_svelte_values.rb +53 -12
- metadata +3 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 5b32e84560ccfb6bffec08316451b2710b14b16aaddb707848f74f56ce2333b7
|
|
4
|
+
data.tar.gz: ad850d58b0f82608846ec010d2865cc613e42a6cbd35c1a403bf9a9097982044
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: e638ab62f665d83189601a567c4483395e50da6c3f6223c2936dfa9141d872011579e33b1b8b9915e6b595348a7356e90f1b21a01e5020a2c5525cafa63aca40
|
|
7
|
+
data.tar.gz: c93e42e91a53d8ce91be1887784537d3d07abb40bb5823bdb63a3a9cbc60d4f219f6cef0bb52e19d6b4dfcde6ca7346ccec183d5195cca9d3fe4b25fd57549e5
|
|
@@ -40,15 +40,25 @@ module SvelteOnRails
|
|
|
40
40
|
else
|
|
41
41
|
|
|
42
42
|
attr_s = attr.to_s
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
43
|
+
if model.method_defined?(attr_s) || model_has_attribute?(model, attr_s)
|
|
44
|
+
@labels[key] ||= {}
|
|
45
|
+
@labels[key][attr_s] ||= column_attributes(model, attr_s)
|
|
46
|
+
@labels[key]['self'] ||= model_attributes(model)
|
|
47
|
+
else
|
|
48
|
+
calls = attr_s.scan(/(&?\.)?\s*(?:try\(\s*:([a-zA-Z_]\w*[!?=]?)\s*\)|([a-zA-Z_]\w*[!?=]?))/)
|
|
49
|
+
first_attr = calls.dig(0, 1) || calls.dig(0, 2)
|
|
50
|
+
|
|
51
|
+
@labels[key] ||= {}
|
|
52
|
+
@labels[key]['self'] ||= model_attributes(model)
|
|
53
|
+
|
|
54
|
+
next if attr_s.starts_with?('try(') || attr_s.starts_with?('&.')
|
|
55
|
+
|
|
56
|
+
if model.method_defined?(first_attr)
|
|
57
|
+
@labels[key][first_attr] ||= column_attributes(model, first_attr)
|
|
58
|
+
else
|
|
59
|
+
raise "[SOR] Attribute or method «#{attr_s}» not found in model «#{model}»"
|
|
60
|
+
end
|
|
47
61
|
end
|
|
48
|
-
@labels[key] ||= {}
|
|
49
|
-
@labels[key][_at] ||= column_attributes(model, _at)
|
|
50
|
-
@labels[key]['self'] ||= model_attributes(model)
|
|
51
|
-
|
|
52
62
|
end
|
|
53
63
|
end
|
|
54
64
|
|
|
@@ -83,6 +93,7 @@ module SvelteOnRails
|
|
|
83
93
|
'human_name_plural' => model_name_plural(model),
|
|
84
94
|
'param_key' => mn.param_key,
|
|
85
95
|
'route_key' => mn.route_key,
|
|
96
|
+
'model_name' => mn.name,
|
|
86
97
|
}
|
|
87
98
|
end
|
|
88
99
|
|
|
@@ -140,6 +151,11 @@ module SvelteOnRails
|
|
|
140
151
|
true
|
|
141
152
|
end
|
|
142
153
|
|
|
154
|
+
def model_has_attribute?(model, attr_s)
|
|
155
|
+
return false unless model.respond_to?(:attribute_names)
|
|
156
|
+
|
|
157
|
+
model.attribute_names.include?(attr_s)
|
|
158
|
+
end
|
|
143
159
|
end
|
|
144
160
|
end
|
|
145
161
|
end
|
|
@@ -64,9 +64,24 @@ module SvelteOnRails
|
|
|
64
64
|
attributes.each do |attr|
|
|
65
65
|
|
|
66
66
|
key_s = attr.to_s
|
|
67
|
-
|
|
67
|
+
_split = split_chained_methods(key_s)
|
|
68
68
|
|
|
69
|
-
|
|
69
|
+
if _split.length > 1
|
|
70
|
+
|
|
71
|
+
r = perform_method(record, _split[0])
|
|
72
|
+
values[strip_method(_split[0])] = extract_values_recursive(
|
|
73
|
+
r,
|
|
74
|
+
[_split[1]],
|
|
75
|
+
{},
|
|
76
|
+
call_stack: next_stack
|
|
77
|
+
)
|
|
78
|
+
|
|
79
|
+
else
|
|
80
|
+
|
|
81
|
+
value = perform_method(record, key_s)
|
|
82
|
+
_key_s = strip_method(key_s)
|
|
83
|
+
values[strip_method(_key_s)] = enums.key?(_key_s) ? perform_method(record, _key_s) : value
|
|
84
|
+
end
|
|
70
85
|
end
|
|
71
86
|
|
|
72
87
|
associations.each do |key, val|
|
|
@@ -118,21 +133,47 @@ module SvelteOnRails
|
|
|
118
133
|
obj.is_a?(ActiveRecord::Associations::CollectionProxy)) rescue false
|
|
119
134
|
end
|
|
120
135
|
|
|
121
|
-
def self.
|
|
122
|
-
|
|
136
|
+
def self.perform_method(object, method)
|
|
137
|
+
if method.starts_with?('&.')
|
|
138
|
+
return object.public_send(method[2..]) unless object.nil?
|
|
139
|
+
elsif method.starts_with?('try(')
|
|
140
|
+
unless method.split('.').first.match(/^try\(:[a-z|A-Z|0-9|_]+\)$/)
|
|
141
|
+
raise ArgumentError, "[SOR] Invalid method name: Try statement must look like «try(:method_name)»"
|
|
142
|
+
end
|
|
143
|
+
meth = method[5..-2]
|
|
144
|
+
if object.respond_to?(meth)
|
|
145
|
+
return object.public_send(meth)
|
|
146
|
+
else
|
|
147
|
+
return nil
|
|
148
|
+
end
|
|
149
|
+
else
|
|
150
|
+
object.public_send(method)
|
|
151
|
+
end
|
|
152
|
+
end
|
|
123
153
|
|
|
124
|
-
|
|
125
|
-
return nil if operator == "&." && current.nil?
|
|
154
|
+
def self.split_chained_methods(str)
|
|
126
155
|
|
|
127
|
-
|
|
156
|
+
ind = str.starts_with?('&.') ? str.index('.', 2) : str.index('.')
|
|
157
|
+
if ind.nil?
|
|
158
|
+
return [str]
|
|
159
|
+
elsif str[ind - 1..ind] == '&.'
|
|
160
|
+
return [str[0..ind - 2], str[ind - 1..]]
|
|
161
|
+
else
|
|
162
|
+
return [str[0..ind - 1], str[ind + 1..]]
|
|
163
|
+
end
|
|
128
164
|
|
|
129
|
-
|
|
130
|
-
raise ArgumentError, "[SOR] No method #{method_name.inspect} on #{current.class}"
|
|
131
|
-
end
|
|
165
|
+
end
|
|
132
166
|
|
|
133
|
-
|
|
167
|
+
def self.strip_method(str)
|
|
168
|
+
if str.starts_with?('&.')
|
|
169
|
+
return str[2..]
|
|
170
|
+
elsif str.starts_with?('try')
|
|
171
|
+
return str[5..-2]
|
|
172
|
+
else
|
|
173
|
+
return str
|
|
134
174
|
end
|
|
135
175
|
end
|
|
176
|
+
|
|
136
177
|
end
|
|
137
178
|
end
|
|
138
|
-
end
|
|
179
|
+
end
|
metadata
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: svelte-on-rails
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 23.2.
|
|
4
|
+
version: 23.2.4
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Christian Sedlmair
|
|
8
8
|
bindir: bin
|
|
9
9
|
cert_chain: []
|
|
10
|
-
date:
|
|
10
|
+
date: 2026-11-06 00:00:00.000000000 Z
|
|
11
11
|
dependencies:
|
|
12
12
|
- !ruby/object:Gem::Dependency
|
|
13
13
|
name: railties
|
|
@@ -156,7 +156,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
156
156
|
- !ruby/object:Gem::Version
|
|
157
157
|
version: '0'
|
|
158
158
|
requirements: []
|
|
159
|
-
rubygems_version:
|
|
159
|
+
rubygems_version: 3.6.2
|
|
160
160
|
specification_version: 4
|
|
161
161
|
summary: Server-side rendering, caching, built on vite_rails.
|
|
162
162
|
test_files: []
|