active_interaction 3.4.0 → 3.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +7 -6
- data/lib/active_interaction/base.rb +28 -4
- data/lib/active_interaction/version.rb +1 -1
- data/spec/active_interaction/base_spec.rb +67 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c2eca96d7ec5eccc82c4321445f7c0e009a0d8e6
|
4
|
+
data.tar.gz: '048a0f22cd8c0e2071eb1428aff2cd9c88be0482'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a67fa88d500066873e6c4626d21fd76c5cf322989fab2fb9ab52f076ce7353d2e22856c4b40b204f23570bfd2d9f218f2c5d2289c77207f43d2a5c21dd557eb7
|
7
|
+
data.tar.gz: 24daf7828183f8093ea7aa19709a0b49f5f8f9f263cf997dd9c5ed32ae5e45beb7267ad892efff27d5318a67c5c6e75f1f31d9048e734284aabf0da4fbdbb65a
|
data/README.md
CHANGED
@@ -66,20 +66,20 @@ Read more on [the project page][] or check out [the full documentation][].
|
|
66
66
|
Add it to your Gemfile:
|
67
67
|
|
68
68
|
``` rb
|
69
|
-
gem 'active_interaction', '~> 3.
|
69
|
+
gem 'active_interaction', '~> 3.5'
|
70
70
|
```
|
71
71
|
|
72
72
|
Or install it manually:
|
73
73
|
|
74
74
|
``` sh
|
75
|
-
$ gem install active_interaction --version '~> 3.
|
75
|
+
$ gem install active_interaction --version '~> 3.5'
|
76
76
|
```
|
77
77
|
|
78
|
-
This project uses [Semantic Versioning][]. Check out [
|
78
|
+
This project uses [Semantic Versioning][]. Check out [GitHub releases][] for a
|
79
79
|
detailed list of changes. For help upgrading to version 2, please read [the
|
80
80
|
announcement post][].
|
81
81
|
|
82
|
-
ActiveInteraction works with Ruby 2.0 through 2.
|
82
|
+
ActiveInteraction works with Ruby 2.0 through 2.4 and ActiveModel 4.0 through
|
83
83
|
5.0. If you want to use ActiveInteraction with an older version of Ruby or
|
84
84
|
ActiveModel, use ActiveInteraction < 3.0.0.
|
85
85
|
|
@@ -1267,7 +1267,8 @@ are merged to create `inputs`. There are times where it is useful to know
|
|
1267
1267
|
whether a value was passed to `run` or the result of a filter default. In
|
1268
1268
|
particular, it is useful when `nil` is an acceptable value. For example, you
|
1269
1269
|
may optionally track your users' birthdays. You can use the `given?` predicate
|
1270
|
-
to see if an input was even passed to `run`.
|
1270
|
+
to see if an input was even passed to `run`. With `given?` you can also check
|
1271
|
+
the input of a hash filter by passing a series of keys to check.
|
1271
1272
|
|
1272
1273
|
``` rb
|
1273
1274
|
class UpdateUser < ActiveInteraction::Base
|
@@ -1401,7 +1402,7 @@ ActiveInteraction is licensed under [the MIT License][].
|
|
1401
1402
|
[the project page]: http://orgsync.github.io/active_interaction/
|
1402
1403
|
[the full documentation]: http://rubydoc.info/github/orgsync/active_interaction
|
1403
1404
|
[semantic versioning]: http://semver.org/spec/v2.0.0.html
|
1404
|
-
[
|
1405
|
+
[GitHub releases]: https://github.com/orgsync/active_interaction/releases
|
1405
1406
|
[the announcement post]: http://devblog.orgsync.com/2015/05/06/announcing-active-interaction-2/
|
1406
1407
|
[active_model-errors_details]: https://github.com/cowbell/active_model-errors_details
|
1407
1408
|
[aaron lasseigne]: https://github.com/AaronLasseigne
|
@@ -203,7 +203,8 @@ module ActiveInteraction
|
|
203
203
|
|
204
204
|
# Returns `true` if the given key was in the hash passed to {.run}.
|
205
205
|
# Otherwise returns `false`. Use this to figure out if an input was given,
|
206
|
-
# even if it was `nil`.
|
206
|
+
# even if it was `nil`. Keys within nested hash filter can also be checked
|
207
|
+
# by passing them in series.
|
207
208
|
#
|
208
209
|
# @example
|
209
210
|
# class Example < ActiveInteraction::Base
|
@@ -214,13 +215,36 @@ module ActiveInteraction
|
|
214
215
|
# Example.run!(x: nil) # => true
|
215
216
|
# Example.run!(x: rand) # => true
|
216
217
|
#
|
218
|
+
# @example Nested checks
|
219
|
+
# class Example < ActiveInteraction::Base
|
220
|
+
# hash :x, default: {} do
|
221
|
+
# integer :y, default: nil
|
222
|
+
# end
|
223
|
+
# def execute; given?(:x, :y) end
|
224
|
+
# end
|
225
|
+
# Example.run!() # => false
|
226
|
+
# Example.run!(x: nil) # => false
|
227
|
+
# Example.run!(x: {}) # => false
|
228
|
+
# Example.run!(x: { y: nil }) # => true
|
229
|
+
# Example.run!(x: { y: rand }) # => true
|
230
|
+
#
|
217
231
|
# @param input [#to_sym]
|
218
232
|
#
|
219
233
|
# @return [Boolean]
|
220
234
|
#
|
221
235
|
# @since 2.1.0
|
222
|
-
def given?(input)
|
223
|
-
|
236
|
+
def given?(input, *rest)
|
237
|
+
filter_level = self.class
|
238
|
+
input_level = @_interaction_inputs
|
239
|
+
|
240
|
+
[input, *rest].map(&:to_sym).each do |key|
|
241
|
+
filter_level = filter_level.filters[key]
|
242
|
+
if !filter_level || input_level.nil? || !input_level.key?(key)
|
243
|
+
break false
|
244
|
+
end
|
245
|
+
|
246
|
+
input_level = input_level[key]
|
247
|
+
end && true
|
224
248
|
end
|
225
249
|
|
226
250
|
protected
|
@@ -250,7 +274,7 @@ module ActiveInteraction
|
|
250
274
|
|
251
275
|
# @param inputs [Hash{Symbol => Object}]
|
252
276
|
def process_inputs(inputs)
|
253
|
-
@
|
277
|
+
@_interaction_inputs = inputs
|
254
278
|
|
255
279
|
inputs.each do |key, value|
|
256
280
|
raise InvalidValueError, key.inspect if InputProcessor.reserved?(key)
|
@@ -436,6 +436,73 @@ describe ActiveInteraction::Base do
|
|
436
436
|
inputs[:y] = rand
|
437
437
|
expect(result).to be false
|
438
438
|
end
|
439
|
+
|
440
|
+
context 'nested hash values' do
|
441
|
+
let(:described_class) do
|
442
|
+
Class.new(TestInteraction) do
|
443
|
+
hash :x, default: {} do
|
444
|
+
boolean :y,
|
445
|
+
default: true
|
446
|
+
end
|
447
|
+
|
448
|
+
def execute; end
|
449
|
+
end
|
450
|
+
end
|
451
|
+
|
452
|
+
it 'is true when the nested input is given' do
|
453
|
+
described_class.class_exec do
|
454
|
+
def execute
|
455
|
+
given?(:x, :y)
|
456
|
+
end
|
457
|
+
end
|
458
|
+
|
459
|
+
inputs[:x] = { y: false }
|
460
|
+
expect(result).to be true
|
461
|
+
end
|
462
|
+
|
463
|
+
it 'is false when the nested input is not given' do
|
464
|
+
described_class.class_exec do
|
465
|
+
def execute
|
466
|
+
given?(:x, :y)
|
467
|
+
end
|
468
|
+
end
|
469
|
+
|
470
|
+
inputs[:x] = {}
|
471
|
+
expect(result).to be false
|
472
|
+
end
|
473
|
+
|
474
|
+
it 'is false when the first input is not given' do
|
475
|
+
described_class.class_exec do
|
476
|
+
def execute
|
477
|
+
given?(:x, :y)
|
478
|
+
end
|
479
|
+
end
|
480
|
+
|
481
|
+
expect(result).to be false
|
482
|
+
end
|
483
|
+
|
484
|
+
it 'is false when the first input is nil' do
|
485
|
+
described_class.class_exec do
|
486
|
+
def execute
|
487
|
+
given?(:x, :y)
|
488
|
+
end
|
489
|
+
end
|
490
|
+
|
491
|
+
inputs[:x] = nil
|
492
|
+
expect(result).to be false
|
493
|
+
end
|
494
|
+
|
495
|
+
it 'returns false if you go too far' do
|
496
|
+
described_class.class_exec do
|
497
|
+
def execute
|
498
|
+
given?(:x, :y, :z)
|
499
|
+
end
|
500
|
+
end
|
501
|
+
|
502
|
+
inputs[:x] = { y: true }
|
503
|
+
expect(result).to be false
|
504
|
+
end
|
505
|
+
end
|
439
506
|
end
|
440
507
|
|
441
508
|
context 'inheritance' do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_interaction
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.
|
4
|
+
version: 3.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Aaron Lasseigne
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2017-03-19 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activemodel
|
@@ -273,7 +273,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
273
273
|
version: '0'
|
274
274
|
requirements: []
|
275
275
|
rubyforge_project:
|
276
|
-
rubygems_version: 2.6.
|
276
|
+
rubygems_version: 2.6.8
|
277
277
|
signing_key:
|
278
278
|
specification_version: 4
|
279
279
|
summary: Manage application specific business logic.
|