attr-gather 1.1.1 → 1.1.2
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8f0cfb5dd834161d41a92270f036981babbc4c64a7a2a0be6c223b52e68f22ed
|
4
|
+
data.tar.gz: e865667f933a51c3931e5c04d09d27bb30effabaae7aa247197f5b23e36908c6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4feb0be067955ac28cc1da31cf278a717a9aa56f43e97409fb110f822acacbae0fda1fc5bc2529c19a0e1d453bd87ef5a140ecde1494da5e5708c8ef4c47b7d4
|
7
|
+
data.tar.gz: 343523a4a84ec2326f9487051898ac3bce17e504a7bda5b93e4e03092bbd5aff4ae3a49b8cde9d2dfa24760803a783ff04d1b4fcc22f28954a798ab35d4503eb
|
data/Gemfile.lock
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'attr/gather/filters/noop'
|
4
|
+
|
3
5
|
module Attr
|
4
6
|
module Gather
|
5
7
|
module Aggregators
|
@@ -11,8 +13,10 @@ module Attr
|
|
11
13
|
class Base
|
12
14
|
attr_accessor :filter
|
13
15
|
|
16
|
+
NOOP_FILTER ||= Filters::Noop.new
|
17
|
+
|
14
18
|
def initialize(**opts)
|
15
|
-
@filter = opts.delete(:filter)
|
19
|
+
@filter = opts.delete(:filter) || NOOP_FILTER
|
16
20
|
end
|
17
21
|
|
18
22
|
def call(_original_input, _results_array)
|
@@ -23,7 +23,7 @@ module Attr
|
|
23
23
|
|
24
24
|
def call(input, execution_results)
|
25
25
|
execution_results = execution_results.reverse_each if reverse?
|
26
|
-
initial =
|
26
|
+
initial = unwrap_initial_input(input)
|
27
27
|
|
28
28
|
result = execution_results.reduce(initial) do |memo, res|
|
29
29
|
deep_merge(memo, unwrap_result(res))
|
@@ -34,6 +34,10 @@ module Attr
|
|
34
34
|
|
35
35
|
private
|
36
36
|
|
37
|
+
def unwrap_initial_input(input)
|
38
|
+
merge_input? ? filter.call(input.dup).value : {}
|
39
|
+
end
|
40
|
+
|
37
41
|
def reverse?
|
38
42
|
@reverse
|
39
43
|
end
|
@@ -23,7 +23,7 @@ module Attr
|
|
23
23
|
|
24
24
|
def call(input, execution_results)
|
25
25
|
execution_results = execution_results.reverse_each if reverse?
|
26
|
-
initial =
|
26
|
+
initial = unwrap_initial_input(input)
|
27
27
|
|
28
28
|
result = execution_results.reduce(initial) do |memo, res|
|
29
29
|
memo.merge(unwrap_result(res))
|
@@ -34,6 +34,10 @@ module Attr
|
|
34
34
|
|
35
35
|
private
|
36
36
|
|
37
|
+
def unwrap_initial_input(input)
|
38
|
+
merge_input? ? filter.call(input.dup).value : {}
|
39
|
+
end
|
40
|
+
|
37
41
|
def reverse?
|
38
42
|
@reverse
|
39
43
|
end
|
data/lib/attr/gather/version.rb
CHANGED
@@ -88,13 +88,13 @@ module Attr
|
|
88
88
|
#
|
89
89
|
# @api public
|
90
90
|
def aggregator(agg = nil, opts = EMPTY_HASH)
|
91
|
-
if agg.nil? && !defined?(@aggregator)
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
91
|
+
@aggregator = if agg.nil? && !defined?(@aggregator)
|
92
|
+
Aggregators.default
|
93
|
+
elsif agg
|
94
|
+
Aggregators.resolve(agg, filter: filter, **opts)
|
95
|
+
else
|
96
|
+
@aggregator
|
97
|
+
end
|
98
98
|
end
|
99
99
|
|
100
100
|
# Defines a filter for filtering out invalid values
|
@@ -130,12 +130,16 @@ module Attr
|
|
130
130
|
# @param args [Array<Object>] arguments for initializing the filter
|
131
131
|
#
|
132
132
|
# @api public
|
133
|
-
def filter(filt =
|
134
|
-
if filt
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
133
|
+
def filter(filt = nil, *args, **opts)
|
134
|
+
@filter = if filt.nil? && !defined?(@filter)
|
135
|
+
Filters.default
|
136
|
+
elsif filt
|
137
|
+
Filters.resolve(filt, *args, **opts)
|
138
|
+
else
|
139
|
+
@filter
|
140
|
+
end
|
141
|
+
|
142
|
+
aggregator.filter = @filter
|
139
143
|
|
140
144
|
@filter
|
141
145
|
end
|
@@ -169,7 +173,7 @@ module Attr
|
|
169
173
|
# @api public
|
170
174
|
def filter_with_contract(arg = nil, &blk)
|
171
175
|
contract = block_given? ? build_inline_contract_filter(&blk) : arg
|
172
|
-
|
176
|
+
filter(:contract, contract)
|
173
177
|
end
|
174
178
|
|
175
179
|
private
|