deco_lite 1.5.2 → 1.5.3

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: b7c43249616f91c50aa1452769ec55d957ff8dd280823202bcae9c35d64cf036
4
- data.tar.gz: 0e99b572d6e8a8d4f1c0070a9a24f76acf5b0d31b9fa89af2fc87da5cccbe2a2
3
+ metadata.gz: c26b97b5df895f19c475e9938b9e039a263ef83f582b57a378d57fb5c2d26a7f
4
+ data.tar.gz: cb1a17c08179e046e2fd18df1f099e4517a08f34b0adbfce6e020a416d2bc277
5
5
  SHA512:
6
- metadata.gz: ff288dbc7abe43674ce30bf7008346151ea486cbbaf1ebf43852ae47cf1a8dc5d723ddc7b04355f96b8762f29a0aa8521951ed1834e58d33e30e9b6ae074a198
7
- data.tar.gz: 393764155f69b9e73e19581d53c0020dc65f01052cd62e577d78bf10499f4ca804129cd39582df018d523957873966ae6922b4c8b90b51e727c670e86f89e260
6
+ metadata.gz: 5e57bff0adf35ede242683dff40b2c3dcd0158ee61474fe974eabcee330bb7467437aa43c1b06842ce2c0a87a22992557b7c512f6f1d87cc789fbc980096dd9a
7
+ data.tar.gz: 539400e71d0ecfefedf2f02c13d1d88026527c6cb0a334a76acc3521c4c0a573b52fcbca34c98d79c88e96459733bac60a3d0b8b5b1af828b011662034e8e617
data/CHANGELOG.md CHANGED
@@ -1,3 +1,10 @@
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.
1
8
  ### 1.5.2
2
9
  * Changes
3
10
  * Update ruby gems. Remedy activesupport dependabot alert.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- deco_lite (1.5.2)
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)
@@ -23,7 +23,7 @@ GEM
23
23
  concurrent-ruby (1.2.2)
24
24
  diff-lcs (1.5.0)
25
25
  docile (1.4.0)
26
- i18n (1.12.0)
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)
@@ -33,8 +33,8 @@ GEM
33
33
  immutable_struct_ex (~> 0.2.0)
34
34
  method_source (1.0.0)
35
35
  minitest (5.18.0)
36
- parallel (1.22.1)
37
- parser (3.2.1.1)
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,39 +48,39 @@ GEM
48
48
  kwalify (~> 0.7.0)
49
49
  parser (~> 3.2.0)
50
50
  rainbow (>= 2.0, < 4.0)
51
- regexp_parser (2.7.0)
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.1)
57
+ rspec-core (3.12.2)
58
58
  rspec-support (~> 3.12.0)
59
- rspec-expectations (3.12.2)
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.4)
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.48.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.26.0, < 2.0)
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.27.0)
76
+ rubocop-ast (1.28.1)
77
77
  parser (>= 3.2.1.0)
78
- rubocop-capybara (2.17.1)
78
+ rubocop-capybara (2.18.0)
79
79
  rubocop (~> 1.41)
80
- rubocop-performance (1.16.0)
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.19.0)
83
+ rubocop-rspec (2.20.0)
84
84
  rubocop (~> 1.33)
85
85
  rubocop-capybara (~> 2.17)
86
86
  ruby-progressbar (1.13.0)
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. However, be aware that any attribute (field) having an *explicit validation* associated with it, will automatically cause an `attr_accessor` to be created for that field; this is to avoid `NoMethodErrors` when validating the model (e.g. `#valid?`, `#validate`, etc.) *before* the data is loaded that would prompt the creation of the associated `attr_accessors` on the model:
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.map(&:attributes)
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
 
@@ -2,5 +2,5 @@
2
2
 
3
3
  # Defines the version of this gem.
4
4
  module DecoLite
5
- VERSION = '1.5.2'
5
+ VERSION = '1.5.3'
6
6
  end
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.2
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-03-22 00:00:00.000000000 Z
11
+ date: 2023-05-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel