trailblazer 2.0.0.rc1 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGES.md +17 -56
- data/lib/trailblazer/operation/contract.rb +3 -3
- data/lib/trailblazer/operation/persist.rb +3 -4
- data/lib/trailblazer/operation/validate.rb +2 -2
- data/lib/trailblazer/version.rb +1 -1
- data/test/docs/contract_test.rb +2 -2
- data/test/operation/dsl/contract_test.rb +1 -1
- metadata +5 -8
- data/TODO.md +0 -11
- data/draft-1.2.rb +0 -7
- data/lib/trailblazer/operation/params.rb +0 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9113e6cd01913594963d2bdd2007df2d82b1a162
|
4
|
+
data.tar.gz: 6f9970934e06c98054d76635cfb0dd9353f03bb3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5252542b46421e3972eda278e6184ee4dffb478db5682918706474d9e4dff31c6ba93c23c3ca3ab34334a05df1ef7e1c30ccf04a1cec16f8935a62f9066f259c
|
7
|
+
data.tar.gz: 03b85c2c94497c52f4017160fdedd11c670cbd22c2adc03af4fd920d266b5ddde1459aa3e03e3dabb0555b87b41c39c555add65796996d697486556de10bf713
|
data/CHANGES.md
CHANGED
@@ -1,54 +1,10 @@
|
|
1
|
-
|
2
1
|
# 2.0.0
|
3
2
|
|
4
|
-
|
5
|
-
|
6
|
-
* You can now have any number of contracts, `contract [:name], constant/block`.
|
7
|
-
|
8
|
-
`Contract`, Setup, Model
|
9
|
-
expose via `result[:_invocations] = _invocations`
|
10
|
-
|
11
|
-
* Changed `Operation#validate`: the signature now is `validate(params, model=self.model, options={}, contract_class)`.
|
12
|
-
* Changed `Operation#contract`: the signature now is `contract(model=self.model, options={}, contract_class)`.
|
13
|
-
|
14
|
-
Both changes simplify injecting additional dependencies into the contract, or making use of `Composition` contracts. Read more [here](http://trailblazer.to/gems/operation/contract.html). Note that in 1.2, there are deprecation mechanics to handle old code.
|
15
|
-
|
16
|
-
* Added `Trailblazer::Builder` for a builder-and-call mechanism decoupled from the operation.
|
17
|
-
* Finally removed `Operation::[]`. Be careful, this is now replaced and will return the specified competence.
|
18
|
-
|
19
|
-
TRB 1.1
|
20
|
-
build_operation(params).run
|
21
|
-
process(@params)
|
22
|
-
TRB 1.2
|
23
|
-
build_operation(params, *).call(params)
|
24
|
-
|
25
|
-
* Removed `Operation::reject`. This is available in `trailblazer-compat`.
|
26
|
-
* `Operation#invalid!` is now an optional module `Trailblazer::Operation::Invalid`.
|
27
|
-
* `Operation::present` is now optional. Include `Present`.
|
28
|
-
|
29
|
-
# CHANGES:
|
30
|
-
# * Removed `Operation::[]` in favor of `Operation::()`.
|
31
|
-
# * `Operation#invalid!` doesn't accept a result anymore.
|
32
|
-
# * Removed `Operation#valid?` in favor of the result object.
|
33
|
-
#
|
34
|
-
|
35
|
-
## Model
|
36
|
-
|
37
|
-
* The `model` method doesn't exist anymore, use `self["model"]` or write your own.
|
38
|
-
* `find_by` diverts to left track.
|
39
|
-
* `:create` is `:new` now.
|
40
|
-
|
41
|
-
## DI
|
42
|
-
|
43
|
-
You can now inject the following objects via `::call`:
|
44
|
-
|
45
|
-
* `"contract.default.class"`
|
46
|
-
* `"contract"`: The contract instance.
|
47
|
-
* `"model.class"`
|
3
|
+
All old semantics will be available via [trailblazer-compat](https://github.com/trailblazer/trailblazer-compat).
|
48
4
|
|
49
5
|
* Removed `Operation::run` as it was a bad decision. Raising an exception on invalid is a very test-specific scenario and shouldn't have been handled in the core doce.
|
50
6
|
* Removed `Operation::present`, since you can simply call `Operation::new` (without builders) or `Operation::build_operation` (with builders).
|
51
|
-
* Removed `Operation::valid?`. This is in the result object via `result
|
7
|
+
* Removed `Operation::valid?`. This is in the result object via `result.success?`.
|
52
8
|
* Removed `Operation#errors`. This is in the result object via `result[:errors]` if the operation was invalid.
|
53
9
|
* Removed the private option `:raise_on_invalid`. Use `Contract::Raise` instead, if you need it in tests.
|
54
10
|
|
@@ -57,6 +13,12 @@ You can now inject the following objects via `::call`:
|
|
57
13
|
* Removed `Operation::contract_class`. Please use `Operation::["contract.default.class"]`.
|
58
14
|
* Removed `Operation::contract_class=`. Please use `Operation::["contract.default.class"]=`. Doesn't inherit.
|
59
15
|
|
16
|
+
## Model
|
17
|
+
|
18
|
+
* The `model` method doesn't exist anymore, use `self["model"]` or write your own.
|
19
|
+
* `:find_by` diverts to left track.
|
20
|
+
* `:create` is `:new` now.
|
21
|
+
|
60
22
|
## Builder
|
61
23
|
|
62
24
|
* It's `include Builder` now, not `extend Builder`.
|
@@ -66,7 +28,7 @@ You can now inject the following objects via `::call`:
|
|
66
28
|
|
67
29
|
* No exception anymore, but `Operation#["policy.result"]`.
|
68
30
|
* Access the current user via `self["current_user"]` now.
|
69
|
-
* `Policy` is `Policy::Pundit` now as `Policy` is Trailblazer's authorization style.
|
31
|
+
* `Policy` is `Policy::Pundit` now as `Policy` is Trailblazer's (upcoming) authorization style.
|
70
32
|
|
71
33
|
## Representer
|
72
34
|
|
@@ -82,13 +44,6 @@ You can now inject the following objects via `::call`:
|
|
82
44
|
|
83
45
|
* Removed `Operation::Dispatch`, it's called `Operation::Callback`.
|
84
46
|
|
85
|
-
## #call
|
86
|
-
* You can return whatever you want now by overriding `Op::call`.
|
87
|
-
* Removed `Op.call().contract`, you now have to do `Op.call()[:operation].contract`.
|
88
|
-
|
89
|
-
|
90
|
-
* Removed the deprecation for `validate`, signature is `(params[, model, options, contract_class])`.
|
91
|
-
* Removed the deprecation for `contract`, signature is `([model, options, contract_class])`.
|
92
47
|
|
93
48
|
## Collection
|
94
49
|
|
@@ -96,16 +51,22 @@ You can now inject the following objects via `::call`:
|
|
96
51
|
|
97
52
|
## Controller
|
98
53
|
|
99
|
-
* Removed `Controller
|
54
|
+
* Removed `Controller`, this is now in [trailblazer-rails](https://github.com/trailblazer/trailblazer-rails/).
|
100
55
|
|
101
56
|
## Contract
|
102
57
|
|
103
|
-
* You can't call `Create.().contract` anymore. The contract instance(s) are available through the `Result` object.
|
58
|
+
* You can't call `Create.().contract` anymore. The contract instance(s) are available through the `Result` object via `["contract.default"]`.
|
59
|
+
* Removed the deprecation for `validate`, signature is `(params[, model, options, contract_class])`.
|
60
|
+
* Removed the deprecation for `contract`, signature is `([model, options, contract_class])`.
|
104
61
|
|
105
62
|
# 2.0.0.rc1
|
106
63
|
|
107
64
|
* `consider` got removed since `step` now evaluates the step's result and deviates (or not).
|
108
65
|
|
66
|
+
# 2.0.0.rc2
|
67
|
+
|
68
|
+
* It's now Contract::Persist( name: "params" ) instead of ( name: "contract.params" ).
|
69
|
+
|
109
70
|
# 2.0.0.beta3
|
110
71
|
|
111
72
|
* New, very slick keyword arguments for steps.
|
@@ -13,11 +13,11 @@ class Trailblazer::Operation
|
|
13
13
|
def self.build_contract!(operation, options, name:"default", constant:nil, builder: nil)
|
14
14
|
# TODO: we could probably clean this up a bit at some point.
|
15
15
|
contract_class = constant || options["contract.#{name}.class"]
|
16
|
-
model =
|
16
|
+
model = options["model"] # FIXME: model.default
|
17
17
|
|
18
|
-
return
|
18
|
+
return options["contract.#{name}"] = Uber::Option[builder].(operation, constant: contract_class, model: model) if builder
|
19
19
|
|
20
|
-
|
20
|
+
options["contract.#{name}"] = contract_class.new(model)
|
21
21
|
end
|
22
22
|
|
23
23
|
def self.import!(operation, import, **args)
|
@@ -1,11 +1,10 @@
|
|
1
1
|
class Trailblazer::Operation
|
2
2
|
module Contract
|
3
3
|
module Persist
|
4
|
-
def self.import!(operation, import,
|
5
|
-
|
6
|
-
contract_name = options[:name] || "contract.default"
|
4
|
+
def self.import!(operation, import, method: :save, name: "default")
|
5
|
+
path = "contract.#{name}"
|
7
6
|
|
8
|
-
import.(:&, ->(input, options) { options[
|
7
|
+
import.(:&, ->(input, options) { options[path].send(method) }, # TODO: test me.
|
9
8
|
name: "persist.save")
|
10
9
|
end
|
11
10
|
end
|
@@ -32,10 +32,10 @@ class Trailblazer::Operation
|
|
32
32
|
|
33
33
|
def self.validate!(operation, options, name: nil, representer:false, from: "document", params_path:nil, **)
|
34
34
|
path = "contract.#{name}"
|
35
|
-
contract =
|
35
|
+
contract = options[path]
|
36
36
|
|
37
37
|
# this is for 1.1-style compatibility and should be removed once we have Deserializer in place:
|
38
|
-
|
38
|
+
options["result.#{path}"] = result =
|
39
39
|
if representer
|
40
40
|
# use "document" as the body and let the representer deserialize to the contract.
|
41
41
|
# this will be simplified once we have Deserializer.
|
data/lib/trailblazer/version.rb
CHANGED
data/test/docs/contract_test.rb
CHANGED
@@ -217,7 +217,7 @@ class ContractNamedConstantTest < Minitest::Spec
|
|
217
217
|
step Model( Song, :new )
|
218
218
|
step Contract::Build( constant: MyContract, name: "form" )
|
219
219
|
step Contract::Validate( name: "form" )
|
220
|
-
step Contract::Persist( method: :sync, name: "
|
220
|
+
step Contract::Persist( method: :sync, name: "form" )
|
221
221
|
end
|
222
222
|
#:constant-name end
|
223
223
|
|
@@ -285,7 +285,7 @@ class DryValidationContractTest < Minitest::Spec
|
|
285
285
|
step Model( Song, :new ) # create the op's main model.
|
286
286
|
step Contract::Build( name: "form" ) # create the Reform contract.
|
287
287
|
step Contract::Validate( name: "form" ) # validate the Reform contract.
|
288
|
-
step Contract::Persist( method: :sync, name: "
|
288
|
+
step Contract::Persist( method: :sync, name: "form" ) # persist the contract's data via the model.
|
289
289
|
#~form end
|
290
290
|
end
|
291
291
|
#:dry-schema end
|
@@ -17,7 +17,7 @@ class DslContractTest < MiniTest::Spec
|
|
17
17
|
includer.| Trailblazer::Operation::Model( OpenStruct, :new )
|
18
18
|
includer.| Trailblazer::Operation::Contract::Build()
|
19
19
|
includer.| Trailblazer::Operation::Contract::Validate()
|
20
|
-
includer.| Trailblazer::Operation::Contract::Persist(
|
20
|
+
includer.| Trailblazer::Operation::Contract::Persist( method: :sync )
|
21
21
|
# includer.> ->(op, *) { op["x"] = [] }
|
22
22
|
end
|
23
23
|
end
|
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
|
4
|
+
version: 2.0.0
|
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-
|
11
|
+
date: 2016-12-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: trailblazer-operation
|
@@ -179,10 +179,8 @@ files:
|
|
179
179
|
- README.md
|
180
180
|
- Rakefile
|
181
181
|
- THOUGHTS
|
182
|
-
- TODO.md
|
183
182
|
- doc/Trb-The-Stack.png
|
184
183
|
- doc/trb.jpg
|
185
|
-
- draft-1.2.rb
|
186
184
|
- lib/trailblazer.rb
|
187
185
|
- lib/trailblazer/dsl.rb
|
188
186
|
- lib/trailblazer/operation/auto_inject.rb
|
@@ -193,7 +191,6 @@ files:
|
|
193
191
|
- lib/trailblazer/operation/model.rb
|
194
192
|
- lib/trailblazer/operation/module.rb
|
195
193
|
- lib/trailblazer/operation/nested.rb
|
196
|
-
- lib/trailblazer/operation/params.rb
|
197
194
|
- lib/trailblazer/operation/persist.rb
|
198
195
|
- lib/trailblazer/operation/policy.rb
|
199
196
|
- lib/trailblazer/operation/procedural/contract.rb
|
@@ -255,12 +252,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
255
252
|
version: 2.0.0
|
256
253
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
257
254
|
requirements:
|
258
|
-
- - "
|
255
|
+
- - ">="
|
259
256
|
- !ruby/object:Gem::Version
|
260
|
-
version:
|
257
|
+
version: '0'
|
261
258
|
requirements: []
|
262
259
|
rubyforge_project:
|
263
|
-
rubygems_version: 2.
|
260
|
+
rubygems_version: 2.4.8
|
264
261
|
signing_key:
|
265
262
|
specification_version: 4
|
266
263
|
summary: A high-level architecture for Ruby and Rails.
|
data/TODO.md
DELETED
@@ -1,11 +0,0 @@
|
|
1
|
-
# Operation: External API
|
2
|
-
|
3
|
-
* allow `Op[{body: "Great!"}, {additional: true}]` to save merge.
|
4
|
-
* make `Op[]` not require wrap like `comment: {}`
|
5
|
-
* in tests, make Op[].model return the reloaded model!
|
6
|
-
|
7
|
-
# Operation: Internal API
|
8
|
-
|
9
|
-
* don't populate the form in #present context, we don't need it (only the representer goes nuts)
|
10
|
-
* don't pass contract in validate, we have #contract.
|
11
|
-
* abstract validate/success/fail into methods to make it easily overrideable.
|
data/draft-1.2.rb
DELETED
@@ -1,13 +0,0 @@
|
|
1
|
-
class Trailblazer::Operation
|
2
|
-
module Params
|
3
|
-
def self.included(includer)
|
4
|
-
includer.> Replace, after: New
|
5
|
-
end
|
6
|
-
end
|
7
|
-
|
8
|
-
# Returned object will replace "params". Original is saved in "params.original".
|
9
|
-
Params::Replace = ->(input, options) {
|
10
|
-
options["params.original"] = original = options["params"]
|
11
|
-
options["params"] = input.params!(original)
|
12
|
-
}
|
13
|
-
end
|