trailblazer-operation 0.0.7 → 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +13 -5
- data/CHANGES.md +13 -0
- data/Rakefile +1 -1
- data/lib/trailblazer/operation/1.9.3/option.rb +36 -0
- data/lib/trailblazer/operation/option.rb +54 -0
- data/lib/trailblazer/operation/pipetree.rb +7 -24
- data/lib/trailblazer/operation/version.rb +1 -1
- data/lib/trailblazer/skill.rb +14 -0
- data/test/2.0.0-pipetree_test.rb +65 -0
- data/test/gemfiles/Gemfile.ruby-1.9.lock +6 -5
- metadata +26 -22
checksums.yaml
CHANGED
@@ -1,7 +1,15 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
YWZkYzZlMjRkOGZkM2RlYzNiMmY2NGE1MjY3YTA2NTk0YWExNDNkYw==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
ZTU3MGVjODM2NjdjNTQ4YmRjMDM1YmMxOGViNGYxMTg3MTY2ZGVjMw==
|
5
7
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
YzgzNDY1YjhhNmZjMmJiYjBjYzEyNTRlMTY1ODYyZGVhOTFjYjQyZTY5ZDMy
|
10
|
+
ZGEzY2UwNWFkZWYyMjE0ODMwMWI2NjllYTU2NTAwOTZkN2IwNmJkMjA2ZTcw
|
11
|
+
MjA2MWIzY2IxZDFiNmQ5OTVmY2NkNWY2ZTM0ZGE4ZDJkN2FiYTQ=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
NjE1ODZhMDI4YWM1MjZjZDY0NDhlMWZiN2ZkNWUzZmJkMTFhMTBkMzA2YzM3
|
14
|
+
YjgxZGE3NmMzNjE0YjZjYmFlZWUyMmFmYjEwOTE3NDc0OWVkMTIzNWI3ODc5
|
15
|
+
ODNlY2QzMmVhMDNlYTEzYzA3Nzc2NzdlYTA5NTM0NmFmZTE3OGI=
|
data/CHANGES.md
CHANGED
@@ -1,3 +1,16 @@
|
|
1
|
+
## 0.0.8
|
2
|
+
|
3
|
+
* Introduce a new keyword signature for steps:
|
4
|
+
|
5
|
+
```ruby
|
6
|
+
step ->(options, params:, **) { options["x"] = params[:id] }
|
7
|
+
```
|
8
|
+
|
9
|
+
The same API works for instance methods and `Callable`s.
|
10
|
+
|
11
|
+
Note that the implementation of `Option` and `Skills#to_hash` are improveable, but work just fine for now.
|
12
|
+
|
13
|
+
|
1
14
|
## 0.0.7
|
2
15
|
|
3
16
|
* Simplify inheritance by basically removing it.
|
data/Rakefile
CHANGED
@@ -10,7 +10,7 @@ Rake::TestTask.new(:test) do |test|
|
|
10
10
|
test_files = FileList['test/*_test.rb']
|
11
11
|
|
12
12
|
if RUBY_VERSION == "1.9.3"
|
13
|
-
test_files = test_files - %w{test/dry_container_test.rb}
|
13
|
+
test_files = test_files - %w{test/dry_container_test.rb test/2.0.0-pipetree_test.rb}
|
14
14
|
end
|
15
15
|
|
16
16
|
test.test_files = test_files
|
@@ -0,0 +1,36 @@
|
|
1
|
+
class Trailblazer::Operation
|
2
|
+
# :private:
|
3
|
+
module Option
|
4
|
+
def self.call(proc, &block)
|
5
|
+
type = :proc
|
6
|
+
|
7
|
+
option =
|
8
|
+
if proc.is_a? Symbol
|
9
|
+
type = :symbol
|
10
|
+
->(input, _options) { call_method(proc, input, _options) }
|
11
|
+
elsif proc.is_a? Proc
|
12
|
+
->(input, _options) { call_proc(proc, input, _options) }
|
13
|
+
elsif proc.is_a? Uber::Callable
|
14
|
+
type = :callable
|
15
|
+
->(input, _options) { call_callable(proc, input, _options) }
|
16
|
+
end
|
17
|
+
|
18
|
+
yield type if block_given?
|
19
|
+
option
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.call_proc(proc, input, options)
|
23
|
+
proc.(options)
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.call_method(proc, input, options)
|
27
|
+
input.send(proc, options)
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.call_callable(callable, input, options)
|
31
|
+
callable.(options)
|
32
|
+
end
|
33
|
+
|
34
|
+
KW = Option
|
35
|
+
end # Option
|
36
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
class Trailblazer::Operation
|
2
|
+
# :private:
|
3
|
+
# This code is not beautiful, but could also be worse.
|
4
|
+
# I'm expecting some of this to go to Uber, as we use this pattern everywhere.
|
5
|
+
class Option
|
6
|
+
def self.call(proc, &block)
|
7
|
+
type = :proc
|
8
|
+
|
9
|
+
option =
|
10
|
+
if proc.is_a? Symbol
|
11
|
+
type = :symbol
|
12
|
+
->(input, *_options) { call_method(proc, input, *_options) }
|
13
|
+
elsif proc.is_a? Proc
|
14
|
+
->(input, *_options) { call_proc(proc, input, *_options) }
|
15
|
+
elsif proc.is_a? Uber::Callable
|
16
|
+
type = :callable
|
17
|
+
->(input, *_options) { call_callable(proc, input, *_options) }
|
18
|
+
end
|
19
|
+
|
20
|
+
yield type if block_given?
|
21
|
+
option
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.call_proc(proc, input, *options)
|
25
|
+
proc.(*options)
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.call_method(proc, input, *options)
|
29
|
+
input.send(proc, *options)
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.call_callable(callable, input, *options)
|
33
|
+
callable.(*options)
|
34
|
+
end
|
35
|
+
|
36
|
+
# Call the option with keyword arguments. Ruby <= 2.0.
|
37
|
+
class KW < Option
|
38
|
+
def self.call_proc(proc, input, options)
|
39
|
+
return proc.(options) if proc.arity == 1
|
40
|
+
proc.(options, **options)
|
41
|
+
end
|
42
|
+
|
43
|
+
def self.call_method(proc, input, options)
|
44
|
+
return input.send(proc, options) if input.method(proc).arity == 1 # TODO: remove this
|
45
|
+
input.send(proc, options, **options)
|
46
|
+
end
|
47
|
+
|
48
|
+
def self.call_callable(callable, input, options)
|
49
|
+
return callable.(options) if callable.method(:call).arity == 1
|
50
|
+
callable.(options, **options)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -3,6 +3,12 @@ require "pipetree/flow"
|
|
3
3
|
require "trailblazer/operation/result"
|
4
4
|
require "uber/option"
|
5
5
|
|
6
|
+
if RUBY_VERSION == "1.9.3"
|
7
|
+
require "trailblazer/operation/1.9.3/option" # TODO: rename to something better.
|
8
|
+
else
|
9
|
+
require "trailblazer/operation/option" # TODO: rename to something better.
|
10
|
+
end
|
11
|
+
|
6
12
|
class Trailblazer::Operation
|
7
13
|
New = ->(klass, options) { klass.new(options) } # returns operation instance.
|
8
14
|
|
@@ -66,39 +72,16 @@ class Trailblazer::Operation
|
|
66
72
|
DSL.insert(self["pipetree"], operator, proc, options, definer_name: self.name)
|
67
73
|
end
|
68
74
|
|
69
|
-
# :private:
|
70
|
-
module Option
|
71
|
-
def self.call(proc, &block)
|
72
|
-
type = :proc
|
73
|
-
|
74
|
-
option =
|
75
|
-
if proc.is_a? Symbol
|
76
|
-
type = :symbol
|
77
|
-
->(input, *_options) { input.send(proc, *_options) }
|
78
|
-
elsif proc.is_a? Proc
|
79
|
-
# ->(input, options) { proc.(**options) }
|
80
|
-
->(input, *_options) { proc.(*_options) }
|
81
|
-
elsif proc.is_a? Uber::Callable
|
82
|
-
type = :callable
|
83
|
-
->(input, *_options) { proc.(*_options) }
|
84
|
-
end
|
85
|
-
|
86
|
-
yield type if block_given?
|
87
|
-
option
|
88
|
-
end
|
89
|
-
end
|
90
|
-
|
91
75
|
# :public:
|
92
76
|
# Wrap the step into a proc that only passes `options` to the step.
|
93
77
|
# This is pure convenience for the developer and will be the default
|
94
78
|
# API for steps. ATM, we also automatically generate a step `:name`.
|
95
79
|
def self.insert(pipe, operator, proc, options={}, kws={}) # TODO: definer_name is a hack for debugging, only.
|
96
|
-
# proc = Uber::Option[proc]
|
97
80
|
_proc =
|
98
81
|
if options[:wrap] == false
|
99
82
|
proc
|
100
83
|
else
|
101
|
-
Option.(proc) do |type|
|
84
|
+
Option::KW.(proc) do |type|
|
102
85
|
options[:name] ||= proc if type == :symbol
|
103
86
|
options[:name] ||= "#{kws[:definer_name]}:#{proc.source_location.last}" if proc.is_a? Proc if type == :proc
|
104
87
|
options[:name] ||= proc.class if type == :callable
|
data/lib/trailblazer/skill.rb
CHANGED
@@ -30,6 +30,20 @@ module Trailblazer
|
|
30
30
|
@mutable_options
|
31
31
|
end
|
32
32
|
|
33
|
+
# Called when Ruby transforms options into kw args, via **options.
|
34
|
+
# TODO: this method has massive potential for speed improvements.
|
35
|
+
def to_hash
|
36
|
+
{}.tap do |h|
|
37
|
+
arr = to_runtime_data << to_mutable_data
|
38
|
+
|
39
|
+
|
40
|
+
arr.each { |hsh|
|
41
|
+
hsh.each { |k, v| h[k.to_sym] = v }
|
42
|
+
}
|
43
|
+
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
33
47
|
# Look through a list of containers until you find the skill.
|
34
48
|
class Resolver
|
35
49
|
# alternative implementation:
|
@@ -0,0 +1,65 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
class Ruby200PipetreeTest < Minitest::Spec
|
4
|
+
class Create < Trailblazer::Operation
|
5
|
+
consider ->(*, params:, **) { params["run"] } # only test kws.
|
6
|
+
step ->(options, params:nil, **) { options["x"] = params["run"] } # read and write.
|
7
|
+
step ->(options) { options["y"] = options["params"]["run"] } # old API.
|
8
|
+
end
|
9
|
+
|
10
|
+
it { Create.("run" => false).inspect("x", "y").must_equal %{<Result:false [nil, nil] >} }
|
11
|
+
it { Create.("run" => true).inspect("x", "y").must_equal %{<Result:true [true, true] >} }
|
12
|
+
|
13
|
+
#- instance methods
|
14
|
+
class Update < Trailblazer::Operation
|
15
|
+
consider :params! # only test kws.
|
16
|
+
step :x! # read and write.
|
17
|
+
step :y! # old API.
|
18
|
+
|
19
|
+
def params!(*, params:, **)
|
20
|
+
params["run"]
|
21
|
+
end
|
22
|
+
|
23
|
+
def x!(options, params:nil, **)
|
24
|
+
options["x"] = params["run"]
|
25
|
+
end
|
26
|
+
|
27
|
+
def y!(options)
|
28
|
+
options["y"] = options["params"]["run"]
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
it { Update.("run" => false).inspect("x", "y").must_equal %{<Result:false [nil, nil] >} }
|
33
|
+
it { Update.("run" => true).inspect("x", "y").must_equal %{<Result:true [true, true] >} }
|
34
|
+
|
35
|
+
|
36
|
+
class Delete < Trailblazer::Operation
|
37
|
+
class Params
|
38
|
+
extend Uber::Callable
|
39
|
+
def self.call(*, params:, **)
|
40
|
+
params["run"]
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
class X
|
45
|
+
extend Uber::Callable
|
46
|
+
def self.call(options, params:nil, **)
|
47
|
+
options["x"] = params["run"]
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
class Y
|
52
|
+
extend Uber::Callable
|
53
|
+
def self.call(options)
|
54
|
+
options["y"] = options["params"]["run"]
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
consider Params
|
59
|
+
step X
|
60
|
+
step Y
|
61
|
+
end
|
62
|
+
|
63
|
+
it { Delete.("run" => false).inspect("x", "y").must_equal %{<Result:false [nil, nil] >} }
|
64
|
+
it { Delete.("run" => true).inspect("x", "y").must_equal %{<Result:true [true, true] >} }
|
65
|
+
end
|
@@ -1,9 +1,9 @@
|
|
1
1
|
PATH
|
2
2
|
remote: ../../
|
3
3
|
specs:
|
4
|
-
trailblazer-operation (0.0.
|
4
|
+
trailblazer-operation (0.0.8)
|
5
5
|
declarative
|
6
|
-
pipetree (>= 0.0.
|
6
|
+
pipetree (>= 0.0.5, < 0.1.0)
|
7
7
|
uber (>= 0.1.0, < 0.2.0)
|
8
8
|
|
9
9
|
GEM
|
@@ -11,9 +11,10 @@ GEM
|
|
11
11
|
specs:
|
12
12
|
declarative (0.0.8)
|
13
13
|
uber (>= 0.0.15)
|
14
|
-
minitest (5.
|
15
|
-
pipetree (0.0.
|
16
|
-
|
14
|
+
minitest (5.10.1)
|
15
|
+
pipetree (0.0.5)
|
16
|
+
uber
|
17
|
+
rake (12.0.0)
|
17
18
|
uber (0.1.0)
|
18
19
|
|
19
20
|
PLATFORMS
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: trailblazer-operation
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nick Sutterer
|
@@ -14,96 +14,96 @@ dependencies:
|
|
14
14
|
name: uber
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - ! '>='
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: 0.1.0
|
20
|
-
- -
|
20
|
+
- - <
|
21
21
|
- !ruby/object:Gem::Version
|
22
22
|
version: 0.2.0
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
25
|
version_requirements: !ruby/object:Gem::Requirement
|
26
26
|
requirements:
|
27
|
-
- -
|
27
|
+
- - ! '>='
|
28
28
|
- !ruby/object:Gem::Version
|
29
29
|
version: 0.1.0
|
30
|
-
- -
|
30
|
+
- - <
|
31
31
|
- !ruby/object:Gem::Version
|
32
32
|
version: 0.2.0
|
33
33
|
- !ruby/object:Gem::Dependency
|
34
34
|
name: declarative
|
35
35
|
requirement: !ruby/object:Gem::Requirement
|
36
36
|
requirements:
|
37
|
-
- -
|
37
|
+
- - ! '>='
|
38
38
|
- !ruby/object:Gem::Version
|
39
39
|
version: '0'
|
40
40
|
type: :runtime
|
41
41
|
prerelease: false
|
42
42
|
version_requirements: !ruby/object:Gem::Requirement
|
43
43
|
requirements:
|
44
|
-
- -
|
44
|
+
- - ! '>='
|
45
45
|
- !ruby/object:Gem::Version
|
46
46
|
version: '0'
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: pipetree
|
49
49
|
requirement: !ruby/object:Gem::Requirement
|
50
50
|
requirements:
|
51
|
-
- -
|
51
|
+
- - ! '>='
|
52
52
|
- !ruby/object:Gem::Version
|
53
53
|
version: 0.0.5
|
54
|
-
- -
|
54
|
+
- - <
|
55
55
|
- !ruby/object:Gem::Version
|
56
56
|
version: 0.1.0
|
57
57
|
type: :runtime
|
58
58
|
prerelease: false
|
59
59
|
version_requirements: !ruby/object:Gem::Requirement
|
60
60
|
requirements:
|
61
|
-
- -
|
61
|
+
- - ! '>='
|
62
62
|
- !ruby/object:Gem::Version
|
63
63
|
version: 0.0.5
|
64
|
-
- -
|
64
|
+
- - <
|
65
65
|
- !ruby/object:Gem::Version
|
66
66
|
version: 0.1.0
|
67
67
|
- !ruby/object:Gem::Dependency
|
68
68
|
name: bundler
|
69
69
|
requirement: !ruby/object:Gem::Requirement
|
70
70
|
requirements:
|
71
|
-
- -
|
71
|
+
- - ! '>='
|
72
72
|
- !ruby/object:Gem::Version
|
73
73
|
version: '0'
|
74
74
|
type: :development
|
75
75
|
prerelease: false
|
76
76
|
version_requirements: !ruby/object:Gem::Requirement
|
77
77
|
requirements:
|
78
|
-
- -
|
78
|
+
- - ! '>='
|
79
79
|
- !ruby/object:Gem::Version
|
80
80
|
version: '0'
|
81
81
|
- !ruby/object:Gem::Dependency
|
82
82
|
name: rake
|
83
83
|
requirement: !ruby/object:Gem::Requirement
|
84
84
|
requirements:
|
85
|
-
- -
|
85
|
+
- - ! '>='
|
86
86
|
- !ruby/object:Gem::Version
|
87
87
|
version: '0'
|
88
88
|
type: :development
|
89
89
|
prerelease: false
|
90
90
|
version_requirements: !ruby/object:Gem::Requirement
|
91
91
|
requirements:
|
92
|
-
- -
|
92
|
+
- - ! '>='
|
93
93
|
- !ruby/object:Gem::Version
|
94
94
|
version: '0'
|
95
95
|
- !ruby/object:Gem::Dependency
|
96
96
|
name: minitest
|
97
97
|
requirement: !ruby/object:Gem::Requirement
|
98
98
|
requirements:
|
99
|
-
- -
|
99
|
+
- - ! '>='
|
100
100
|
- !ruby/object:Gem::Version
|
101
101
|
version: '0'
|
102
102
|
type: :development
|
103
103
|
prerelease: false
|
104
104
|
version_requirements: !ruby/object:Gem::Requirement
|
105
105
|
requirements:
|
106
|
-
- -
|
106
|
+
- - ! '>='
|
107
107
|
- !ruby/object:Gem::Version
|
108
108
|
version: '0'
|
109
109
|
description: Trailblazer's operation object.
|
@@ -113,19 +113,22 @@ executables: []
|
|
113
113
|
extensions: []
|
114
114
|
extra_rdoc_files: []
|
115
115
|
files:
|
116
|
-
-
|
117
|
-
-
|
116
|
+
- .gitignore
|
117
|
+
- .travis.yml
|
118
118
|
- CHANGES.md
|
119
119
|
- Gemfile
|
120
120
|
- README.md
|
121
121
|
- Rakefile
|
122
122
|
- lib/trailblazer/operation.rb
|
123
|
+
- lib/trailblazer/operation/1.9.3/option.rb
|
123
124
|
- lib/trailblazer/operation/generic.rb
|
125
|
+
- lib/trailblazer/operation/option.rb
|
124
126
|
- lib/trailblazer/operation/pipetree.rb
|
125
127
|
- lib/trailblazer/operation/result.rb
|
126
128
|
- lib/trailblazer/operation/skill.rb
|
127
129
|
- lib/trailblazer/operation/version.rb
|
128
130
|
- lib/trailblazer/skill.rb
|
131
|
+
- test/2.0.0-pipetree_test.rb
|
129
132
|
- test/benchmark/skill_resolver_benchmark.rb
|
130
133
|
- test/call_test.rb
|
131
134
|
- test/dry_container_test.rb
|
@@ -150,21 +153,22 @@ require_paths:
|
|
150
153
|
- lib
|
151
154
|
required_ruby_version: !ruby/object:Gem::Requirement
|
152
155
|
requirements:
|
153
|
-
- -
|
156
|
+
- - ! '>='
|
154
157
|
- !ruby/object:Gem::Version
|
155
158
|
version: 1.9.3
|
156
159
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
157
160
|
requirements:
|
158
|
-
- -
|
161
|
+
- - ! '>='
|
159
162
|
- !ruby/object:Gem::Version
|
160
163
|
version: '0'
|
161
164
|
requirements: []
|
162
165
|
rubyforge_project:
|
163
|
-
rubygems_version: 2.
|
166
|
+
rubygems_version: 2.4.8
|
164
167
|
signing_key:
|
165
168
|
specification_version: 4
|
166
169
|
summary: Trailblazer's operation object with dependency management and pipetree flow.
|
167
170
|
test_files:
|
171
|
+
- test/2.0.0-pipetree_test.rb
|
168
172
|
- test/benchmark/skill_resolver_benchmark.rb
|
169
173
|
- test/call_test.rb
|
170
174
|
- test/dry_container_test.rb
|