chobble-forms 0.5.6 → 0.6.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 38897550927a4c901cada28fbe5f63e8447bf108e6eb3bedf5d045807e45c245
4
- data.tar.gz: ede19464d42338a4834967dda6a1df1048d2bef39599ddd89e079256c796ec15
3
+ metadata.gz: 32610a1903913985762082f5865bd24bfcae7327bf887cafa70c09db7efe9e88
4
+ data.tar.gz: 4d0e15de04ab8ceee7fac1fea871d83582caf5bc96e4cc39760ef7e1297c8915
5
5
  SHA512:
6
- metadata.gz: c24eca1ed04bf5d7cbbe7d483451368ef3b636d3d0d42018e967a5f22ddbee88e4c7c8d2c5a7f6f104828af570610d395342bb05fad838c5366f4b84edd186db
7
- data.tar.gz: b486d795a2b856e0895b4736901f52fede072e35319acb7511aaef5b007919e8af5ea644365c34ef30839f0f36301a247fe0b791a5a12c98318ebdd078c11649
6
+ metadata.gz: c70cbe6796e0edba08b2c41c5e476401d4579cc86de865710a772c0f4ef570abacd76f4ec08033d1d405ef887cdf44b52aa5f4e82c07085270c28186f5fb7532
7
+ data.tar.gz: d9b8cc2aff3b86e9de10b189a44f2d2a9f651a236b87da01dd0095bc27fb81b8ea034f14d72655ae580fa4cd26a777674c3a2db78225769eca42af134e176208
data/README.md CHANGED
@@ -18,36 +18,20 @@ bundle install
18
18
 
19
19
  ## Type Safety with Sorbet
20
20
 
21
- ChobbleForms uses Sorbet for static type checking, providing improved type safety and better IDE support. All library files use `typed: strict` with comprehensive type signatures.
21
+ ChobbleForms is fully typed with Sorbet (`typed: strict`) providing compile-time type safety and runtime validation. All field parameters must be symbols for a clean, consistent API.
22
22
 
23
23
  ### Type Checking
24
24
 
25
- Run type checking with:
26
-
27
25
  ```bash
28
26
  bundle exec srb tc
29
27
  ```
30
28
 
31
- Or use the provided Rake task:
32
-
33
- ```bash
34
- bundle exec rake typecheck
35
- ```
36
-
37
29
  ### Development Setup
38
30
 
39
- For contributors working on this gem:
40
-
41
31
  1. Install dependencies: `bundle install`
42
32
  2. Generate RBI files: `bundle exec rake sorbet_rbi`
43
33
  3. Run type checking: `bundle exec rake typecheck`
44
34
 
45
- All methods have full type signatures, providing:
46
- - Static type checking at development time
47
- - Runtime type validation
48
- - Better IDE autocomplete and documentation
49
- - Early detection of type mismatches
50
-
51
35
  ## CSS Styles
52
36
 
53
37
  ChobbleForms includes CSS for styling the form components. To use the included styles, add this to your application.css:
@@ -1,13 +1,20 @@
1
- # typed: false
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ require "sorbet-runtime"
2
5
 
3
6
  module ChobbleForms
4
7
  module FieldUtils
8
+ extend T::Sig
9
+
10
+ sig { params(field: Symbol).returns(String) }
5
11
  def self.strip_field_suffix(field)
6
12
  field.to_s.gsub(/_pass$|_comment$/, "")
7
13
  end
8
14
 
15
+ sig { params(field: Symbol, partial: Symbol).returns(T::Array[String]) }
9
16
  def self.get_composite_fields(field, partial)
10
- fields = []
17
+ fields = T.let([], T::Array[String])
11
18
  partial_str = partial.to_s
12
19
 
13
20
  if partial_str.include?("pass_fail") && !field.to_s.end_with?("_pass")
@@ -22,22 +29,27 @@ module ChobbleForms
22
29
  fields
23
30
  end
24
31
 
32
+ sig { params(field: Symbol).returns(T::Boolean) }
25
33
  def self.is_pass_field?(field)
26
34
  field.to_s.end_with?("_pass")
27
35
  end
28
36
 
37
+ sig { params(field: Symbol).returns(T::Boolean) }
29
38
  def self.is_comment_field?(field)
30
39
  field.to_s.end_with?("_comment")
31
40
  end
32
41
 
42
+ sig { params(field: Symbol).returns(T::Boolean) }
33
43
  def self.is_composite_field?(field)
34
44
  is_pass_field?(field) || is_comment_field?(field)
35
45
  end
36
46
 
47
+ sig { params(field: Symbol).returns(String) }
37
48
  def self.base_field_name(field)
38
49
  strip_field_suffix(field)
39
50
  end
40
51
 
52
+ sig { params(form: Symbol, field: Symbol).returns(String) }
41
53
  def self.form_field_label(form, field)
42
54
  I18n.t("forms.#{form}.fields.#{field}")
43
55
  end
@@ -7,7 +7,7 @@ module ChobbleForms
7
7
  module Helpers
8
8
  extend T::Sig
9
9
 
10
- sig { params(field: T.any(Symbol, String), local_assigns: T::Hash[Symbol, T.untyped]).returns(T::Hash[Symbol, T.untyped]) }
10
+ sig { params(field: Symbol, local_assigns: T::Hash[Symbol, T.untyped]).returns(T::Hash[Symbol, T.untyped]) }
11
11
  def form_field_setup(field, local_assigns)
12
12
  validate_local_assigns(local_assigns)
13
13
  validate_form_context
@@ -19,7 +19,7 @@ module ChobbleForms
19
19
  build_field_setup_result(field_translations, value, prefilled)
20
20
  end
21
21
 
22
- sig { params(form_object: T.untyped, field: T.any(Symbol, String)).returns([T.untyped, T::Boolean]) }
22
+ sig { params(form_object: T.untyped, field: Symbol).returns([T.untyped, T::Boolean]) }
23
23
  def get_field_value_and_prefilled_status(form_object, field)
24
24
  return [nil, false] unless form_object&.object
25
25
  model = form_object.object
@@ -27,7 +27,7 @@ module ChobbleForms
27
27
  [resolved[:value], resolved[:prefilled]]
28
28
  end
29
29
 
30
- sig { params(form: T.untyped, comment_field: T.any(Symbol, String), base_field_label: String).returns(T::Hash[Symbol, T.untyped]) }
30
+ sig { params(form: T.untyped, comment_field: Symbol, base_field_label: String).returns(T::Hash[Symbol, T.untyped]) }
31
31
  def comment_field_options(form, comment_field, base_field_label)
32
32
  raise ArgumentError, "form_object required" unless form
33
33
  model = form.object
@@ -106,7 +106,7 @@ module ChobbleForms
106
106
  raise ArgumentError, "missing form_object" unless form_obj
107
107
  end
108
108
 
109
- sig { params(field: T.any(Symbol, String)).returns(T::Hash[Symbol, T.nilable(String)]) }
109
+ sig { params(field: Symbol).returns(T::Hash[Symbol, T.nilable(String)]) }
110
110
  def build_field_translations(field)
111
111
  i18n_base = T.unsafe(instance_variable_get(:@_current_i18n_base))
112
112
  fields_key = "#{i18n_base}.fields.#{field}"
@@ -137,29 +137,24 @@ module ChobbleForms
137
137
  }.merge(field_translations)
138
138
  end
139
139
 
140
- sig { params(model: T.untyped, field: T.any(Symbol, String)).returns(T::Hash[Symbol, T.untyped]) }
140
+ sig { params(model: T.untyped, field: Symbol).returns(T::Hash[Symbol, T.untyped]) }
141
141
  def resolve_field_value(model, field)
142
142
  field_str = field.to_s
143
143
 
144
- # Never return values for password fields
145
144
  if field_str.include?("password")
146
145
  return {value: nil, prefilled: false}
147
146
  end
148
147
 
149
- # Check current model value
150
148
  current_value = model.send(field) if model.respond_to?(field)
151
149
 
152
- # Check if this field should be excluded from prefilling
153
150
  if defined?(InspectionsController::NOT_COPIED_FIELDS) &&
154
151
  InspectionsController::NOT_COPIED_FIELDS.include?(field_str)
155
152
  return {value: current_value, prefilled: false}
156
153
  end
157
154
 
158
- # Extract previous value if available
159
155
  prev_inspection = T.unsafe(instance_variable_get(:@previous_inspection))
160
156
  previous_value = extract_previous_value(prev_inspection, model, field)
161
157
 
162
- # Return previous value if current is nil and previous exists
163
158
  if current_value.nil? && !previous_value.nil?
164
159
  return {
165
160
  value: format_numeric_value(previous_value),
@@ -170,12 +165,11 @@ module ChobbleForms
170
165
  if field_str.end_with?("_id") && field_str != "id"
171
166
  resolve_association_value(model, field_str)
172
167
  else
173
- # Always return current value, even if nil
174
168
  {value: current_value, prefilled: false}
175
169
  end
176
170
  end
177
171
 
178
- sig { params(previous_inspection: T.untyped, current_model: T.untyped, field: T.any(Symbol, String)).returns(T.untyped) }
172
+ sig { params(previous_inspection: T.untyped, current_model: T.untyped, field: Symbol).returns(T.untyped) }
179
173
  def extract_previous_value(previous_inspection, current_model, field)
180
174
  if !previous_inspection
181
175
  nil
@@ -2,5 +2,5 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  module ChobbleForms
5
- VERSION = "0.5.6"
5
+ VERSION = "0.6.0"
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.5.6
4
+ version: 0.6.0
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-12 00:00:00.000000000 Z
11
+ date: 2025-08-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails