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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f8fa328e87d9ada849f7cb531e7f2ca5a5caef9a3c4c43b231b366060eb2f452
4
- data.tar.gz: b316fd8f037a0f700b56f6648b383af606b802e65c21fd23030c0da9916399dc
3
+ metadata.gz: 5b32e84560ccfb6bffec08316451b2710b14b16aaddb707848f74f56ce2333b7
4
+ data.tar.gz: ad850d58b0f82608846ec010d2865cc613e42a6cbd35c1a403bf9a9097982044
5
5
  SHA512:
6
- metadata.gz: ebeb23d19bbd630b0250922cebca37cffb9524eaf1de12a895acb75b6c071ff80fa879fae2999091404ecf0784a892c39b5c200423a01cc68b323675967bc82e
7
- data.tar.gz: 2808b70bafe5bb0d5f6f34b347ddfe21dcb55611eda252d848b422e5b35ca26da4a6d86bb23c8f578af1aa6ed53ea17d3b50b6497fa8760c617a4493abee4516
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
- dot_index = attr_s.index('.')
44
- _at = dot_index ? attr_s[0...dot_index].delete_suffix('&') : attr_s
45
- if !model.method_defined?(_at) && !model.attribute_names.include?(_at)
46
- raise "ERROR: Attribute or method «#{_at}» not found in model «#{_at}»"
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
- value = chained_send(record, key_s)
67
+ _split = split_chained_methods(key_s)
68
68
 
69
- values[key_s] = enums.key?(key_s) ? chained_send(record, key_s) : value
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.chained_send(object, path)
122
- calls = path.to_s.scan(/(&?\.)?([a-zA-Z_]\w*[!?=]?)/)
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
- calls.reduce(object) do |current, (operator, method_name)|
125
- return nil if operator == "&." && current.nil?
154
+ def self.split_chained_methods(str)
126
155
 
127
- raise ArgumentError, "[SOR] Cannot call #{method_name} on nil" if current.nil?
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
- unless current.respond_to?(method_name)
130
- raise ArgumentError, "[SOR] No method #{method_name.inspect} on #{current.class}"
131
- end
165
+ end
132
166
 
133
- current.public_send(method_name)
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.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: 1980-01-02 00:00:00.000000000 Z
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: 4.0.4
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: []