attr-gather 1.4.0 → 1.5.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9bd71ae41d26e56b126cd094b0baa82755c246c059c3149330730e80ff075836
4
- data.tar.gz: 1ca6c61fa9e9daddcacb558387e2fac8d471108c223a390404ce77b11b2051b7
3
+ metadata.gz: d5a781371ace4374427a2510da9860b10014caf039fcfd4aa620886f252d57a9
4
+ data.tar.gz: a0d1d564f206b30246e67d017e8a814c43529b120c6ff8499ef0198d5847ad7a
5
5
  SHA512:
6
- metadata.gz: 96607adf22289a8fc5226ec952e9e80d6694f79cc97bee2100d842c7dd5068b3bc4799d57026876888a432075f6c35d1dfba155069594f945ea002856e5ab7cc
7
- data.tar.gz: 6ca46ed75fb879de04127ff80c3018a2b086a206ddac8c1e3d311fd71f292642709a09ea0b6dc4285ec19b3ddb1f9493a279894b870052c0c497ca7d9fc974ff
6
+ metadata.gz: 52823ab8e9b562de9b23b8bdbe6bc08354bb85f71bd51580ab746fd4adce30cade4d27d55c3bf67a294bbb101f61eae485bc006537c89aefcba57ca28f3e8e39
7
+ data.tar.gz: '0998be6201c8b8292297390064233d0ad04c17b5b8d84ceebf76f0766e5d84fdfafb7edc0d2a4621825f2efafd66b192f89a3fbd38d6462b16ecbecbea7abc01'
@@ -6,7 +6,7 @@ jobs:
6
6
  runs-on: ubuntu-latest
7
7
  strategy:
8
8
  matrix:
9
- ruby: ["2.4.x", "2.5.x", "2.6.x", "2.7.x"]
9
+ ruby: ["2.5.x", "2.6.x", "2.7.x"]
10
10
  steps:
11
11
  - uses: actions/checkout@v1
12
12
  - name: Set up Ruby 2.6
data/.rubocop.yml CHANGED
@@ -4,7 +4,7 @@ require:
4
4
  AllCops:
5
5
  UseCache: true
6
6
  CacheRootDirectory: './tmp/cache'
7
- TargetRubyVersion: 2.4
7
+ TargetRubyVersion: 2.5
8
8
  NewCops: enable
9
9
 
10
10
  Metrics/BlockLength:
@@ -15,7 +15,7 @@ Metrics/ModuleLength:
15
15
  Exclude:
16
16
  - spec/**/*.rb
17
17
 
18
- Metrics/LineLength:
18
+ Layout/LineLength:
19
19
  Exclude:
20
20
  - ./attr-gather.gemspec
21
21
  - ./bin/**/*
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 2.6.5
1
+ 2.6.6
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- attr-gather (1.4.0)
4
+ attr-gather (1.5.1)
5
5
  dry-container (~> 0.7)
6
6
 
7
7
  GEM
@@ -9,46 +9,42 @@ GEM
9
9
  specs:
10
10
  addressable (2.7.0)
11
11
  public_suffix (>= 2.0.2, < 5.0)
12
- ast (2.4.1)
12
+ ast (2.4.2)
13
13
  backport (1.1.2)
14
- benchmark (0.1.0)
14
+ benchmark (0.1.1)
15
15
  coderay (1.1.3)
16
- concurrent-ruby (1.1.7)
16
+ concurrent-ruby (1.1.8)
17
17
  diff-lcs (1.4.4)
18
18
  domain_name (0.5.20190701)
19
19
  unf (>= 0.0.5, < 1.0.0)
20
- dry-configurable (0.11.6)
20
+ dry-configurable (0.12.1)
21
21
  concurrent-ruby (~> 1.0)
22
- dry-core (~> 0.4, >= 0.4.7)
23
- dry-equalizer (~> 0.2)
22
+ dry-core (~> 0.5, >= 0.5.0)
24
23
  dry-container (0.7.2)
25
24
  concurrent-ruby (~> 1.0)
26
25
  dry-configurable (~> 0.1, >= 0.1.3)
27
- dry-core (0.4.9)
26
+ dry-core (0.6.0)
28
27
  concurrent-ruby (~> 1.0)
29
28
  dry-equalizer (0.3.0)
30
29
  dry-inflector (0.2.0)
31
30
  dry-initializer (3.0.4)
32
- dry-logic (1.0.8)
31
+ dry-logic (1.2.0)
33
32
  concurrent-ruby (~> 1.0)
34
- dry-core (~> 0.2)
35
- dry-equalizer (~> 0.2)
36
- dry-schema (1.5.5)
33
+ dry-core (~> 0.5, >= 0.5)
34
+ dry-schema (1.6.2)
37
35
  concurrent-ruby (~> 1.0)
38
36
  dry-configurable (~> 0.8, >= 0.8.3)
39
- dry-core (~> 0.4)
40
- dry-equalizer (~> 0.2)
37
+ dry-core (~> 0.5, >= 0.5)
41
38
  dry-initializer (~> 3.0)
42
39
  dry-logic (~> 1.0)
43
- dry-types (~> 1.4)
44
- dry-types (1.4.0)
40
+ dry-types (~> 1.5)
41
+ dry-types (1.5.1)
45
42
  concurrent-ruby (~> 1.0)
46
43
  dry-container (~> 0.3)
47
- dry-core (~> 0.4, >= 0.4.4)
48
- dry-equalizer (~> 0.3)
44
+ dry-core (~> 0.5, >= 0.5)
49
45
  dry-inflector (~> 0.1, >= 0.1.2)
50
46
  dry-logic (~> 1.0, >= 1.0.2)
51
- dry-validation (1.5.6)
47
+ dry-validation (1.6.0)
52
48
  concurrent-ruby (~> 1.0)
53
49
  dry-container (~> 0.7, >= 0.7.1)
54
50
  dry-core (~> 0.4)
@@ -56,87 +52,94 @@ GEM
56
52
  dry-initializer (~> 3.0)
57
53
  dry-schema (~> 1.5, >= 1.5.2)
58
54
  e2mmap (0.1.0)
59
- ffi (1.13.1)
55
+ ffi (1.15.1)
60
56
  ffi-compiler (1.0.1)
61
57
  ffi (>= 1.0.0)
62
58
  rake
63
- http (4.4.1)
59
+ http (5.0.0)
64
60
  addressable (~> 2.3)
65
61
  http-cookie (~> 1.0)
66
62
  http-form_data (~> 2.2)
67
- http-parser (~> 1.2.0)
63
+ llhttp-ffi (~> 0.0.1)
68
64
  http-cookie (1.0.3)
69
65
  domain_name (~> 0.5)
70
66
  http-form_data (2.3.0)
71
- http-parser (1.2.1)
72
- ffi-compiler (>= 1.0, < 2.0)
73
67
  jaro_winkler (1.5.4)
74
- maruku (0.7.3)
68
+ kramdown (2.3.1)
69
+ rexml
70
+ kramdown-parser-gfm (1.1.0)
71
+ kramdown (~> 2.0)
72
+ llhttp-ffi (0.0.1)
73
+ ffi-compiler (~> 1.0)
74
+ rake (~> 13.0)
75
75
  method_source (1.0.0)
76
- mini_portile2 (2.4.0)
77
- nokogiri (1.10.10)
78
- mini_portile2 (~> 2.4.0)
76
+ mini_portile2 (2.5.3)
77
+ nokogiri (1.11.7)
78
+ mini_portile2 (~> 2.5.0)
79
+ racc (~> 1.4)
79
80
  parallel (1.20.1)
80
- parser (2.7.2.0)
81
+ parser (3.0.1.1)
81
82
  ast (~> 2.4.1)
82
- pry (0.13.1)
83
+ pry (0.14.1)
83
84
  coderay (~> 1.1)
84
85
  method_source (~> 1.0)
85
86
  public_suffix (4.0.6)
87
+ racc (1.5.2)
86
88
  rainbow (3.0.0)
87
- rake (13.0.1)
88
- regexp_parser (2.0.0)
89
+ rake (13.0.3)
90
+ regexp_parser (2.1.1)
89
91
  reverse_markdown (2.0.0)
90
92
  nokogiri
91
- rexml (3.2.4)
93
+ rexml (3.2.5)
92
94
  rspec (3.10.0)
93
95
  rspec-core (~> 3.10.0)
94
96
  rspec-expectations (~> 3.10.0)
95
97
  rspec-mocks (~> 3.10.0)
96
- rspec-core (3.10.0)
98
+ rspec-core (3.10.1)
97
99
  rspec-support (~> 3.10.0)
98
- rspec-expectations (3.10.0)
100
+ rspec-expectations (3.10.1)
99
101
  diff-lcs (>= 1.2.0, < 2.0)
100
102
  rspec-support (~> 3.10.0)
101
- rspec-mocks (3.10.0)
103
+ rspec-mocks (3.10.2)
102
104
  diff-lcs (>= 1.2.0, < 2.0)
103
105
  rspec-support (~> 3.10.0)
104
- rspec-support (3.10.0)
105
- rubocop (0.93.1)
106
+ rspec-support (3.10.2)
107
+ rubocop (1.16.0)
106
108
  parallel (~> 1.10)
107
- parser (>= 2.7.1.5)
109
+ parser (>= 3.0.0.0)
108
110
  rainbow (>= 2.2.2, < 4.0)
109
- regexp_parser (>= 1.8)
111
+ regexp_parser (>= 1.8, < 3.0)
110
112
  rexml
111
- rubocop-ast (>= 0.6.0)
113
+ rubocop-ast (>= 1.7.0, < 2.0)
112
114
  ruby-progressbar (~> 1.7)
113
- unicode-display_width (>= 1.4.0, < 2.0)
114
- rubocop-ast (1.3.0)
115
- parser (>= 2.7.1.5)
116
- rubocop-performance (1.6.1)
117
- rubocop (>= 0.71.0)
118
- ruby-progressbar (1.10.1)
119
- solargraph (0.39.17)
115
+ unicode-display_width (>= 1.4.0, < 3.0)
116
+ rubocop-ast (1.7.0)
117
+ parser (>= 3.0.1.1)
118
+ rubocop-performance (1.11.3)
119
+ rubocop (>= 1.7.0, < 2.0)
120
+ rubocop-ast (>= 0.4.0)
121
+ ruby-progressbar (1.11.0)
122
+ solargraph (0.41.1)
120
123
  backport (~> 1.1)
121
124
  benchmark
122
125
  bundler (>= 1.17.2)
123
126
  e2mmap
124
127
  jaro_winkler (~> 1.5)
125
- maruku (~> 0.7, >= 0.7.3)
126
- nokogiri (~> 1.9, >= 1.9.1)
127
- parser (~> 2.3)
128
+ kramdown (~> 2.3)
129
+ kramdown-parser-gfm (~> 1.1)
130
+ parser (~> 3.0)
128
131
  reverse_markdown (>= 1.0.5, < 3)
129
- rubocop (~> 0.52)
132
+ rubocop (>= 0.52)
130
133
  thor (~> 1.0)
131
134
  tilt (~> 2.0)
132
135
  yard (~> 0.9, >= 0.9.24)
133
- thor (1.0.1)
136
+ thor (1.1.0)
134
137
  tilt (2.0.10)
135
138
  unf (0.1.4)
136
139
  unf_ext
137
140
  unf_ext (0.0.7.7)
138
- unicode-display_width (1.7.0)
139
- yard (0.9.25)
141
+ unicode-display_width (2.0.0)
142
+ yard (0.9.26)
140
143
 
141
144
  PLATFORMS
142
145
  ruby
@@ -155,4 +158,4 @@ DEPENDENCIES
155
158
  yard
156
159
 
157
160
  BUNDLED WITH
158
- 2.1.4
161
+ 2.2.11
data/Rakefile CHANGED
@@ -23,7 +23,7 @@ rescue LoadError
23
23
  warn 'Could not load yarddoc rake task'
24
24
  end
25
25
 
26
- task default: %i[spec lint]
26
+ task default: %i[spec lint doc]
27
27
 
28
28
  namespace :examples do
29
29
  desc 'Run all examples'
data/attr-gather.gemspec CHANGED
@@ -15,7 +15,7 @@ Gem::Specification.new do |spec|
15
15
  spec.homepage = 'https://github.com/ianks/attr-gather'
16
16
  spec.license = 'MIT'
17
17
 
18
- spec.required_ruby_version = '>= 2.4'
18
+ spec.required_ruby_version = '>= 2.5'
19
19
 
20
20
  # spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
21
21
 
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'attr/gather/aggregators/base'
3
4
  require 'attr/gather/concerns/registrable'
4
5
 
5
6
  module Attr
@@ -13,7 +13,7 @@ module Attr
13
13
  class Base
14
14
  attr_accessor :filter
15
15
 
16
- NOOP_FILTER ||= Filters::Noop.new
16
+ NOOP_FILTER = Filters::Noop.new
17
17
 
18
18
  def initialize(**opts)
19
19
  @filter = opts.delete(:filter) || NOOP_FILTER
@@ -13,11 +13,18 @@ module Attr
13
13
  #
14
14
  # @param reverse [Boolean] deep merge results in reverse order
15
15
  # @param merge_input [Boolean] merge the result with the initial input
16
+ # @param array_strategy [Symbol] strategy for handling arrays, one of (:concat, :overwrite)
16
17
  #
17
18
  # @api private
18
- def initialize(reverse: false, merge_input: true, **)
19
+ def initialize(reverse: false, merge_input: true, array_strategy: :concat, **)
20
+ unless ARRAY_STRATEGY.include?(array_strategy)
21
+ raise ArgumentError, 'array_strategy must be one of: :concat, :overwrite'
22
+ end
23
+
19
24
  @reverse = reverse
20
25
  @merge_input = merge_input
26
+ @array_strategy = array_strategy
27
+
21
28
  super
22
29
  end
23
30
 
@@ -31,19 +38,38 @@ module Attr
31
38
 
32
39
  private
33
40
 
34
- def reverse?
35
- @reverse
36
- end
41
+ ARRAY_STRATEGY = %i[concat overwrite].freeze
42
+
43
+ private_constant :ARRAY_STRATEGY
37
44
 
38
45
  def deep_merge(hash, other)
39
- Hash[hash].merge(other) do |_, orig, new|
46
+ hash.to_h.merge(other) do |_, orig, new|
40
47
  if orig.respond_to?(:to_hash) && new.respond_to?(:to_hash)
41
- deep_merge(Hash[orig], Hash[new])
48
+ deep_merge(orig.to_h, new.to_h)
49
+ elsif concattable?(orig, new)
50
+ orig + new
42
51
  else
43
52
  new
44
53
  end
45
54
  end
46
55
  end
56
+
57
+ def concattable?(orig, new)
58
+ return false unless @array_strategy == :concat
59
+
60
+ concattable_class?(orig) && concattable_class?(new)
61
+ end
62
+
63
+ def concattable_class?(obj)
64
+ return true if obj.is_a?(Array)
65
+ return true if obj.is_a?(Set)
66
+
67
+ false
68
+ end
69
+
70
+ def reverse?
71
+ @reverse
72
+ end
47
73
  end
48
74
  end
49
75
  end
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'attr/gather/filters/base'
4
+
3
5
  module Attr
4
6
  module Gather
5
7
  module Filters
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Attr
4
4
  module Gather
5
- VERSION = '1.4.0'
5
+ VERSION = '1.5.1'
6
6
  end
7
7
  end
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'concurrent/promise'
4
+
3
5
  module Attr
4
6
  module Gather
5
7
  module Workflow
@@ -63,7 +65,7 @@ module Attr
63
65
  return @aggregator if defined?(@aggregator) && !@aggregator.nil?
64
66
 
65
67
  @aggregator = self.class.aggregator
66
- @aggregator.filter ||= filter
68
+ @aggregator.filter ||= filter if @aggregator.respond_to?(:filter=)
67
69
 
68
70
  @aggregator
69
71
  end
@@ -38,7 +38,7 @@ module Attr
38
38
  def task(task_name, opts = EMPTY_HASH)
39
39
  conf = OpenStruct.new
40
40
  yield conf
41
- tasks << Hash[name: task_name, **opts, **conf.to_h]
41
+ tasks << ({ name: task_name, **opts, **conf.to_h })
42
42
  self
43
43
  end
44
44
 
@@ -134,12 +134,21 @@ module Attr
134
134
  # aggregator :deep_merge
135
135
  # end
136
136
  #
137
+ # @example
138
+ # class EnhanceUserProfile
139
+ # include Attr::Gather::Workflow
140
+ #
141
+ # aggregator MyCustomAggregator
142
+ # end
143
+ #
137
144
  # @param agg [#call] the aggregator to use
138
145
  #
139
146
  # @api public
140
147
  def aggregator(agg = nil, opts = EMPTY_HASH)
141
148
  @aggregator = if agg.nil? && !defined?(@aggregator)
142
149
  Aggregators.default
150
+ elsif agg.respond_to?(:new)
151
+ agg.new(filter: filter, **opts)
143
152
  elsif agg
144
153
  Aggregators.resolve(agg, filter: filter, **opts)
145
154
  else
@@ -222,7 +231,7 @@ module Attr
222
231
  #
223
232
  # @api public
224
233
  def filter_with_contract(arg = nil, &blk)
225
- contract = block_given? ? build_inline_contract_filter(&blk) : arg
234
+ contract = blk ? build_inline_contract_filter(&blk) : arg
226
235
  filter(:contract, contract)
227
236
  end
228
237
 
@@ -9,6 +9,7 @@ module Attr
9
9
  # @api private
10
10
  class TaskGraph
11
11
  class UnfinishableError < StandardError; end
12
+
12
13
  class InvalidTaskDepedencyError < StandardError; end
13
14
 
14
15
  include TSort
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: attr-gather
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.0
4
+ version: 1.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ian Ker-Seymer
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-06-01 00:00:00.000000000 Z
11
+ date: 2021-06-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -135,7 +135,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
135
135
  requirements:
136
136
  - - ">="
137
137
  - !ruby/object:Gem::Version
138
- version: '2.4'
138
+ version: '2.5'
139
139
  required_rubygems_version: !ruby/object:Gem::Requirement
140
140
  requirements:
141
141
  - - ">="