shifty 0.4.2 → 0.5.0

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: 9e40c676c0313d5e9d68d6f086d288cbe8ff2ab62daec547512ff2a6d88f7137
4
- data.tar.gz: 4510bcada58be0042ecef3acefb11b8805ca58d309ba5633a0c86ad2d99d8f35
3
+ metadata.gz: b2d09c087eca2d3c2790efab38c0e12230edd9738daf7e43c6788a8671c64356
4
+ data.tar.gz: 98fe18da84e2889e1b0c1bb90ea41ffcb6928e50868033fa33627bce58482052
5
5
  SHA512:
6
- metadata.gz: 243e0b8aac6babbd44913ece9b7fae08b38aff704f6c5949ad48eb393558cf012c6f49b68dad301bd468f17247c76c0e3e2943ef894f1090806d8e2cfbd53879
7
- data.tar.gz: 3adca13be889a7b036f6cc670832603f9015b2c6a5f00af54da0398e6c04585b0ce99a651d2867e3c81e36007999de20f9ae1479d41ac70ef97bc05ea5a27e00
6
+ metadata.gz: 0fb0046526de78394da2a742f9c9d41d07d58717592f0ce40f13d32e6cdf8e2c0c42d30fffe2bc53e164398422639c5f42943c0e7edb064eb0ec8c21960fe833
7
+ data.tar.gz: 45792b0187073a88781217d1559afc185471bbdbd849c233af81055a9dc5d71ebf8bbd018a3224baa4d0a32795109802eadfcfe9dba754f964907154dabc0e4c
data/lib/shifty/dsl.rb CHANGED
@@ -19,18 +19,23 @@ module Shifty
19
19
  end
20
20
  end
21
21
 
22
- def relay_worker(&block)
22
+ def relay_worker(options = {}, &block)
23
+ options[:tags] ||= []
24
+ options[:tags] << :relay
23
25
  ensure_regular_arity(block)
24
26
 
25
- Worker.new(tags: [:relay]) do |value|
27
+ Worker.new(options) do |value|
26
28
  value && block.call(value)
27
29
  end
28
30
  end
29
31
 
30
- def side_worker(mode = :normal, &block)
32
+ def side_worker(options = {}, &block)
33
+ options[:tags] ||= []
34
+ options[:tags] << :side_effect
35
+ mode = options[:mode] || :normal
31
36
  ensure_regular_arity(block)
32
37
 
33
- Worker.new(tags: [:side_effect]) do |value|
38
+ Worker.new(options) do |value|
34
39
  value.tap do |v|
35
40
  used_value = (mode == :hardened) ?
36
41
  Marshal.load(Marshal.dump(v)) : v
@@ -40,15 +45,13 @@ module Shifty
40
45
  end
41
46
  end
42
47
 
43
- def filter_worker(argument = nil, &block)
44
- if block && argument.respond_to?(:call)
45
- throw_with "You cannot supply two callables"
46
- end
47
- callable = argument.respond_to?(:call) ? argument : block
48
- ensure_callable(callable)
48
+ def filter_worker(options = {}, &block)
49
+ options[:tags] ||= []
50
+ options[:tags] << :filter
51
+ ensure_callable!(block)
49
52
 
50
- Worker.new(tags: [:filter]) do |value, supply|
51
- while value && !callable.call(value)
53
+ Worker.new(options) do |value, supply|
54
+ while value && !block.call(value)
52
55
  value = supply.shift
53
56
  end
54
57
  value
@@ -62,14 +65,18 @@ module Shifty
62
65
  end
63
66
  end
64
67
 
65
- def batch_worker(options = {gathering: 1}, &block)
68
+ def batch_worker(options = {}, &block)
69
+ options[:tags] ||= []
70
+ options[:tags] << :batch
71
+ options[:gathering] ||= 1
72
+
66
73
  ensure_regular_arity(block) if block
67
74
  batch_full = block ||
68
75
  proc { |_, batch| batch.size >= options[:gathering] }
69
76
 
70
- batch_context = BatchContext.new({batch_full: batch_full})
77
+ options[:context] = BatchContext.new({batch_full: batch_full})
71
78
 
72
- Worker.new(tags: [:batch], context: batch_context) do |value, supply, context|
79
+ Worker.new(options) do |value, supply, context|
73
80
  if value
74
81
  context.collection = [value]
75
82
  until context.batch_complete?(
@@ -83,10 +90,12 @@ module Shifty
83
90
  end
84
91
  end
85
92
 
86
- def splitter_worker(&block)
93
+ def splitter_worker(options = {}, &block)
94
+ options[:tags] ||= []
95
+ options[:tags] << :splitter
87
96
  ensure_regular_arity(block)
88
97
 
89
- Worker.new(tags: [:splitter]) do |value|
98
+ Worker.new(options) do |value|
90
99
  if value.nil?
91
100
  value
92
101
  else
@@ -99,9 +108,11 @@ module Shifty
99
108
  end
100
109
  end
101
110
 
111
+ # don't like that this is a second exception to accepting options..
102
112
  def trailing_worker(trail_length = 2)
113
+ options = {tags: [:trailing]}
103
114
  trail = []
104
- Worker.new(tags: [:trailing]) do |value, supply|
115
+ Worker.new(options) do |value, supply|
105
116
  if value
106
117
  trail.unshift value
107
118
  if trail.size >= trail_length
@@ -113,7 +124,7 @@ module Shifty
113
124
 
114
125
  trail
115
126
  else
116
- value
127
+ value # hint: it's nil!
117
128
  end
118
129
  end
119
130
  end
@@ -128,7 +139,7 @@ module Shifty
128
139
  raise WorkerInitializationError.new([msg].flatten.join(" "))
129
140
  end
130
141
 
131
- def ensure_callable(callable)
142
+ def ensure_callable!(callable)
132
143
  unless callable&.respond_to?(:call)
133
144
  throw_with "You must supply a callable"
134
145
  end
@@ -1,7 +1,7 @@
1
1
  module Shifty
2
2
  module Taggable
3
3
  def tags=(tag_arg)
4
- @tags = [tag_arg].flatten.compact
4
+ @tags = [tag_arg].flatten.compact.uniq
5
5
  end
6
6
 
7
7
  def criteria=(criteria_arg)
@@ -1,3 +1,3 @@
1
1
  module Shifty
2
- VERSION = "0.4.2"
2
+ VERSION = "0.5.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shifty
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.2
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joel Helbling
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-05-11 00:00:00.000000000 Z
11
+ date: 2023-05-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake