chobble-forms 0.7.1 → 0.7.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: 771171d582d4bdb09d03fc7ac56a37ca4922d7ce9ee76f392c19c0667e2cd6d3
4
- data.tar.gz: e692e2d66579f14eae1099989efddef5a7358620653ac6ab7daaf3ffab151333
3
+ metadata.gz: 6541e97cfb901cd5437021bc314615f055125057456dfad79475be9497c55092
4
+ data.tar.gz: 21a7944f64c0974e144cfbc0b39fcb4d0f7dcff980358b08454c899ef181d8a3
5
5
  SHA512:
6
- metadata.gz: c7b53bd70bfa1063f24071b476a9789b43d79c0c539e033857b1331caf0456bb324fea113a93471bc0fef9b114c9b9004f52b10c0c3a82ef52c6a85e54b91e34
7
- data.tar.gz: f4b9fd0dedb8a2e0d133cf09f0dc0ab5e9e4b390cfeafe510b16424e9ec1037492fdec506db580447c61d6857597bb164d60c2b211fc019f1df58d1472f27202
6
+ metadata.gz: 47ddc8c257e2e6b228205fbe2f6ac215b5d43d51e1df0f4348f912b94f1d153f2b0d810db04ef6531c71c30b0f69ad12b29a4d9ab74b4a5be7af60bf56237f2a
7
+ data.tar.gz: f30b8deb1d9ad611671be7a3fc92d41e37e36613b6a6d294cef1c28e46ef402bd495820b5a7b1bd0e989e987729defb196292c17dc20a258a3b88b3c437e2a92
@@ -7,11 +7,11 @@ module ChobbleForms
7
7
  module Helpers
8
8
  extend T::Sig
9
9
 
10
- SelectOption = T.type_alias {
10
+ SelectOption = T.type_alias do
11
11
  [String, T.any(String, Integer)]
12
- }
12
+ end
13
13
 
14
- LocalAssignValue = T.type_alias {
14
+ LocalAssignValue = T.type_alias do
15
15
  T.any(
16
16
  String,
17
17
  Symbol,
@@ -21,9 +21,9 @@ module ChobbleForms
21
21
  T::Array[SelectOption],
22
22
  T::Hash[Symbol, T.untyped]
23
23
  )
24
- }
24
+ end
25
25
 
26
- FieldSetupResult = T.type_alias {
26
+ FieldSetupResult = T.type_alias do
27
27
  {
28
28
  form_object: T.untyped,
29
29
  i18n_base: String,
@@ -33,7 +33,7 @@ module ChobbleForms
33
33
  field_hint: T.nilable(String),
34
34
  field_placeholder: T.nilable(String)
35
35
  }
36
- }
36
+ end
37
37
 
38
38
  sig { params(field: Symbol, local_assigns: T::Hash[Symbol, LocalAssignValue]).returns(FieldSetupResult) }
39
39
  def form_field_setup(field, local_assigns)
@@ -91,7 +91,10 @@ module ChobbleForms
91
91
  }
92
92
  end
93
93
 
94
- sig { params(prefilled: T::Boolean, checked_value: T.untyped, expected_value: T.untyped).returns(T::Hash[Symbol, T::Boolean]) }
94
+ sig do
95
+ params(prefilled: T::Boolean, checked_value: T.untyped,
96
+ expected_value: T.untyped).returns(T::Hash[Symbol, T::Boolean])
97
+ end
95
98
  def radio_button_options(prefilled, checked_value, expected_value)
96
99
  (prefilled && checked_value == expected_value) ? {checked: true} : {}
97
100
  end
@@ -136,7 +139,11 @@ module ChobbleForms
136
139
  i18n_base = T.unsafe(instance_variable_get(:@_current_i18n_base))
137
140
 
138
141
  # Only strip _pass suffix for pass/fail fields, not _comment fields
139
- lookup_field = field.to_s.end_with?("_pass") ? FieldUtils.strip_field_suffix(field) : field
142
+ lookup_field = if field.to_s.end_with?("_pass")
143
+ FieldUtils.strip_field_suffix(field)
144
+ else
145
+ field
146
+ end
140
147
  fields_key = "#{i18n_base}.fields.#{lookup_field}"
141
148
  field_label = t(fields_key, raise: true)
142
149
 
@@ -152,7 +159,10 @@ module ChobbleForms
152
159
  }
153
160
  end
154
161
 
155
- sig { params(field_translations: T::Hash[Symbol, T.nilable(String)], value: T.untyped, prefilled: T::Boolean).returns(FieldSetupResult) }
162
+ sig do
163
+ params(field_translations: T::Hash[Symbol, T.nilable(String)], value: T.untyped,
164
+ prefilled: T::Boolean).returns(FieldSetupResult)
165
+ end
156
166
  def build_field_setup_result(field_translations, value, prefilled)
157
167
  form_obj = T.unsafe(instance_variable_get(:@_current_form))
158
168
  i18n_base = T.unsafe(instance_variable_get(:@_current_i18n_base))
@@ -168,21 +178,28 @@ module ChobbleForms
168
178
  )
169
179
  end
170
180
 
181
+ sig { params(model: T.untyped, field: Symbol, raise_if_missing: T::Boolean).returns(T.untyped) }
182
+ def get_field_value_from_model(model, field, raise_if_missing: false)
183
+ return nil unless model
184
+
185
+ # Check for base field first (for fields like step_ramp_size that have a base value)
186
+ # Only check for _pass suffix if base field doesn't exist (for pass_fail_comment partials)
187
+ if model.respond_to?(field)
188
+ model.send(field)
189
+ elsif model.respond_to?("#{field}_pass")
190
+ model.send("#{field}_pass")
191
+ elsif raise_if_missing
192
+ available = model.attributes.keys.sort.join(", ")
193
+ raise "Field '#{field}' or '#{field}_pass' not found on " \
194
+ "#{model.class.name}. Available fields: #{available}"
195
+ end
196
+ end
197
+
171
198
  sig { params(model: T.untyped, field: Symbol).returns({value: T.untyped, prefilled: T::Boolean}) }
172
199
  def resolve_field_value(model, field)
173
- field_str = field.to_s
200
+ return {value: nil, prefilled: false} if field.to_s.include?("password")
174
201
 
175
- return {value: nil, prefilled: false} if field_str.include?("password")
176
-
177
- # For composite partials, we receive the base field but need to check for suffixed fields
178
- # Check for _pass field first (in case both base and _pass exist)
179
- if model.respond_to?("#{field}_pass")
180
- current_value = model.send("#{field}_pass")
181
- elsif model.respond_to?(field)
182
- current_value = model.send(field)
183
- else
184
- raise "Field '#{field}' or '#{field}_pass' not found on #{model.class.name}. Available fields: #{model.attributes.keys.sort.join(", ")}"
185
- end
202
+ current_value = get_field_value_from_model(model, field, raise_if_missing: true)
186
203
 
187
204
  # Check if this field should not be prefilled based on excluded fields list
188
205
  excluded_fields = T.unsafe(instance_variable_get(:@_excluded_prefill_fields))
@@ -198,11 +215,7 @@ module ChobbleForms
198
215
  }
199
216
  end
200
217
 
201
- if field_str.end_with?("_id") && field_str != "id"
202
- resolve_association_value(model, field_str)
203
- else
204
- {value: current_value, prefilled: false}
205
- end
218
+ {value: current_value, prefilled: false}
206
219
  end
207
220
 
208
221
  sig { params(previous_inspection: T.untyped, current_model: T.untyped, field: Symbol).returns(T.untyped) }
@@ -212,7 +225,7 @@ module ChobbleForms
212
225
  elsif current_model.class.name.include?("Assessment")
213
226
  assessment_type = current_model.class.name.demodulize.underscore
214
227
  previous_model = previous_inspection.send(assessment_type)
215
- previous_model&.send(field)
228
+ get_field_value_from_model(previous_model, field, raise_if_missing: false)
216
229
  else
217
230
  previous_inspection.send(field)
218
231
  end
@@ -2,5 +2,5 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  module ChobbleForms
5
- VERSION = "0.7.1"
5
+ VERSION = "0.7.2"
6
6
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chobble-forms
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.1
4
+ version: 0.7.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chobble.com
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2025-08-16 00:00:00.000000000 Z
11
+ date: 2025-08-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails