active_interaction 4.0.6 → 5.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (79) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +156 -7
  3. data/CONTRIBUTING.md +11 -3
  4. data/README.md +260 -219
  5. data/lib/active_interaction/array_input.rb +77 -0
  6. data/lib/active_interaction/base.rb +14 -98
  7. data/lib/active_interaction/concerns/active_recordable.rb +3 -3
  8. data/lib/active_interaction/concerns/missable.rb +2 -2
  9. data/lib/active_interaction/errors.rb +6 -88
  10. data/lib/active_interaction/exceptions.rb +47 -0
  11. data/lib/active_interaction/filter/column.rb +59 -0
  12. data/lib/active_interaction/filter/error.rb +40 -0
  13. data/lib/active_interaction/filter.rb +44 -53
  14. data/lib/active_interaction/filters/abstract_date_time_filter.rb +9 -6
  15. data/lib/active_interaction/filters/abstract_numeric_filter.rb +7 -3
  16. data/lib/active_interaction/filters/array_filter.rb +40 -6
  17. data/lib/active_interaction/filters/boolean_filter.rb +4 -3
  18. data/lib/active_interaction/filters/date_filter.rb +1 -1
  19. data/lib/active_interaction/filters/date_time_filter.rb +1 -1
  20. data/lib/active_interaction/filters/decimal_filter.rb +1 -1
  21. data/lib/active_interaction/filters/float_filter.rb +1 -1
  22. data/lib/active_interaction/filters/hash_filter.rb +23 -15
  23. data/lib/active_interaction/filters/integer_filter.rb +1 -1
  24. data/lib/active_interaction/filters/interface_filter.rb +12 -12
  25. data/lib/active_interaction/filters/object_filter.rb +9 -3
  26. data/lib/active_interaction/filters/record_filter.rb +21 -11
  27. data/lib/active_interaction/filters/string_filter.rb +1 -1
  28. data/lib/active_interaction/filters/symbol_filter.rb +1 -1
  29. data/lib/active_interaction/filters/time_filter.rb +4 -4
  30. data/lib/active_interaction/hash_input.rb +43 -0
  31. data/lib/active_interaction/input.rb +23 -0
  32. data/lib/active_interaction/inputs.rb +161 -46
  33. data/lib/active_interaction/locale/en.yml +0 -1
  34. data/lib/active_interaction/locale/fr.yml +0 -1
  35. data/lib/active_interaction/locale/it.yml +0 -1
  36. data/lib/active_interaction/locale/ja.yml +0 -1
  37. data/lib/active_interaction/locale/pt-BR.yml +0 -1
  38. data/lib/active_interaction/modules/validation.rb +6 -17
  39. data/lib/active_interaction/version.rb +1 -1
  40. data/lib/active_interaction.rb +41 -36
  41. data/spec/active_interaction/array_input_spec.rb +166 -0
  42. data/spec/active_interaction/base_spec.rb +34 -248
  43. data/spec/active_interaction/concerns/active_modelable_spec.rb +3 -3
  44. data/spec/active_interaction/concerns/active_recordable_spec.rb +7 -7
  45. data/spec/active_interaction/concerns/hashable_spec.rb +8 -8
  46. data/spec/active_interaction/concerns/missable_spec.rb +9 -9
  47. data/spec/active_interaction/concerns/runnable_spec.rb +34 -32
  48. data/spec/active_interaction/errors_spec.rb +60 -43
  49. data/spec/active_interaction/{filter_column_spec.rb → filter/column_spec.rb} +3 -10
  50. data/spec/active_interaction/filter_spec.rb +6 -6
  51. data/spec/active_interaction/filters/abstract_date_time_filter_spec.rb +2 -2
  52. data/spec/active_interaction/filters/abstract_numeric_filter_spec.rb +2 -2
  53. data/spec/active_interaction/filters/array_filter_spec.rb +109 -16
  54. data/spec/active_interaction/filters/boolean_filter_spec.rb +12 -11
  55. data/spec/active_interaction/filters/date_filter_spec.rb +32 -27
  56. data/spec/active_interaction/filters/date_time_filter_spec.rb +34 -29
  57. data/spec/active_interaction/filters/decimal_filter_spec.rb +20 -18
  58. data/spec/active_interaction/filters/file_filter_spec.rb +7 -7
  59. data/spec/active_interaction/filters/float_filter_spec.rb +19 -17
  60. data/spec/active_interaction/filters/hash_filter_spec.rb +16 -18
  61. data/spec/active_interaction/filters/integer_filter_spec.rb +24 -22
  62. data/spec/active_interaction/filters/interface_filter_spec.rb +105 -82
  63. data/spec/active_interaction/filters/object_filter_spec.rb +52 -36
  64. data/spec/active_interaction/filters/record_filter_spec.rb +61 -39
  65. data/spec/active_interaction/filters/string_filter_spec.rb +7 -7
  66. data/spec/active_interaction/filters/symbol_filter_spec.rb +6 -6
  67. data/spec/active_interaction/filters/time_filter_spec.rb +57 -34
  68. data/spec/active_interaction/hash_input_spec.rb +58 -0
  69. data/spec/active_interaction/i18n_spec.rb +22 -17
  70. data/spec/active_interaction/inputs_spec.rb +170 -18
  71. data/spec/active_interaction/integration/array_interaction_spec.rb +3 -7
  72. data/spec/active_interaction/integration/record_integration_spec.rb +5 -0
  73. data/spec/active_interaction/modules/validation_spec.rb +8 -31
  74. data/spec/spec_helper.rb +9 -0
  75. data/spec/support/concerns.rb +2 -2
  76. data/spec/support/filters.rb +27 -51
  77. data/spec/support/interactions.rb +4 -4
  78. metadata +50 -50
  79. data/lib/active_interaction/filter_column.rb +0 -57
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8ea0d31fc8d2cf65540edb64cc51b1b3a31205a5f4a179fd56ecdb1606d84c9f
4
- data.tar.gz: fd79ef266a8357bad053b282068b0fe5bfb3cf677f778b97ebe373b7c9c9a216
3
+ metadata.gz: c740eef14e1c0bca42f4bbb5b3718c879bc3af038f40953a60a53007611916e5
4
+ data.tar.gz: b0a3738aa38869c7be559d72f23e958d0f9e66c0f490652bd8a92e1ef449e48e
5
5
  SHA512:
6
- metadata.gz: d4070194c1bcf654043c65e340abf6a1be0977282c214636511cb5188cace08a81a34ef811f9d3a369b7dc10a8ce8fcdda6a563c69fe34435fef6618c67dc5b7
7
- data.tar.gz: 446e6ccc7f28132c70808817b3db99b5852486f1c097212aea861db4235da1df676c1cd3751019425a34f84b6590b9c06e954b31ae3c8dc32cf0843ea3c7d326
6
+ metadata.gz: f998483eb21ec13a43dcf3c7b6805f7865b3dd7b4d8fbc9846263338d676c41c7991a602dd3a82e13a9b93a027cbeccd5648a87fef688964124935d38d9ef6c4
7
+ data.tar.gz: 4669a1e76a427af4a62415f242bfdc3fa45f7a63c5a43de704b7849639841f365e83168b5c1db68ab067ca2104f8f7ec580baa487e5caa6035196607033c79f8
data/CHANGELOG.md CHANGED
@@ -1,38 +1,180 @@
1
+ # [5.1.0][] (2022-07-28)
2
+
3
+ ## Added
4
+
5
+ - Limit dependencies to the minimum requirements.
6
+
7
+ ## Fixed
8
+
9
+ - [#536][] - `compose` accepts `Inputs`.
10
+ - [#537][] - Arrays with nested filters returned the wrong value.
11
+
12
+ # [5.0.0][] (2022-06-24)
13
+
14
+ ## Changed
15
+
16
+ - Drop support for JRuby.
17
+ - Drop support for Ruby 2.5 and 2.6, adding support for 3.1
18
+ - Drop support for Rails 5.0 and 5.1
19
+ - `ActiveInteraction::Inputs` no longer inherits from `Hash` though it still has most of the methods
20
+ provided by `Hash` (methods that write were removed).
21
+ - Removed `Filter#clean` (use `Filter#process` and call `#value` on the result)
22
+ - The `given?` method has been moved onto `inputs`. ([how to upgrade](#given))
23
+ - [#503][] - The record filter now treats blank strings value as `nil`. This was missed in the 4.0 update.
24
+ - The `type_check` callback has been renamed to `filter` to better match the reality of what it does.
25
+ ([how to upgrade](#filter-callback))
26
+ - `ActiveIneraction::FilterColumn` is now `ActiveInteraction::Filter::Column`
27
+ - Errors on the array filter will now be indexed if the Rails config `index_nested_attribute_errors`
28
+ is `true` or the `:index_errors` option is set to `true`. The `:index_errors` option always overrides
29
+ the Rails config.
30
+ - Invalid nested errors (`:invalid_nested`) are gone. Instead the nested errors will appear as they would
31
+ in Rails if they were a `has_many` relationship being assigned attributes through a parent.
32
+ ([how to upgrade](#nested-hash-errors))
33
+
34
+ ## Added
35
+
36
+ - `Filter#process` which returns an `Input`.
37
+
38
+ ## Fixed
39
+
40
+ - When passing an `ActiveRecord::Relation` in an array filter with no inner
41
+ filter, the value returned was an `ActiveRecord::Relation` instead of an
42
+ Array.
43
+
44
+ ## Upgrading
45
+
46
+ ### `given?`
47
+
48
+ The `given?` method can now be found on `inputs`. It works the same as before.
49
+
50
+ ```ruby
51
+ # 4.1
52
+ class Example < ActiveInteraction::Base
53
+ string :name, default: nil
54
+
55
+ def execute
56
+ given?(:name)
57
+ end
58
+ end
59
+
60
+ # 5.0
61
+ class Example < ActiveInteraction::Base
62
+ string :name, default: nil
63
+
64
+ def execute
65
+ inputs.given?(:name)
66
+ end
67
+ end
68
+ ```
69
+
70
+ ### Filter Callback
71
+
72
+ You'll need to rename any `:type_check` callbacks to `:filter`.
73
+
74
+ ```ruby
75
+ # 4.1
76
+ set_callback :type_check, :before, -> { puts 'before type check' }
77
+
78
+ # 5.0
79
+ set_callback :filter, :before, -> { puts 'before type check' }
80
+ ```
81
+
82
+ ### Nested Hash Errors
83
+
84
+ Nested hash errors no longer add an error as through it happened on the hash.
85
+ They now use the error in its original form and attach the name of the hash to
86
+ the error. It is also not limited to returning one error.
87
+
88
+ ```ruby
89
+ class HashInteraction < ActiveInteraction::Base
90
+ hash :mailing_lists do
91
+ boolean :marketing
92
+ boolean :product_updates
93
+ end
94
+
95
+ def execute
96
+ # ...
97
+ end
98
+ end
99
+
100
+ > outcome = HashInteraction.run(mailing_lists: {})
101
+
102
+ # 4.1
103
+ > outcome.errors.details
104
+ # => {:mailing_lists=>[{:error=>:invalid_nested, :name=>"\"marketing\"", :value=>"nil"}]},
105
+ > outcome.errors.messages
106
+ # => {:mailing_lists=>["has an invalid nested value (\"marketing\" => nil)"]}
107
+ > outcome.errors.full_messages
108
+ # => ["Mailing lists has an invalid nested value (\"marketing\" => nil)"]
109
+
110
+ # 5.0
111
+ > outcome.errors.details
112
+ # => {:"mailing_lists.marketing"=>[{:error=>:missing}], :"mailing_lists.product_updates"=>[{:error=>:missing}]}
113
+ > outcome.errors.messages
114
+ # => {:"mailing_lists.marketing"=>["is required"], :"mailing_lists.product_updates"=>["is required"]}
115
+ > outcome.errors.full_messages
116
+ # => ["Mailing lists marketing is required", "Mailing lists product updates is required"]
117
+ ```
118
+
119
+ I18n can handle these values the same as nested values in Rails:
120
+
121
+ ```yml
122
+ en:
123
+ active_interaction:
124
+ attributes:
125
+ hash_interaction/mailing_lists:
126
+ marketing: 'Mailing list "Marketing"'
127
+ product_updates: 'Mailing list "Product Updates"'
128
+ ```
129
+
130
+ Using the same example from above:
131
+
132
+ ```ruby
133
+ > outcome.errors.full_messages
134
+ # => ["Mailing list \"Marketing\" is required", "Mailing list \"Product Updates\" is required"]
135
+ ```
136
+
137
+ # [4.1.0][] (2021-12-30)
138
+
139
+ ## Added
140
+
141
+ - [#518][] - Add Rails 7 support
142
+
1
143
  # [4.0.6][] (2021-10-13)
2
144
 
3
- ## Fix
145
+ ## Fixed
4
146
 
5
147
  - [#515][] - Filters nested in arrays should accept default values as indicated in the documentation.
6
148
 
7
149
  # [4.0.5][] (2021-07-11)
8
150
 
9
- ## Fix
151
+ ## Fixed
10
152
 
11
153
  - [#480][] - Interfaces used inside hashes failed to recognize `nil` as a non-value.
12
154
 
13
155
  # [4.0.4][] (2021-07-03)
14
156
 
15
- ## Fix
157
+ ## Fixed
16
158
 
17
159
  - [#510][] - Hash parameters failed when working outside of Rails.
18
160
  - [#511][] - Nested filters with options but no `:class` failed to have `:class` automatically added.
19
161
 
20
162
  # [4.0.3][] (2021-06-24)
21
163
 
22
- ## Fix
164
+ ## Fixed
23
165
 
24
166
  - [#499][] - `given?` now recognizes multi-part date inputs by their primary key name
25
167
  - [#493][] - `compose` now properly accepts `Inputs`
26
168
 
27
169
  # [4.0.2][] (2021-06-22)
28
170
 
29
- ## Fix
171
+ ## Fixed
30
172
 
31
173
  - [#505][] - Nested Interface filters using the `:methods` option threw an error.
32
174
 
33
175
  # [4.0.1][] (2021-05-26)
34
176
 
35
- ## Fix
177
+ ## Fixed
36
178
 
37
179
  - Fix regression of filter name relaxing.
38
180
  - [#495][] - Fix time filter ignoring time zones
@@ -62,7 +204,7 @@
62
204
 
63
205
  ## Added
64
206
 
65
- - Implicit coercion of types are now supported in filters (e.g. to_str, to_int,
207
+ - Implicit coercion of types are now supported in filters (e.g. `to_str`, `to_int`,
66
208
  etc).
67
209
  - The `interface` and `record` filters, when used as an inner filter for an
68
210
  `array`, will have their `from/class` option set to a singularized version of
@@ -970,6 +1112,9 @@ Example.run
970
1112
 
971
1113
  - Initial release.
972
1114
 
1115
+ [5.1.0]: https://github.com/AaronLasseigne/active_interaction/compare/v5.0.0...v5.1.0
1116
+ [5.0.0]: https://github.com/AaronLasseigne/active_interaction/compare/v4.1.0...v5.0.0
1117
+ [4.1.0]: https://github.com/AaronLasseigne/active_interaction/compare/v4.0.6...v4.1.0
973
1118
  [4.0.6]: https://github.com/AaronLasseigne/active_interaction/compare/v4.0.5...v4.0.6
974
1119
  [4.0.5]: https://github.com/AaronLasseigne/active_interaction/compare/v4.0.4...v4.0.5
975
1120
  [4.0.4]: https://github.com/AaronLasseigne/active_interaction/compare/v4.0.3...v4.0.4
@@ -1190,3 +1335,7 @@ Example.run
1190
1335
  [#412]: https://github.com/AaronLasseigne/active_interaction/issues/412
1191
1336
  [#480]: https://github.com/AaronLasseigne/active_interaction/issues/480
1192
1337
  [#515]: https://github.com/AaronLasseigne/active_interaction/issues/515
1338
+ [#518]: https://github.com/AaronLasseigne/active_interaction/issues/518
1339
+ [#503]: https://github.com/AaronLasseigne/active_interaction/issues/503
1340
+ [#536]: https://github.com/AaronLasseigne/active_interaction/issues/536
1341
+ [#537]: https://github.com/AaronLasseigne/active_interaction/issues/537
data/CONTRIBUTING.md CHANGED
@@ -1,13 +1,21 @@
1
- # Steps
1
+ # Contributing
2
+
3
+ Bug fixes and optimizations are welcome.
4
+ For optimizations please provide some reproducable proof of the improvement.
5
+
6
+ For features please open a [discussion][] and we can make sure the feature fits with the gem before working on it.
7
+
8
+ ## Steps
2
9
 
3
10
  1. [Fork][] the repo.
4
11
  2. Add a breaking test for your change.
5
12
  3. Make the tests pass.
6
13
  4. Push your fork.
7
- 5. Submit a pull request.
14
+ 5. Submit a pull request against the `next` branch.
8
15
 
9
- # Code Style
16
+ ## Code Style
10
17
 
11
18
  Running the tests using `rake` (with no args) will also check for style issues in the code. Ideally all submissions would pass these checks. If the code style is causing issues (particularly the method or class size) we can work with you to correct it. Don't let it stop you from contributing.
12
19
 
13
20
  [fork]: https://github.com/AaronLasseigne/active_interaction/fork
21
+ [discussion]: https://github.com/AaronLasseigne/active_interaction/discussions/categories/ideas