trailblazer 2.0.0.beta3 → 2.0.0.rc1

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
  SHA1:
3
- metadata.gz: 36d5743aefbaa5f3164a9d247adfcef5a4acd3ad
4
- data.tar.gz: 4d263f2e11657140bccbd98e90915896b00d39db
3
+ metadata.gz: cb0eb777dc5afb25cb6200169ca06bf75a18db94
4
+ data.tar.gz: 8ca6d1c9b0a5491ea9fa282cf5766552fcf8462a
5
5
  SHA512:
6
- metadata.gz: 92afde635725edbf16f2c3705fc9f3e1462ab955c5fbb273754f58fc1c79bff1916cb5ad4aeb319784d6a1589b8dc1371283469b74a540922e1bfeda2730f3f7
7
- data.tar.gz: e323a24a729b87ae7fcb50ecc8a2483c237f0f7f2edf0e6025185d8787b26abda307d176f3b0b884fd642d04dc0c958e01b1e8ba2b60cdd6b562707569829b33
6
+ metadata.gz: 939adb355c6875cf922f6dda5056ee2d13664c386149c3afd7d62c5f0a0b77b51d1c487e62ac4ea1c5af39aa481e9d1b7bef891bca55a0dc6af92fb5d764786a
7
+ data.tar.gz: 5e1f1f2de36e85c4f6a0c84e655c329e22073027130c079e6f3b776de84c1046867056a8fb40aa915919ac83a6ec74300428d45c24a1b65eb06031c8d20d3296
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.rc1
106
+
107
+ * `consider` got removed since `step` now evaluates the step's result and deviates (or not).
108
+
105
109
  # 2.0.0.beta3
106
110
 
107
111
  * New, very slick keyword arguments for steps.
@@ -1,3 +1,3 @@
1
1
  module Trailblazer
2
- VERSION = "2.0.0.beta3"
2
+ VERSION = "2.0.0.rc1"
3
3
  end
@@ -166,7 +166,7 @@ class DocsContractSeparateKeyTest < Minitest::Spec
166
166
 
167
167
  step Model( Song, :new )
168
168
  step Contract::Build()
169
- consider :extract_params!
169
+ step :extract_params!
170
170
  step Contract::Validate( skip_extract: true )
171
171
  step Contract::Persist( method: :sync )
172
172
 
@@ -32,7 +32,7 @@ class DocsGuardProcTest < Minitest::Spec
32
32
  override Policy::Guard( ->(options) { options["current_user"] } )
33
33
  end
34
34
 
35
- it { New["pipetree"].inspect.must_equal %{[>>operation.new,&policy.default.eval,>process]} }
35
+ it { New["pipetree"].inspect.must_equal %{[>>operation.new,&policy.default.eval,&process]} }
36
36
  end
37
37
 
38
38
  #---
@@ -4,8 +4,8 @@ class DocsOperationExampleTest < Minitest::Spec
4
4
  Song = Struct.new(:id, :title, :created_by) do
5
5
  def save; true; end
6
6
  end
7
- #:op
8
7
 
8
+ #:op
9
9
  class Song::Create < Trailblazer::Operation
10
10
  extend Contract::DSL
11
11
 
@@ -15,7 +15,7 @@ class DocsOperationExampleTest < Minitest::Spec
15
15
  end
16
16
 
17
17
  step Model( Song, :new )
18
- consider :assign_current_user!
18
+ step :assign_current_user!
19
19
  step Contract::Build()
20
20
  step Contract::Validate( )
21
21
  failure :log_error!
@@ -38,9 +38,9 @@ end
38
38
 
39
39
  class DndTest < Minitest::Spec
40
40
  class Create < Trailblazer::Operation
41
- consider :authorize!
41
+ step :authorize!
42
42
  failure :auth_err!
43
- consider :save!
43
+ step :save!
44
44
  self.< Wrap
45
45
  end
46
46
  end
@@ -54,7 +54,7 @@ class DocsResultTest < Minitest::Spec
54
54
  class Song::Create < Trailblazer::Operation
55
55
  step :model!
56
56
  step :assign!
57
- consider :validate!
57
+ step :validate!
58
58
 
59
59
  def model!(options, current_user:, **)
60
60
  options["model"] = Song.new
@@ -98,3 +98,87 @@ class DocsResultTest < Minitest::Spec
98
98
  #:step-inspect end
99
99
  end
100
100
  end
101
+
102
+ class DocsDependencyTest < Minitest::Spec
103
+ Song = Struct.new(:id, :title, :created_by) do
104
+ def save; true; end
105
+ end
106
+ Hit = Struct.new(:id)
107
+
108
+ #:dep-op
109
+ class Song::Create < Trailblazer::Operation
110
+ self["my.model.class"] = Song
111
+
112
+ #~dep-pipe
113
+ step :model!
114
+
115
+ def model!(options, **)
116
+ options["my.model"] = # setting runtime data.
117
+ options["my.model.class"].new # reading class data at runtime.
118
+ end
119
+ #~dep-pipe end
120
+ end
121
+ #:dep-op end
122
+
123
+ it do
124
+ #:dep-op-class
125
+ Song::Create["my.model.class"] #=> Song
126
+ #:dep-op-class end
127
+
128
+ #:dep-op-res
129
+ result = Song::Create.({})
130
+
131
+ result["my.model.class"] #=> Song
132
+ result["my.model"] #=> #<Song title=nil>
133
+ #:dep-op-res end
134
+
135
+ Song::Create["my.model.class"].must_equal Song
136
+ result["my.model.class"].must_equal Song
137
+ result["my.model"].inspect.must_equal %{#<struct DocsDependencyTest::Song id=nil, title=nil, created_by=nil>}
138
+ end
139
+
140
+ it do
141
+ #:dep-di
142
+ result = Song::Create.({}, "my.model.class" => Hit)
143
+
144
+ result["my.model"] #=> #<Hit id=nil>
145
+ #:dep-di end
146
+ result["my.model"].inspect.must_equal %{#<struct DocsDependencyTest::Hit id=nil>}
147
+ end
148
+ end
149
+
150
+
151
+
152
+ class DocsOperationAPIExampleTest < Minitest::Spec
153
+ Song = Struct.new(:id, :title, :created_by) do
154
+ def save; true; end
155
+ end
156
+
157
+ class MyContract < Reform::Form
158
+ property :title
159
+ validates :title, presence: true
160
+ end
161
+
162
+ #:op-api
163
+ class Song::Create < Trailblazer::Operation
164
+ step Model( Song, :new )
165
+ step :assign_current_user!
166
+ step Contract::Build( constant: MyContract )
167
+ step Contract::Validate()
168
+ failure :log_error!
169
+ step Contract::Persist()
170
+
171
+ def log_error!(options)
172
+ # ..
173
+ end
174
+
175
+ def assign_current_user!(options)
176
+ options["model"].created_by =
177
+ options["current_user"]
178
+ end
179
+ end
180
+ #:op-api end
181
+
182
+ it { Song::Create.({ }).inspect("model").must_equal %{<Result:false [#<struct DocsOperationAPIExampleTest::Song id=nil, title=nil, created_by=nil>] >} }
183
+ it { Song::Create.({ title: "Nothin'" }, "current_user"=>Module).inspect("model").must_equal %{<Result:true [#<struct DocsOperationAPIExampleTest::Song id=nil, title="Nothin'", created_by=Module>] >} }
184
+ end
@@ -11,11 +11,11 @@ class NestedRescueTest < Minitest::Spec
11
11
  step ->(options) { options["a"] = true }
12
12
  step Rescue {
13
13
  step ->(options) { options["y"] = true }
14
- step ->(options) { raise Y if options["raise-y"] }
14
+ success ->(options) { raise Y if options["raise-y"] }
15
15
  step ->(options) { options["z"] = true }
16
16
  }
17
17
  step ->(options) { options["b"] = true }
18
- step ->(options) { raise A if options["raise-a"] }
18
+ success ->(options) { raise A if options["raise-a"] }
19
19
  step ->(options) { options["c"] = true }
20
20
  self.< ->(options) { options["inner-err"] = true }
21
21
  }
@@ -23,7 +23,7 @@ class NestedRescueTest < Minitest::Spec
23
23
  failure ->(options) { options["outer-err"] = true }
24
24
  end
25
25
 
26
- it { NestedInsanity["pipetree"].inspect.must_equal %{[>>operation.new,&Rescue:10,>:22,<NestedRescueTest::NestedInsanity:23]} }
26
+ it { NestedInsanity["pipetree"].inspect.must_equal %{[>>operation.new,&Rescue:10,&:22,<NestedRescueTest::NestedInsanity:23]} }
27
27
  it { NestedInsanity.({}).inspect("a", "y", "z", "b", "c", "e", "inner-err", "outer-err").must_equal %{<Result:true [true, true, true, true, true, true, nil, nil] >} }
28
28
  it { NestedInsanity.({}, "raise-y" => true).inspect("a", "y", "z", "b", "c", "e", "inner-err", "outer-err").must_equal %{<Result:false [true, true, nil, nil, nil, nil, true, true] >} }
29
29
  it { NestedInsanity.({}, "raise-a" => true).inspect("a", "y", "z", "b", "c", "e", "inner-err", "outer-err").must_equal %{<Result:false [true, true, true, true, nil, nil, nil, true] >} }
@@ -47,6 +47,7 @@ class RescueTest < Minitest::Spec
47
47
  end
48
48
 
49
49
  def lock!
50
+ true
50
51
  end
51
52
  end
52
53
 
@@ -35,7 +35,7 @@ class WrapTest < Minitest::Spec
35
35
  class Create < Trailblazer::Operation
36
36
  step Wrap ->(options, *, &block) { options["yield?"] ? block.call : false } {
37
37
  step ->(options) { options["x"] = true }
38
- step :noop!
38
+ success :noop!
39
39
  # ...
40
40
  }
41
41
 
@@ -87,6 +87,10 @@ class WrapTest < Minitest::Spec
87
87
  end
88
88
  end
89
89
 
90
+ module MyNotifier
91
+ def self.mail; true; end
92
+ end
93
+
90
94
  #:sequel-transaction
91
95
  class Create < Trailblazer::Operation
92
96
  #~wrap-only
@@ -112,7 +116,7 @@ class WrapTest < Minitest::Spec
112
116
  end
113
117
 
114
118
  def notify!(options)
115
- # send emails, because success...
119
+ MyNotifier.mail
116
120
  end
117
121
  #~wrap-only end
118
122
  end
@@ -128,6 +132,10 @@ class WrapTest < Minitest::Spec
128
132
  end
129
133
  end
130
134
 
135
+ module MyNotifier
136
+ def self.mail; true; end
137
+ end
138
+
131
139
  #:callable-t
132
140
  class MyTransaction
133
141
  extend Uber::Callable
@@ -162,7 +170,7 @@ class WrapTest < Minitest::Spec
162
170
  end
163
171
 
164
172
  def notify!(options)
165
- # send emails, because success...
173
+ MyNotifier.mail # send emails, because success...
166
174
  end
167
175
  #~wrap-onlyy end
168
176
  end
@@ -41,7 +41,7 @@ class BuilderTest < MiniTest::Spec
41
41
  class B < A
42
42
  end
43
43
 
44
- it { B["pipetree"].inspect.must_equal %{[>>operation.new,>process]} }
44
+ it { B["pipetree"].inspect.must_equal %{[>>operation.new,&process]} }
45
45
 
46
46
  #---
47
47
  # use Builder DSL
@@ -53,7 +53,7 @@ class PolicyTest < Minitest::Spec
53
53
  self.| Model( Song, :new ), before: "policy.default.eval"
54
54
  end
55
55
 
56
- it { Show["pipetree"].inspect.must_equal %{[>>operation.new,&model.build,&policy.default.eval,>process]} }
56
+ it { Show["pipetree"].inspect.must_equal %{[>>operation.new,&model.build,&policy.default.eval,&process]} }
57
57
 
58
58
  # invalid because user AND model.
59
59
  it do
@@ -35,7 +35,7 @@ class ResolverTest < Minitest::Spec
35
35
  def process(*); self["x"] = self.class end
36
36
  end
37
37
 
38
- it { A["pipetree"].inspect.must_equal %{[&model.build,&policy.default.eval,>>builder.call,>>operation.new,>process]} }
38
+ it { A["pipetree"].inspect.must_equal %{[&model.build,&policy.default.eval,>>builder.call,>>operation.new,&process]} }
39
39
 
40
40
  it { r=A.({ some: "params", id: 1 }, { "current_user" => Module })
41
41
  puts r.inspect
data/trailblazer.gemspec CHANGED
@@ -17,7 +17,7 @@ Gem::Specification.new do |spec|
17
17
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
18
  spec.require_paths = ["lib"]
19
19
 
20
- spec.add_dependency "trailblazer-operation"
20
+ spec.add_dependency "trailblazer-operation", ">= 0.0.9"
21
21
  spec.add_dependency "uber", ">= 0.1.0", "< 0.2.0"
22
22
  spec.add_dependency "reform", ">= 2.2.0", "< 3.0.0"
23
23
  spec.add_dependency "declarative"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: trailblazer
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0.beta3
4
+ version: 2.0.0.rc1
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-12-12 00:00:00.000000000 Z
11
+ date: 2016-12-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: trailblazer-operation
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '0'
19
+ version: 0.0.9
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '0'
26
+ version: 0.0.9
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: uber
29
29
  requirement: !ruby/object:Gem::Requirement