svelte-on-rails 23.2.3 → 23.2.5

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: f57193866eadaa502f7c7a58092f5b3eef61e5daaf61afa6ddaad40654aea5c5
4
- data.tar.gz: 4e8e65401809985e091f63e6477cd263caf7bee5cc1bf8e9091c028c7174a907
3
+ metadata.gz: b6a5ee69f9cf88c4f9828917ea97e128dc98b14202c831be7807486b88f6a41c
4
+ data.tar.gz: 61a0ece2fc654a64a2287447a4676308ddd94c2036d0f88e6e3d55e773dc3e14
5
5
  SHA512:
6
- metadata.gz: 477588c626391c9a253c262959f15f612a21a19f0a54b300dd0bdc8e5f110f947351274dd6b214b18adcee0973288e25072d1c1e991efbfd39b40e09b6cac432
7
- data.tar.gz: 17224735040f888256f2de5c8043eb0ac12d5218e38d4f4f4c7b8e906ec5dfdbe9f1dfdea2c3b7d687c7509393e8052f2bbc2768a47a696a167b0cb3a49feb0d
6
+ metadata.gz: b4f6ef5f773f2d1f7cc05c7d9f62a5495be0c1cfc0a0877ae1f211efd71a8646519860d7467d69425c150a0adf7769e597f98f62b6a1ade6b94c056d09a7437d
7
+ data.tar.gz: d96c76a6e11a07277beca9746f6daf53b567c41eceddd5fe1313f8e19b44803dda86bdf24fd0af4f2e0bb47604ad329531f30b77964d38b12c5e84cd0764e1d3
@@ -51,7 +51,7 @@ module SvelteOnRails
51
51
  cleanup_requests
52
52
 
53
53
  FileUtils.mkdir_p(File.dirname(file_path))
54
- File.write(file_path, @requests.to_json)
54
+ File.write(file_path, JSON.generate(@requests))
55
55
  end
56
56
 
57
57
  def warm_up
@@ -23,7 +23,7 @@ module SvelteOnRails
23
23
 
24
24
  stdout, stderr, status = Open3.capture3(
25
25
  cmd,
26
- stdin_data: props.to_json,
26
+ stdin_data: JSON.generate(props),
27
27
  chdir: cnf.rails_root,
28
28
  )
29
29
 
@@ -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
 
@@ -141,6 +151,11 @@ module SvelteOnRails
141
151
  true
142
152
  end
143
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
144
159
  end
145
160
  end
146
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
@@ -141,7 +141,7 @@ module SvelteOnRails
141
141
  )
142
142
 
143
143
  ht_opts[:class] = "svelte-component #{ht_opts[:class]}"
144
- ht_opts[:data][:props] = svelte_props.to_json
144
+ ht_opts[:data][:props] = JSON.generate(svelte_props)
145
145
  ht_opts[:data][:svelte_status] = (@options[:hydrate] == false ? 'do-not-hydrate-me' : 'ssr')
146
146
  ht_opts
147
147
  end
@@ -55,7 +55,7 @@ module SvelteOnRails
55
55
  end
56
56
 
57
57
  build_status_file.dirname.mkpath
58
- build_status_file.write(@build_status.to_json)
58
+ build_status_file.write(JSON.generate(@build_status))
59
59
 
60
60
  {
61
61
  status: (passed ? "SUCCESS" : "failed"),
@@ -74,7 +74,7 @@ module SvelteOnRails
74
74
  _asset_path = manifest[component[:path]]['file']
75
75
  full_asset_path = Rails.root.join('public', 'svelte-ssr', _asset_path)
76
76
 
77
- body_json = { component: full_asset_path, props: props }.to_json
77
+ body_json = JSON.generate({ component: full_asset_path, props: props })
78
78
 
79
79
  request = "POST /render HTTP/1.1\r\n" +
80
80
  "Host: localhost\r\n" +
@@ -511,14 +511,14 @@ module SvelteOnRails
511
511
  def write_startup_flock_info(flock)
512
512
  flock.rewind
513
513
  flock.truncate(0)
514
- flock.puts({
514
+ flock.puts(JSON.generate({
515
515
  startup_id: @startup_id,
516
516
  pid: Process.pid,
517
517
  ppid: Process.ppid,
518
518
  rails_root: Rails.root.to_s,
519
519
  socket_path: socket_path_fresh.to_s,
520
520
  created_at: Time.now.utc.iso8601(3)
521
- }.to_json)
521
+ }))
522
522
  flock.flush
523
523
  end
524
524
 
@@ -738,7 +738,7 @@ module SvelteOnRails
738
738
  end
739
739
  end
740
740
 
741
- client.puts(response.to_json)
741
+ client.puts(JSON.generate(response))
742
742
  rescue => e
743
743
  SvelteOnRails::Lib::Utils.ssr_server_log(
744
744
  "[control] handler error: #{e.class}: #{e.message}",
@@ -21,7 +21,7 @@ module SvelteOnRails
21
21
  selector: selector
22
22
  }
23
23
 
24
- args_enc = Base64.strict_encode64(args.to_json)
24
+ args_enc = Base64.strict_encode64(JSON.generate(args))
25
25
 
26
26
  Turbo::StreamsChannel.send(
27
27
  "broadcast_append_to",
@@ -45,7 +45,7 @@ module SvelteOnRails
45
45
  selector: selector
46
46
  }
47
47
 
48
- args_enc = Base64.strict_encode64(args.to_json)
48
+ args_enc = Base64.strict_encode64(JSON.generate(args))
49
49
 
50
50
  Turbo::StreamsChannel.send(
51
51
  "broadcast_append_to",
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.3
4
+ version: 23.2.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Christian Sedlmair
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2026-11-03 00:00:00.000000000 Z
10
+ date: 2026-11-09 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: railties