trailblazer 2.0.0.beta2 → 2.0.0.beta3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGES.md +4 -0
- data/Gemfile +1 -1
- data/lib/trailblazer/operation/rescue.rb +4 -2
- data/lib/trailblazer/version.rb +1 -1
- data/test/docs/operation_test.rb +54 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 36d5743aefbaa5f3164a9d247adfcef5a4acd3ad
|
4
|
+
data.tar.gz: 4d263f2e11657140bccbd98e90915896b00d39db
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 92afde635725edbf16f2c3705fc9f3e1462ab955c5fbb273754f58fc1c79bff1916cb5ad4aeb319784d6a1589b8dc1371283469b74a540922e1bfeda2730f3f7
|
7
|
+
data.tar.gz: e323a24a729b87ae7fcb50ecc8a2483c237f0f7f2edf0e6025185d8787b26abda307d176f3b0b884fd642d04dc0c958e01b1e8ba2b60cdd6b562707569829b33
|
data/CHANGES.md
CHANGED
@@ -102,6 +102,10 @@ You can now inject the following objects via `::call`:
|
|
102
102
|
|
103
103
|
* You can't call `Create.().contract` anymore. The contract instance(s) are available through the `Result` object.
|
104
104
|
|
105
|
+
# 2.0.0.beta3
|
106
|
+
|
107
|
+
* New, very slick keyword arguments for steps.
|
108
|
+
|
105
109
|
# 2.0.0.beta2
|
106
110
|
|
107
111
|
* Removed `Operation::Controller`.
|
data/Gemfile
CHANGED
@@ -1,8 +1,10 @@
|
|
1
1
|
class Trailblazer::Operation
|
2
2
|
module Rescue
|
3
|
-
|
3
|
+
Noop = ->(*) {}
|
4
|
+
|
5
|
+
def self.import!(_operation, import, *exceptions, handler: Noop, &block)
|
4
6
|
exceptions = [StandardError] unless exceptions.any?
|
5
|
-
handler =
|
7
|
+
handler = Option.(handler)
|
6
8
|
|
7
9
|
rescue_block = ->(options, operation, *, &nested_pipe) {
|
8
10
|
begin
|
data/lib/trailblazer/version.rb
CHANGED
data/test/docs/operation_test.rb
CHANGED
@@ -44,3 +44,57 @@ class DndTest < Minitest::Spec
|
|
44
44
|
self.< Wrap
|
45
45
|
end
|
46
46
|
end
|
47
|
+
|
48
|
+
class DocsResultTest < Minitest::Spec
|
49
|
+
Song = Struct.new(:id, :title, :created_by) do
|
50
|
+
def save; true; end
|
51
|
+
end
|
52
|
+
|
53
|
+
#:step-options
|
54
|
+
class Song::Create < Trailblazer::Operation
|
55
|
+
step :model!
|
56
|
+
step :assign!
|
57
|
+
consider :validate!
|
58
|
+
|
59
|
+
def model!(options, current_user:, **)
|
60
|
+
options["model"] = Song.new
|
61
|
+
options["model"].created_by = current_user
|
62
|
+
end
|
63
|
+
|
64
|
+
def assign!(*, params:, model:, **)
|
65
|
+
model.title= params[:title]
|
66
|
+
end
|
67
|
+
|
68
|
+
#:step-val
|
69
|
+
def validate!(options, model:, **)
|
70
|
+
options["result.validate"] = ( model.created_by && model.title )
|
71
|
+
end
|
72
|
+
#:step-val end
|
73
|
+
end
|
74
|
+
#:step-options end
|
75
|
+
|
76
|
+
it do
|
77
|
+
current_user = Struct.new(:email).new("nick@trailblazer.to")
|
78
|
+
#:step-res
|
79
|
+
result = Song::Create.({ title: "Roxanne" }, "current_user" => current_user)
|
80
|
+
|
81
|
+
result["model"] #=> #<Song title="Roxanne", "created_by"=<User ...>
|
82
|
+
result["result.validate"] #=> true
|
83
|
+
#:step-res end
|
84
|
+
|
85
|
+
result.inspect("current_user", "model").must_equal %{<Result:true [#<struct email=\"nick@trailblazer.to\">, #<struct DocsResultTest::Song id=nil, title="Roxanne", created_by=#<struct email=\"nick@trailblazer.to\">>] >}
|
86
|
+
|
87
|
+
#:step-binary
|
88
|
+
result.success? #=> true
|
89
|
+
result.failure? #=> falsee
|
90
|
+
#:step-binary end
|
91
|
+
|
92
|
+
#:step-dep
|
93
|
+
result["current_user"] #=> <User ...>
|
94
|
+
#:step-dep end
|
95
|
+
|
96
|
+
#:step-inspect
|
97
|
+
result.inspect("current_user", "model") #=> "<Result:true [#<User email=\"nick@tra... "
|
98
|
+
#:step-inspect end
|
99
|
+
end
|
100
|
+
end
|