trailblazer-operation 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/trailblazer/operation/pipetree.rb +25 -4
- data/lib/trailblazer/operation/version.rb +1 -1
- data/test/call_test.rb +1 -1
- data/test/operation_skill_test.rb +3 -4
- data/test/pipetree_test.rb +18 -5
- data/test/result_test.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 518732c6417e754d620873510361cd17958defb1
|
4
|
+
data.tar.gz: a77e4f2314161fb500b15017c79e81e1d53ffb09
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0b88e57e5469ab4f41f13954a4c92469f98c661c883c8c1bb1a3f192a32a9f8389e3d941768c867faa9a40d119cf671bca666389a2da704f4957cb7cffcb785d
|
7
|
+
data.tar.gz: e265e9034e34e802d0364ad3402ab2c5d9f02e1ce5bff8a72a9f78341aa3f1c04abd84625d40cd3abce9d64c54a8455b4a4281809cc2ce5351ac758066c688f1
|
data/CHANGES.md
CHANGED
@@ -4,9 +4,10 @@ require "trailblazer/operation/result"
|
|
4
4
|
require "uber/option"
|
5
5
|
|
6
6
|
class Trailblazer::Operation
|
7
|
-
New
|
8
|
-
Process = ->(operation, options) { operation.process(options["params"]) }
|
7
|
+
New = ->(klass, options) { klass.new(options) } # returns operation instance.
|
9
8
|
|
9
|
+
# Implements the API to populate the operation's pipetree and
|
10
|
+
# `Operation::call` to invoke the latter.
|
10
11
|
# http://trailblazer.to/gems/operation/2.0/pipetree.html
|
11
12
|
module Pipetree
|
12
13
|
def self.included(includer)
|
@@ -14,7 +15,7 @@ class Trailblazer::Operation
|
|
14
15
|
includer.extend DSL # ::|, ::> and friends.
|
15
16
|
|
16
17
|
includer.initialize_pipetree!
|
17
|
-
includer.>> New, name: "operation.new"
|
18
|
+
includer.>> New, name: "operation.new", wrap: false
|
18
19
|
end
|
19
20
|
|
20
21
|
module ClassMethods
|
@@ -47,9 +48,27 @@ class Trailblazer::Operation
|
|
47
48
|
def <(*args); _insert(:<, *args) end
|
48
49
|
|
49
50
|
# :private:
|
51
|
+
# High-level user step API that allows ->(options) procs.
|
50
52
|
def _insert(operator, proc, options={})
|
51
53
|
heritage.record(:_insert, operator, proc, options)
|
52
|
-
|
54
|
+
|
55
|
+
# proc = Uber::Option[proc]
|
56
|
+
_proc =
|
57
|
+
if options[:wrap] == false
|
58
|
+
proc
|
59
|
+
elsif proc.is_a? Symbol
|
60
|
+
options[:name] ||= proc
|
61
|
+
->(input, _options) { input.send(proc, _options) }
|
62
|
+
elsif proc.is_a? Proc
|
63
|
+
options[:name] ||= "#{self.name}:#{proc.source_location.last}" if proc.is_a? Proc
|
64
|
+
# ->(input, options) { proc.(**options) }
|
65
|
+
->(input, _options) { proc.(_options) }
|
66
|
+
elsif proc.is_a? Uber::Callable
|
67
|
+
options[:name] ||= proc.class
|
68
|
+
->(input, _options) { proc.(_options) }
|
69
|
+
end
|
70
|
+
|
71
|
+
self["pipetree"].send(operator, _proc, options) # ex: pipetree.> Validate, after: Model::Build
|
53
72
|
end
|
54
73
|
|
55
74
|
def ~(cfg)
|
@@ -71,6 +90,8 @@ class Trailblazer::Operation
|
|
71
90
|
|
72
91
|
# Try to abstract as much as possible from the imported module. This is for
|
73
92
|
# forward-compatibility.
|
93
|
+
# Note that Import#call will push the step directly on the pipetree which gives it the
|
94
|
+
# low-level (input, options) interface.
|
74
95
|
Import = Struct.new(:operation, :user_options) do
|
75
96
|
def call(operator, step, options)
|
76
97
|
operation["pipetree"].send operator, step, options.merge(user_options)
|
data/test/call_test.rb
CHANGED
@@ -18,7 +18,7 @@ class CallTest < Minitest::Spec
|
|
18
18
|
#---
|
19
19
|
# success?
|
20
20
|
class Update < Trailblazer::Operation
|
21
|
-
self.& ->(
|
21
|
+
self.& ->(options) { options["params"] }, after: "operation.new"
|
22
22
|
end
|
23
23
|
|
24
24
|
it { Update.(true).success?.must_equal true }
|
@@ -12,12 +12,11 @@ class OperationSkillTest < Minitest::Spec
|
|
12
12
|
end
|
13
13
|
|
14
14
|
class OperationCompetenceTest < Minitest::Spec
|
15
|
-
Call = ->(input, options) { input.call }
|
16
15
|
# Operation#[]
|
17
16
|
# Operation#[]=
|
18
17
|
# arbitrary options can be saved via Op#[].
|
19
18
|
class Create < Trailblazer::Operation
|
20
|
-
self.>
|
19
|
+
self.> :call
|
21
20
|
|
22
21
|
def call(*)
|
23
22
|
self["drink"] = "Little Creatures"
|
@@ -38,7 +37,7 @@ class OperationCompetenceTest < Minitest::Spec
|
|
38
37
|
# Operation::[]
|
39
38
|
# Operation::[]=
|
40
39
|
class Update < Trailblazer::Operation
|
41
|
-
self.>
|
40
|
+
self.> :call
|
42
41
|
|
43
42
|
self["drink"] = "Beer"
|
44
43
|
|
@@ -57,7 +56,7 @@ class OperationCompetenceTest < Minitest::Spec
|
|
57
56
|
|
58
57
|
# instance can override class-level
|
59
58
|
class Delete < Trailblazer::Operation
|
60
|
-
self.>
|
59
|
+
self.> :call
|
61
60
|
|
62
61
|
self["drink"] = "Beer"
|
63
62
|
|
data/test/pipetree_test.rb
CHANGED
@@ -54,29 +54,42 @@ class PipetreeTest < Minitest::Spec
|
|
54
54
|
# ::>, ::<, ::>>, :&
|
55
55
|
# with proc, method, callable.
|
56
56
|
class Right < Trailblazer::Operation
|
57
|
-
|
57
|
+
MyProc = ->(*) { }
|
58
|
+
self.> ->(options) { options[">"] = options["params"][:id] }, better_api: true
|
58
59
|
|
59
60
|
self.> :method_name!
|
60
61
|
def method_name!(options); self["method_name!"] = options["params"][:id] end
|
61
62
|
|
62
63
|
class MyCallable
|
63
64
|
include Uber::Callable
|
64
|
-
def call(
|
65
|
+
def call(options); options["callable"] = options["params"][:id] end
|
65
66
|
end
|
66
67
|
self.> MyCallable.new
|
67
68
|
end
|
68
69
|
|
69
70
|
it { Right.( id: 1 ).slice(">", "method_name!", "callable").must_equal [1, 1, 1] }
|
70
|
-
it { Right["pipetree"].inspect.must_equal %{[>>operation.new,>
|
71
|
+
it { Right["pipetree"].inspect.must_equal %{[>>operation.new,>PipetreeTest::Right:58,>method_name!,>PipetreeTest::Right::MyCallable]} }
|
71
72
|
|
72
73
|
#---
|
73
74
|
# inheritance
|
74
75
|
class Righter < Right
|
75
|
-
self.> ->(
|
76
|
+
self.> ->(options) { options["righter"] = true }
|
76
77
|
end
|
77
78
|
|
78
79
|
it { Righter.( id: 1 ).slice(">", "method_name!", "callable", "righter").must_equal [1, 1, 1, true] }
|
79
80
|
end
|
80
81
|
|
82
|
+
#---
|
83
|
+
#- kw args
|
84
|
+
class OperationKwArgsTest < Minitest::Spec
|
85
|
+
Song = Struct.new(:id)
|
81
86
|
|
82
|
-
|
87
|
+
class Create < Trailblazer::Operation
|
88
|
+
self.> ->(options) { options["model"] = "Object" }
|
89
|
+
# self.> ->(model:) { snippet }
|
90
|
+
end
|
91
|
+
|
92
|
+
it {
|
93
|
+
skip
|
94
|
+
Create.() }
|
95
|
+
end
|
data/test/result_test.rb
CHANGED
@@ -17,7 +17,7 @@ class ResultTest < Minitest::Spec
|
|
17
17
|
it { Result.new(true, "x"=> true, "y"=>1, "z"=>2).inspect("z", "y").must_equal %{<Result:true [2, 1] >} }
|
18
18
|
|
19
19
|
class Create < Trailblazer::Operation
|
20
|
-
self.>
|
20
|
+
self.> :call
|
21
21
|
|
22
22
|
def call(*)
|
23
23
|
self[:message] = "Result objects are actually quite handy!"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
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.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-
|
11
|
+
date: 2016-11-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: uber
|