pipetree 0.0.4 → 0.0.5
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 +4 -4
- data/CHANGES.md +4 -0
- data/lib/pipetree/flow.rb +16 -4
- data/lib/pipetree/version.rb +1 -1
- data/pipetree.gemspec +2 -0
- data/test/altering_test.rb +7 -7
- data/test/flow_test.rb +4 -1
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fa9de99071c198cb1ac6254f7c5fc9eddbc3eaa1
|
4
|
+
data.tar.gz: ceb3b6450907aeccd607e8704fc78a24fbcd2b87
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d57ed120a07f1ab17b84c96539eefad984a702156f72dfd4d3e86aa03e6185df9b1786ffe7af666d75a4dfd1168ffd4b090ffd89b98a8d1f757dbc2fc1c1012a
|
7
|
+
data.tar.gz: 75183aa0a9538807dbd9e3d7fc832d7645618d6275be743ff9234aa4fbd4512d937917e24a73ea6351734572758adf3a71668a43af0a2186460e0b20afa9e067
|
data/CHANGES.md
CHANGED
@@ -1,3 +1,7 @@
|
|
1
|
+
# 0.0.5
|
2
|
+
|
3
|
+
* `Flow` doesn't inherit from `Array` anymore. Temporarily use `Uber::Delegates` to achieve the same interface. This will change in 0.1.x when `Insert` works against an array. This makes `Flow.new` the new canonical constructor which allows us to initialize `step@proc` properly.
|
4
|
+
|
1
5
|
# 0.0.3
|
2
6
|
|
3
7
|
* Improved insert semantics.
|
data/lib/pipetree/flow.rb
CHANGED
@@ -1,10 +1,17 @@
|
|
1
1
|
class Pipetree < Array
|
2
|
-
class Flow
|
2
|
+
class Flow
|
3
3
|
require "pipetree/flow/inspect"
|
4
4
|
include Inspect
|
5
5
|
require "pipetree/flow/step_map"
|
6
6
|
require "pipetree/insert"
|
7
7
|
|
8
|
+
def initialize(*args)
|
9
|
+
@steps = Array.new(*args)
|
10
|
+
@step2proc = StepMap.new
|
11
|
+
end
|
12
|
+
|
13
|
+
# TODO: don't inherit from Array, because we don't want Array[].
|
14
|
+
|
8
15
|
module Operators
|
9
16
|
# Optimize the most common steps with Stay/And objects that are faster than procs.
|
10
17
|
def <(proc, options={})
|
@@ -37,15 +44,20 @@ class Pipetree < Array
|
|
37
44
|
options = { append: true }.merge(options)
|
38
45
|
|
39
46
|
insert!(step, options).tap do
|
40
|
-
@step2proc ||= StepMap.new
|
41
47
|
@step2proc[step] = options[:name], original_proc, operator
|
42
48
|
end
|
49
|
+
|
50
|
+
self
|
43
51
|
end
|
44
52
|
|
45
53
|
# :private:
|
46
54
|
def index(proc) # @step2proc: { <On @proc> => {proc: @proc, name: "trb.validate", operator: "&"} }
|
47
|
-
on = @step2proc.find_proc(proc) and return
|
55
|
+
on = @step2proc.find_proc(proc) and return @steps.index(on)
|
48
56
|
end
|
57
|
+
|
58
|
+
require "uber/delegates"
|
59
|
+
extend Uber::Delegates
|
60
|
+
delegates :@steps, :<<, :each_with_index, :[]=, :delete_at, :insert, :unshift # FIXME: make Insert properly decoupled!
|
49
61
|
end
|
50
62
|
include Operators
|
51
63
|
|
@@ -53,7 +65,7 @@ class Pipetree < Array
|
|
53
65
|
def call(input, options)
|
54
66
|
input = [Right, input]
|
55
67
|
|
56
|
-
inject(input) do |memooo, step|
|
68
|
+
@steps.inject(input) do |memooo, step|
|
57
69
|
last, memo = memooo
|
58
70
|
step.call(last, memo, options)
|
59
71
|
end
|
data/lib/pipetree/version.rb
CHANGED
data/pipetree.gemspec
CHANGED
@@ -17,6 +17,8 @@ Gem::Specification.new do |spec|
|
|
17
17
|
spec.test_files = spec.files.grep(%r{^(test)/})
|
18
18
|
spec.require_paths = ["lib"]
|
19
19
|
|
20
|
+
spec.add_dependency "uber"
|
21
|
+
|
20
22
|
spec.add_development_dependency "bundler"
|
21
23
|
spec.add_development_dependency "rake"
|
22
24
|
spec.add_development_dependency "minitest"
|
data/test/altering_test.rb
CHANGED
@@ -37,12 +37,12 @@ class FlowInsertTest < Minitest::Spec
|
|
37
37
|
B = ->{ }
|
38
38
|
C = ->{ }
|
39
39
|
|
40
|
-
it { pipe = Pipetree::Flow
|
41
|
-
it { pipe = Pipetree::Flow
|
42
|
-
it { pipe = Pipetree::Flow
|
43
|
-
it { pipe = Pipetree::Flow
|
44
|
-
it { pipe = Pipetree::Flow
|
45
|
-
it { pipe = Pipetree::Flow
|
46
|
-
it { pipe = Pipetree::Flow
|
40
|
+
it { pipe = Pipetree::Flow.new.>(A).>(B).inspect.must_equal %{[>A,>B]} }
|
41
|
+
it { pipe = Pipetree::Flow.new.>(A).>(B, before: A).inspect.must_equal %{[>B,>A]} }
|
42
|
+
it { pipe = Pipetree::Flow.new.>(A).>(B).>(C, after: A).inspect.must_equal %{[>A,>C,>B]} }
|
43
|
+
it { pipe = Pipetree::Flow.new.>(A).>(C, append: true).inspect.must_equal %{[>A,>C]} }
|
44
|
+
it { pipe = Pipetree::Flow.new.>(A).>(C, prepend: true).inspect.must_equal %{[>C,>A]} }
|
45
|
+
it { pipe = Pipetree::Flow.new.>(A).>(C, replace: A).inspect.must_equal %{[>C]} }
|
46
|
+
it { pipe = Pipetree::Flow.new.>(A)._insert(A, {delete: true}, nil, nil).inspect.must_equal %{[]} }
|
47
47
|
# FIXME: add :delete and :replace.
|
48
48
|
end
|
data/test/flow_test.rb
CHANGED
@@ -74,7 +74,7 @@ class FlowTest < Minitest::Spec
|
|
74
74
|
#---
|
75
75
|
# return value is new input.
|
76
76
|
it do
|
77
|
-
pipe = Pipetree::Flow[
|
77
|
+
pipe = Pipetree::Flow.new [
|
78
78
|
Pipetree::Flow::On.new(Pipetree::Flow::Right, ->(last, value, options) { [Pipetree::Flow::Right, value.reverse] } )
|
79
79
|
]
|
80
80
|
pipe.("Hello", {}).must_equal [Pipetree::Flow::Right, "olleH"]
|
@@ -129,6 +129,9 @@ class FlowTest < Minitest::Spec
|
|
129
129
|
it { pipe.index(Aaa).must_equal 0 }
|
130
130
|
# with alias
|
131
131
|
it { pipe.index("a.triple").must_equal 2 }
|
132
|
+
|
133
|
+
# without steps
|
134
|
+
it { Pipetree::Flow.new.index(B).must_equal nil }
|
132
135
|
end
|
133
136
|
|
134
137
|
#---
|
metadata
CHANGED
@@ -1,15 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pipetree
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nick Sutterer
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-12-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: uber
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: bundler
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|