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 +4 -4
- data/README.md +1 -17
- data/lib/chobble_forms/field_utils.rb +14 -2
- data/lib/chobble_forms/helpers.rb +6 -12
- data/lib/chobble_forms/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 32610a1903913985762082f5865bd24bfcae7327bf887cafa70c09db7efe9e88
|
4
|
+
data.tar.gz: 4d0e15de04ab8ceee7fac1fea871d83582caf5bc96e4cc39760ef7e1297c8915
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
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:
|
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:
|
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:
|
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:
|
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:
|
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:
|
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:
|
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
|
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.
|
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-
|
11
|
+
date: 2025-08-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|