deco_lite 1.5.1 → 1.5.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +11 -0
- data/Gemfile.lock +20 -20
- data/README.md +9 -1
- data/lib/deco_lite/fields_auto_attr_accessable.rb +14 -1
- data/lib/deco_lite/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: c26b97b5df895f19c475e9938b9e039a263ef83f582b57a378d57fb5c2d26a7f
|
4
|
+
data.tar.gz: cb1a17c08179e046e2fd18df1f099e4517a08f34b0adbfce6e020a416d2bc277
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5e57bff0adf35ede242683dff40b2c3dcd0158ee61474fe974eabcee330bb7467437aa43c1b06842ce2c0a87a22992557b7c512f6f1d87cc789fbc980096dd9a
|
7
|
+
data.tar.gz: 539400e71d0ecfefedf2f02c13d1d88026527c6cb0a334a76acc3521c4c0a573b52fcbca34c98d79c88e96459733bac60a3d0b8b5b1af828b011662034e8e617
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,14 @@
|
|
1
|
+
### 1.5.3
|
2
|
+
* Bugs
|
3
|
+
* Fix bug that raised an exception when using `validates_with <Custom Validator>` because `#attributes` is not found on custom validators.
|
4
|
+
* Changes
|
5
|
+
* You can now use `validates_with <Custom Validator>` by passing the attribute name(s) to your custom validator via the `#options` hash with a key of `:attributes` OR `:fields`. For example: `validates_with MyCustomValidator, attributes: %i[field1 field2]` of `validates_with MyCustomValidator, fields: %i[field1 field2]`
|
6
|
+
* Updated README.md for the above change.
|
7
|
+
* Update bundled gems.
|
8
|
+
### 1.5.2
|
9
|
+
* Changes
|
10
|
+
* Update ruby gems. Remedy activesupport dependabot alert.
|
11
|
+
|
1
12
|
### 1.5.1
|
2
13
|
* Changes
|
3
14
|
* Update ruby gems.
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
deco_lite (1.5.
|
4
|
+
deco_lite (1.5.3)
|
5
5
|
activemodel (~> 7.0, >= 7.0.3.1)
|
6
6
|
activesupport (~> 7.0, >= 7.0.3.1)
|
7
7
|
immutable_struct_ex (~> 0.2.0)
|
@@ -10,9 +10,9 @@ PATH
|
|
10
10
|
GEM
|
11
11
|
remote: https://rubygems.org/
|
12
12
|
specs:
|
13
|
-
activemodel (7.0.4.
|
14
|
-
activesupport (= 7.0.4.
|
15
|
-
activesupport (7.0.4.
|
13
|
+
activemodel (7.0.4.3)
|
14
|
+
activesupport (= 7.0.4.3)
|
15
|
+
activesupport (7.0.4.3)
|
16
16
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
17
17
|
i18n (>= 1.6, < 2)
|
18
18
|
minitest (>= 5.1)
|
@@ -20,10 +20,10 @@ GEM
|
|
20
20
|
ast (2.4.2)
|
21
21
|
byebug (11.1.3)
|
22
22
|
coderay (1.1.3)
|
23
|
-
concurrent-ruby (1.2.
|
23
|
+
concurrent-ruby (1.2.2)
|
24
24
|
diff-lcs (1.5.0)
|
25
25
|
docile (1.4.0)
|
26
|
-
i18n (1.
|
26
|
+
i18n (1.13.0)
|
27
27
|
concurrent-ruby (~> 1.0)
|
28
28
|
immutable_struct_ex (0.2.3)
|
29
29
|
json (2.6.3)
|
@@ -32,9 +32,9 @@ GEM
|
|
32
32
|
activesupport (~> 7.0, >= 7.0.3.1)
|
33
33
|
immutable_struct_ex (~> 0.2.0)
|
34
34
|
method_source (1.0.0)
|
35
|
-
minitest (5.
|
36
|
-
parallel (1.
|
37
|
-
parser (3.2.1
|
35
|
+
minitest (5.18.0)
|
36
|
+
parallel (1.23.0)
|
37
|
+
parser (3.2.2.1)
|
38
38
|
ast (~> 2.4.1)
|
39
39
|
pry (0.14.2)
|
40
40
|
coderay (~> 1.1)
|
@@ -48,42 +48,42 @@ GEM
|
|
48
48
|
kwalify (~> 0.7.0)
|
49
49
|
parser (~> 3.2.0)
|
50
50
|
rainbow (>= 2.0, < 4.0)
|
51
|
-
regexp_parser (2.
|
51
|
+
regexp_parser (2.8.0)
|
52
52
|
rexml (3.2.5)
|
53
53
|
rspec (3.12.0)
|
54
54
|
rspec-core (~> 3.12.0)
|
55
55
|
rspec-expectations (~> 3.12.0)
|
56
56
|
rspec-mocks (~> 3.12.0)
|
57
|
-
rspec-core (3.12.
|
57
|
+
rspec-core (3.12.2)
|
58
58
|
rspec-support (~> 3.12.0)
|
59
|
-
rspec-expectations (3.12.
|
59
|
+
rspec-expectations (3.12.3)
|
60
60
|
diff-lcs (>= 1.2.0, < 2.0)
|
61
61
|
rspec-support (~> 3.12.0)
|
62
|
-
rspec-mocks (3.12.
|
62
|
+
rspec-mocks (3.12.5)
|
63
63
|
diff-lcs (>= 1.2.0, < 2.0)
|
64
64
|
rspec-support (~> 3.12.0)
|
65
65
|
rspec-support (3.12.0)
|
66
|
-
rubocop (1.
|
66
|
+
rubocop (1.50.2)
|
67
67
|
json (~> 2.3)
|
68
68
|
parallel (~> 1.10)
|
69
69
|
parser (>= 3.2.0.0)
|
70
70
|
rainbow (>= 2.2.2, < 4.0)
|
71
71
|
regexp_parser (>= 1.8, < 3.0)
|
72
72
|
rexml (>= 3.2.5, < 4.0)
|
73
|
-
rubocop-ast (>= 1.
|
73
|
+
rubocop-ast (>= 1.28.0, < 2.0)
|
74
74
|
ruby-progressbar (~> 1.7)
|
75
75
|
unicode-display_width (>= 2.4.0, < 3.0)
|
76
|
-
rubocop-ast (1.
|
76
|
+
rubocop-ast (1.28.1)
|
77
77
|
parser (>= 3.2.1.0)
|
78
|
-
rubocop-capybara (2.
|
78
|
+
rubocop-capybara (2.18.0)
|
79
79
|
rubocop (~> 1.41)
|
80
|
-
rubocop-performance (1.
|
80
|
+
rubocop-performance (1.17.1)
|
81
81
|
rubocop (>= 1.7.0, < 2.0)
|
82
82
|
rubocop-ast (>= 0.4.0)
|
83
|
-
rubocop-rspec (2.
|
83
|
+
rubocop-rspec (2.20.0)
|
84
84
|
rubocop (~> 1.33)
|
85
85
|
rubocop-capybara (~> 2.17)
|
86
|
-
ruby-progressbar (1.
|
86
|
+
ruby-progressbar (1.13.0)
|
87
87
|
simplecov (0.21.2)
|
88
88
|
docile (~> 1.1)
|
89
89
|
simplecov-html (~> 0.11)
|
data/README.md
CHANGED
@@ -176,12 +176,20 @@ model.wife_info_address #=> 1 street, boonton, nj 07005
|
|
176
176
|
|
177
177
|
#### Add validators to my model
|
178
178
|
|
179
|
-
Simply add your `ActiveModel` validators just like you would any other `ActiveModel::Model` validator.
|
179
|
+
Simply add your `ActiveModel` validators just like you would any other `ActiveModel::Model` validator, with one caveat noted below. It is important to note that any attribute (field) having an *explicit validation* associated with it, will automatically cause `DecoLite` to create an `attr_accessor` for that field; this is to avoid `NoMethodErrors` when validating the model (e.g. `#valid?`, `#validate`, etc.) *before* the data is loaded. Why does `DecoLite` need to do this? Typically, `DecoLite` dynamically creates `attr_accessors` using the keys from the `Hash` loaded into the model. If the `Hash` loaded into your `DecoLite` model _does not_ include a `Hash` key for the attribute referenced by any validators on your model, `DecoLite` will not create an `attr_accessor` for it; consequently, calling any validation method (e.g. `#valid?`, `#validate`, etc.) on your model will result in a `NoMethodError` for that attribute.
|
180
|
+
|
181
|
+
One caveat to note is when using Rails custom validators with `validates_with`. When using Rails custom validators via `validates_with`, you should pass the attribute names being validated to your custom validator via the `#options` `Hash` with a key of either `:attributes` or `:fields`. This is so that `DecoLite` can create dynamic `attr_accessors` for these attributes and avoid the aformentioned `NoMethodError` (see above):
|
180
182
|
|
181
183
|
```ruby
|
182
184
|
class Model < DecoLite::Model
|
183
185
|
validates :first, :last, :address, presence: true
|
184
186
|
validates :age, numericality: true
|
187
|
+
# When using Rails custom validators via validates_with,
|
188
|
+
# pass the attribute name(s) being validated in an Array
|
189
|
+
# via the #options Hash, with a key of either :attributes
|
190
|
+
# or :fields. For example:
|
191
|
+
validates_with CustomFirstNameValidator, attributes: [:first]
|
192
|
+
validates_with CustomAgeValidator, fields: [:age]
|
185
193
|
end
|
186
194
|
|
187
195
|
# :address is missing
|
@@ -15,7 +15,20 @@ module DecoLite
|
|
15
15
|
def auto_attr_accessors
|
16
16
|
return @auto_attr_accessors.dup if defined?(@auto_attr_accessors)
|
17
17
|
|
18
|
-
@auto_attr_accessors = self.class.validators.
|
18
|
+
@auto_attr_accessors = self.class.validators.filter_map do |validator|
|
19
|
+
if validator.respond_to?(:attributes)
|
20
|
+
validator.attributes
|
21
|
+
elsif validator.respond_to?(:options)
|
22
|
+
# This path handles the case where the validator is a custom validator
|
23
|
+
# (i.e. `validates_with MyCustomValidator`). deco_lite in this case, has
|
24
|
+
# no way of knowing what fields are being validated, so we have to rely
|
25
|
+
# on the user to tell us what fields are being validated by passing
|
26
|
+
# the attributes to validate in the #options hash. For example:
|
27
|
+
# `validates_with MyCustomValidator, attributes: %i[field1 field2]`)
|
28
|
+
# `validates_with MyCustomValidator, fields: %i[field1 field2]`)
|
29
|
+
validator.options[:attributes].presence || validator.options[:fields].presence
|
30
|
+
end
|
31
|
+
end
|
19
32
|
@auto_attr_accessors = auto_attr_accessors_assign
|
20
33
|
end
|
21
34
|
|
data/lib/deco_lite/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: deco_lite
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.5.
|
4
|
+
version: 1.5.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gene M. Angelo, Jr.
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-05-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|