active_interaction 4.1.0 → 5.1.1

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 +150 -1
  3. data/CONTRIBUTING.md +11 -3
  4. data/README.md +256 -215
  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 +40 -52
  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 +27 -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 +43 -44
  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: 557de518b6e1a33937d70d31e6c29dd6179384372e082595f8087b3efcdae784
4
- data.tar.gz: 2ba312b6ddc61043acbc8bcb48dbbc4a60010be6701a5a368325d0a14fc4c557
3
+ metadata.gz: 1205bfc3c95589bd74fdb6395e09573c01210a95bf5d6644b70fef11cacea914
4
+ data.tar.gz: 2494a61529d645f6dcfaef940e4d54e404bda94eb78eabbac605dcc14221e422
5
5
  SHA512:
6
- metadata.gz: 28674a0400c7bd8dafaae7430f1609fdbd3cd93e3ca5c60a07d2df2970b825a7e218d2482026f0a6365ba11fdd6518830fdfb96f496909ee7d8cb63154c5b8e7
7
- data.tar.gz: e527210922d3e9af79ff3c61f2e5d1ba873fe9eb31be543ffd640d255f69de19b40d0621ff9900db19e3cf3f553c8cfbcf583954385d2c8a3db2f24a747037f7
6
+ metadata.gz: 6037171bd7f2ddc2af0204e2af5fdf0140725678698e7c4fa27875f16446c7c8be0b69aa83da30626bf9fe96ae00a5f76ffc92274cfd9654abad355e611df7ed
7
+ data.tar.gz: fac17df5266c5a72809fbc32ab3e84d840b35fe59cb2d483511b27c46beaec197b5a5e669d740ef023bf064df82a8ac8d5cbcd94bba60b3c5e0ba72969b385c2
data/CHANGELOG.md CHANGED
@@ -1,3 +1,145 @@
1
+ # [5.1.1][] (2022-09-01)
2
+
3
+ ## Fixed
4
+
5
+ - [#539][] - Fixed a caching error in default values.
6
+
7
+ # [5.1.0][] (2022-07-28)
8
+
9
+ ## Added
10
+
11
+ - Limit dependencies to the minimum requirements.
12
+
13
+ ## Fixed
14
+
15
+ - [#536][] - `compose` accepts `Inputs`.
16
+ - [#537][] - Arrays with nested filters returned the wrong value.
17
+
18
+ # [5.0.0][] (2022-06-24)
19
+
20
+ ## Changed
21
+
22
+ - Drop support for JRuby.
23
+ - Drop support for Ruby 2.5 and 2.6, adding support for 3.1
24
+ - Drop support for Rails 5.0 and 5.1
25
+ - `ActiveInteraction::Inputs` no longer inherits from `Hash` though it still has most of the methods
26
+ provided by `Hash` (methods that write were removed).
27
+ - Removed `Filter#clean` (use `Filter#process` and call `#value` on the result)
28
+ - The `given?` method has been moved onto `inputs`. ([how to upgrade](#given))
29
+ - [#503][] - The record filter now treats blank strings value as `nil`. This was missed in the 4.0 update.
30
+ - The `type_check` callback has been renamed to `filter` to better match the reality of what it does.
31
+ ([how to upgrade](#filter-callback))
32
+ - `ActiveIneraction::FilterColumn` is now `ActiveInteraction::Filter::Column`
33
+ - Errors on the array filter will now be indexed if the Rails config `index_nested_attribute_errors`
34
+ is `true` or the `:index_errors` option is set to `true`. The `:index_errors` option always overrides
35
+ the Rails config.
36
+ - Invalid nested errors (`:invalid_nested`) are gone. Instead the nested errors will appear as they would
37
+ in Rails if they were a `has_many` relationship being assigned attributes through a parent.
38
+ ([how to upgrade](#nested-hash-errors))
39
+
40
+ ## Added
41
+
42
+ - `Filter#process` which returns an `Input`.
43
+
44
+ ## Fixed
45
+
46
+ - When passing an `ActiveRecord::Relation` in an array filter with no inner
47
+ filter, the value returned was an `ActiveRecord::Relation` instead of an
48
+ Array.
49
+
50
+ ## Upgrading
51
+
52
+ ### `given?`
53
+
54
+ The `given?` method can now be found on `inputs`. It works the same as before.
55
+
56
+ ```ruby
57
+ # 4.1
58
+ class Example < ActiveInteraction::Base
59
+ string :name, default: nil
60
+
61
+ def execute
62
+ given?(:name)
63
+ end
64
+ end
65
+
66
+ # 5.0
67
+ class Example < ActiveInteraction::Base
68
+ string :name, default: nil
69
+
70
+ def execute
71
+ inputs.given?(:name)
72
+ end
73
+ end
74
+ ```
75
+
76
+ ### Filter Callback
77
+
78
+ You'll need to rename any `:type_check` callbacks to `:filter`.
79
+
80
+ ```ruby
81
+ # 4.1
82
+ set_callback :type_check, :before, -> { puts 'before type check' }
83
+
84
+ # 5.0
85
+ set_callback :filter, :before, -> { puts 'before type check' }
86
+ ```
87
+
88
+ ### Nested Hash Errors
89
+
90
+ Nested hash errors no longer add an error as through it happened on the hash.
91
+ They now use the error in its original form and attach the name of the hash to
92
+ the error. It is also not limited to returning one error.
93
+
94
+ ```ruby
95
+ class HashInteraction < ActiveInteraction::Base
96
+ hash :mailing_lists do
97
+ boolean :marketing
98
+ boolean :product_updates
99
+ end
100
+
101
+ def execute
102
+ # ...
103
+ end
104
+ end
105
+
106
+ > outcome = HashInteraction.run(mailing_lists: {})
107
+
108
+ # 4.1
109
+ > outcome.errors.details
110
+ # => {:mailing_lists=>[{:error=>:invalid_nested, :name=>"\"marketing\"", :value=>"nil"}]},
111
+ > outcome.errors.messages
112
+ # => {:mailing_lists=>["has an invalid nested value (\"marketing\" => nil)"]}
113
+ > outcome.errors.full_messages
114
+ # => ["Mailing lists has an invalid nested value (\"marketing\" => nil)"]
115
+
116
+ # 5.0
117
+ > outcome.errors.details
118
+ # => {:"mailing_lists.marketing"=>[{:error=>:missing}], :"mailing_lists.product_updates"=>[{:error=>:missing}]}
119
+ > outcome.errors.messages
120
+ # => {:"mailing_lists.marketing"=>["is required"], :"mailing_lists.product_updates"=>["is required"]}
121
+ > outcome.errors.full_messages
122
+ # => ["Mailing lists marketing is required", "Mailing lists product updates is required"]
123
+ ```
124
+
125
+ I18n can handle these values the same as nested values in Rails:
126
+
127
+ ```yml
128
+ en:
129
+ active_interaction:
130
+ attributes:
131
+ hash_interaction/mailing_lists:
132
+ marketing: 'Mailing list "Marketing"'
133
+ product_updates: 'Mailing list "Product Updates"'
134
+ ```
135
+
136
+ Using the same example from above:
137
+
138
+ ```ruby
139
+ > outcome.errors.full_messages
140
+ # => ["Mailing list \"Marketing\" is required", "Mailing list \"Product Updates\" is required"]
141
+ ```
142
+
1
143
  # [4.1.0][] (2021-12-30)
2
144
 
3
145
  ## Added
@@ -68,7 +210,7 @@
68
210
 
69
211
  ## Added
70
212
 
71
- - Implicit coercion of types are now supported in filters (e.g. to_str, to_int,
213
+ - Implicit coercion of types are now supported in filters (e.g. `to_str`, `to_int`,
72
214
  etc).
73
215
  - The `interface` and `record` filters, when used as an inner filter for an
74
216
  `array`, will have their `from/class` option set to a singularized version of
@@ -976,6 +1118,9 @@ Example.run
976
1118
 
977
1119
  - Initial release.
978
1120
 
1121
+ [5.1.1]: https://github.com/AaronLasseigne/active_interaction/compare/v5.1.0...v5.1.1
1122
+ [5.1.0]: https://github.com/AaronLasseigne/active_interaction/compare/v5.0.0...v5.1.0
1123
+ [5.0.0]: https://github.com/AaronLasseigne/active_interaction/compare/v4.1.0...v5.0.0
979
1124
  [4.1.0]: https://github.com/AaronLasseigne/active_interaction/compare/v4.0.6...v4.1.0
980
1125
  [4.0.6]: https://github.com/AaronLasseigne/active_interaction/compare/v4.0.5...v4.0.6
981
1126
  [4.0.5]: https://github.com/AaronLasseigne/active_interaction/compare/v4.0.4...v4.0.5
@@ -1198,3 +1343,7 @@ Example.run
1198
1343
  [#480]: https://github.com/AaronLasseigne/active_interaction/issues/480
1199
1344
  [#515]: https://github.com/AaronLasseigne/active_interaction/issues/515
1200
1345
  [#518]: https://github.com/AaronLasseigne/active_interaction/issues/518
1346
+ [#503]: https://github.com/AaronLasseigne/active_interaction/issues/503
1347
+ [#536]: https://github.com/AaronLasseigne/active_interaction/issues/536
1348
+ [#537]: https://github.com/AaronLasseigne/active_interaction/issues/537
1349
+ [#539]: https://github.com/AaronLasseigne/active_interaction/issues/539
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