trailblazer-macro-contract 2.1.0.beta4 → 2.1.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 +4 -4
- data/.rubocop.yml +6 -0
- data/.rubocop_todo.yml +21 -79
- data/CHANGES.md +11 -0
- data/Gemfile +11 -7
- data/LICENSE.txt +23 -5
- data/lib/trailblazer-macro-contract.rb +1 -1
- data/lib/trailblazer/macro/contract/version.rb +1 -1
- data/lib/trailblazer/operation/validate.rb +11 -9
- data/test/docs/contract_test.rb +63 -0
- data/test/operation/contract_test.rb +1 -0
- data/test/operation/persist_test.rb +2 -2
- data/test/test_helper.rb +0 -4
- data/trailblazer-macro-contract.gemspec +8 -15
- metadata +7 -97
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 6950c7cb14a9a1ef7ca1ee5ae5a9a516ddc193e2e2d92b74a0a1dd270a86a3ff
|
|
4
|
+
data.tar.gz: 2ced13008f600a7a4627c560cc0688a7c77870455cc0b00860fd292805197bec
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: aa924fcd28353032eb0b613a5d32ed2ffb6d3c1e4ef0833fbdb4fbde6499ad799ce779b7e6b697c9d36e3ec257782969ecfabbe0ca0bf0b658e7352f10abcac2
|
|
7
|
+
data.tar.gz: 8cdc084886db6cd010bbf035c84e444b4c2ee32ce5fdc4ad62efb1d71bbb11226c24dbe1ab1e164ff994e4a84741165c38698244a706ad3f654a90be4ddbd06b
|
data/.rubocop.yml
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
inherit_from: .rubocop_todo.yml
|
|
2
2
|
|
|
3
|
+
Style/StringLiterals:
|
|
4
|
+
EnforcedStyle: double_quotes
|
|
5
|
+
Style/StringLiteralsInInterpolation:
|
|
6
|
+
EnforcedStyle: double_quotes
|
|
7
|
+
|
|
3
8
|
Naming/MethodName:
|
|
4
9
|
Exclude:
|
|
5
10
|
- 'lib/trailblazer/operation/persist.rb'
|
|
6
11
|
- 'lib/trailblazer/operation/contract.rb'
|
|
12
|
+
|
data/.rubocop_todo.yml
CHANGED
|
@@ -1,11 +1,18 @@
|
|
|
1
1
|
# This configuration was generated by
|
|
2
2
|
# `rubocop --auto-gen-config`
|
|
3
|
-
# on 2018-
|
|
3
|
+
# on 2018-05-29 21:00:52 +0800 using RuboCop version 0.56.0.
|
|
4
4
|
# The point is for the user to remove these configuration records
|
|
5
5
|
# one by one as the offenses are removed from the code base.
|
|
6
6
|
# Note that changes in the inspected code, or installation of new
|
|
7
7
|
# versions of RuboCop, may require this file to be generated again.
|
|
8
8
|
|
|
9
|
+
# Offense count: 1
|
|
10
|
+
# Configuration parameters: Include.
|
|
11
|
+
# Include: **/*.gemfile, **/Gemfile, **/gems.rb
|
|
12
|
+
Bundler/DuplicatedGem:
|
|
13
|
+
Exclude:
|
|
14
|
+
- 'Gemfile'
|
|
15
|
+
|
|
9
16
|
# Offense count: 2
|
|
10
17
|
# Cop supports --auto-correct.
|
|
11
18
|
# Configuration parameters: Include, TreatCommentsAsGroupSeparators.
|
|
@@ -14,7 +21,7 @@ Bundler/OrderedGems:
|
|
|
14
21
|
Exclude:
|
|
15
22
|
- 'Gemfile'
|
|
16
23
|
|
|
17
|
-
# Offense count:
|
|
24
|
+
# Offense count: 2
|
|
18
25
|
# Cop supports --auto-correct.
|
|
19
26
|
# Configuration parameters: Include, TreatCommentsAsGroupSeparators.
|
|
20
27
|
# Include: **/*.gemspec
|
|
@@ -36,14 +43,6 @@ Layout/EmptyLineBetweenDefs:
|
|
|
36
43
|
Exclude:
|
|
37
44
|
- 'test/test_helper.rb'
|
|
38
45
|
|
|
39
|
-
# Offense count: 1
|
|
40
|
-
# Cop supports --auto-correct.
|
|
41
|
-
# Configuration parameters: EnforcedStyle.
|
|
42
|
-
# SupportedStyles: empty_lines, no_empty_lines
|
|
43
|
-
Layout/EmptyLinesAroundBlockBody:
|
|
44
|
-
Exclude:
|
|
45
|
-
- 'test/operation/dsl/contract_test.rb'
|
|
46
|
-
|
|
47
46
|
# Offense count: 1
|
|
48
47
|
# Cop supports --auto-correct.
|
|
49
48
|
# Configuration parameters: EnforcedStyle.
|
|
@@ -52,13 +51,12 @@ Layout/EmptyLinesAroundClassBody:
|
|
|
52
51
|
Exclude:
|
|
53
52
|
- 'test/docs/contract_test.rb'
|
|
54
53
|
|
|
55
|
-
# Offense count:
|
|
54
|
+
# Offense count: 1
|
|
56
55
|
# Cop supports --auto-correct.
|
|
57
56
|
# Configuration parameters: AllowForAlignment, ForceEqualSignAlignment.
|
|
58
57
|
Layout/ExtraSpacing:
|
|
59
58
|
Exclude:
|
|
60
59
|
- 'test/docs/contract_test.rb'
|
|
61
|
-
- 'test/operation/dsl/contract_test.rb'
|
|
62
60
|
|
|
63
61
|
# Offense count: 1
|
|
64
62
|
# Cop supports --auto-correct.
|
|
@@ -67,12 +65,11 @@ Layout/IndentAssignment:
|
|
|
67
65
|
Exclude:
|
|
68
66
|
- 'lib/trailblazer/operation/validate.rb'
|
|
69
67
|
|
|
70
|
-
# Offense count:
|
|
68
|
+
# Offense count: 5
|
|
71
69
|
# Cop supports --auto-correct.
|
|
72
70
|
Layout/LeadingCommentSpace:
|
|
73
71
|
Exclude:
|
|
74
72
|
- 'test/docs/contract_test.rb'
|
|
75
|
-
- 'test/operation/dsl/contract_test.rb'
|
|
76
73
|
|
|
77
74
|
# Offense count: 13
|
|
78
75
|
# Cop supports --auto-correct.
|
|
@@ -89,22 +86,15 @@ Layout/SpaceAfterColon:
|
|
|
89
86
|
Layout/SpaceAroundEqualsInParameterDefault:
|
|
90
87
|
EnforcedStyle: no_space
|
|
91
88
|
|
|
92
|
-
# Offense count:
|
|
89
|
+
# Offense count: 7
|
|
93
90
|
# Cop supports --auto-correct.
|
|
94
91
|
# Configuration parameters: AllowForAlignment.
|
|
95
92
|
Layout/SpaceAroundOperators:
|
|
96
93
|
Exclude:
|
|
97
94
|
- 'test/docs/contract_test.rb'
|
|
98
95
|
- 'test/operation/contract_test.rb'
|
|
99
|
-
- 'test/operation/dsl/contract_test.rb'
|
|
100
96
|
- 'test/operation/persist_test.rb'
|
|
101
97
|
|
|
102
|
-
# Offense count: 2
|
|
103
|
-
# Cop supports --auto-correct.
|
|
104
|
-
Layout/SpaceBeforeComment:
|
|
105
|
-
Exclude:
|
|
106
|
-
- 'test/operation/dsl/contract_test.rb'
|
|
107
|
-
|
|
108
98
|
# Offense count: 5
|
|
109
99
|
# Cop supports --auto-correct.
|
|
110
100
|
# Configuration parameters: EnforcedStyle, EnforcedStyleForEmptyBraces, SpaceBeforeBlockParameters.
|
|
@@ -114,7 +104,7 @@ Layout/SpaceInsideBlockBraces:
|
|
|
114
104
|
Exclude:
|
|
115
105
|
- 'test/docs/contract_test.rb'
|
|
116
106
|
|
|
117
|
-
# Offense count:
|
|
107
|
+
# Offense count: 38
|
|
118
108
|
# Cop supports --auto-correct.
|
|
119
109
|
# Configuration parameters: EnforcedStyle, EnforcedStyleForEmptyBraces.
|
|
120
110
|
# SupportedStyles: space, no_space, compact
|
|
@@ -123,11 +113,12 @@ Layout/SpaceInsideHashLiteralBraces:
|
|
|
123
113
|
Exclude:
|
|
124
114
|
- 'test/docs/contract_test.rb'
|
|
125
115
|
- 'test/operation/contract_test.rb'
|
|
126
|
-
- 'test/operation/dsl/contract_test.rb'
|
|
127
116
|
- 'test/test_helper.rb'
|
|
128
117
|
|
|
129
|
-
# Offense count:
|
|
118
|
+
# Offense count: 110
|
|
130
119
|
# Cop supports --auto-correct.
|
|
120
|
+
# Configuration parameters: EnforcedStyle.
|
|
121
|
+
# SupportedStyles: space, no_space
|
|
131
122
|
Layout/SpaceInsideParens:
|
|
132
123
|
Exclude:
|
|
133
124
|
- 'lib/trailblazer/operation/contract.rb'
|
|
@@ -136,7 +127,6 @@ Layout/SpaceInsideParens:
|
|
|
136
127
|
- 'test/docs/contract_test.rb'
|
|
137
128
|
- 'test/docs/dry_test.rb'
|
|
138
129
|
- 'test/operation/contract_test.rb'
|
|
139
|
-
- 'test/operation/dsl/contract_test.rb'
|
|
140
130
|
- 'test/operation/persist_test.rb'
|
|
141
131
|
|
|
142
132
|
# Offense count: 1
|
|
@@ -164,57 +154,19 @@ Lint/UnusedBlockArgument:
|
|
|
164
154
|
Exclude:
|
|
165
155
|
- 'test/test_helper.rb'
|
|
166
156
|
|
|
167
|
-
# Offense count: 3
|
|
168
|
-
# Configuration parameters: CountComments, ExcludedMethods.
|
|
169
|
-
Metrics/BlockLength:
|
|
170
|
-
Max: 32
|
|
171
|
-
|
|
172
|
-
# Offense count: 2
|
|
173
|
-
# Configuration parameters: .
|
|
174
|
-
# SupportedStyles: snake_case, camelCase
|
|
175
|
-
Naming/MethodName:
|
|
176
|
-
EnforcedStyle: snake_case
|
|
177
|
-
|
|
178
|
-
# Offense count: 1
|
|
179
|
-
# Configuration parameters: MinNameLength, AllowNamesEndingInNumbers, AllowedNames, ForbiddenNames.
|
|
180
|
-
Naming/UncommunicativeBlockParamName:
|
|
181
|
-
Exclude:
|
|
182
|
-
- 'lib/trailblazer/operation/persist.rb'
|
|
183
|
-
|
|
184
|
-
# Offense count: 6
|
|
185
|
-
# Configuration parameters: MinNameLength, AllowNamesEndingInNumbers, AllowedNames, ForbiddenNames.
|
|
186
|
-
# AllowedNames: io, id
|
|
187
|
-
Naming/UncommunicativeMethodParamName:
|
|
188
|
-
Exclude:
|
|
189
|
-
- 'lib/trailblazer/operation/validate.rb'
|
|
190
|
-
- 'test/docs/contract_test.rb'
|
|
191
|
-
- 'test/operation/persist_test.rb'
|
|
192
|
-
|
|
193
157
|
# Offense count: 1
|
|
194
158
|
# Cop supports --auto-correct.
|
|
195
159
|
Style/BlockComments:
|
|
196
160
|
Exclude:
|
|
197
161
|
- 'test/docs/contract_test.rb'
|
|
198
162
|
|
|
199
|
-
# Offense count:
|
|
200
|
-
# Cop supports --auto-correct.
|
|
201
|
-
# Configuration parameters: EnforcedStyle, ProceduralMethods, FunctionalMethods, IgnoredMethods.
|
|
202
|
-
# SupportedStyles: line_count_based, semantic, braces_for_chaining
|
|
203
|
-
# ProceduralMethods: benchmark, bm, bmbm, create, each_with_object, measure, new, realtime, tap, with_object
|
|
204
|
-
# FunctionalMethods: let, let!, subject, watch
|
|
205
|
-
# IgnoredMethods: lambda, proc, it
|
|
206
|
-
Style/BlockDelimiters:
|
|
207
|
-
Exclude:
|
|
208
|
-
- 'test/operation/dsl/contract_test.rb'
|
|
209
|
-
|
|
210
|
-
# Offense count: 4
|
|
163
|
+
# Offense count: 3
|
|
211
164
|
# Cop supports --auto-correct.
|
|
212
165
|
# Configuration parameters: EnforcedStyle.
|
|
213
166
|
# SupportedStyles: braces, no_braces, context_dependent
|
|
214
167
|
Style/BracesAroundHashParameters:
|
|
215
168
|
Exclude:
|
|
216
169
|
- 'test/operation/contract_test.rb'
|
|
217
|
-
- 'test/operation/dsl/contract_test.rb'
|
|
218
170
|
|
|
219
171
|
# Offense count: 8
|
|
220
172
|
# Cop supports --auto-correct.
|
|
@@ -254,7 +206,7 @@ Style/HashSyntax:
|
|
|
254
206
|
- 'test/docs/contract_test.rb'
|
|
255
207
|
- 'test/operation/contract_test.rb'
|
|
256
208
|
|
|
257
|
-
# Offense count:
|
|
209
|
+
# Offense count: 66
|
|
258
210
|
# Cop supports --auto-correct.
|
|
259
211
|
# Configuration parameters: .
|
|
260
212
|
# SupportedStyles: call, braces
|
|
@@ -267,7 +219,7 @@ Style/ParallelAssignment:
|
|
|
267
219
|
Exclude:
|
|
268
220
|
- 'lib/trailblazer/operation/validate.rb'
|
|
269
221
|
|
|
270
|
-
# Offense count:
|
|
222
|
+
# Offense count: 30
|
|
271
223
|
# Cop supports --auto-correct.
|
|
272
224
|
# Configuration parameters: PreferredDelimiters.
|
|
273
225
|
Style/PercentLiteralDelimiters:
|
|
@@ -275,7 +227,6 @@ Style/PercentLiteralDelimiters:
|
|
|
275
227
|
- 'test/docs/contract_test.rb'
|
|
276
228
|
- 'test/docs/dry_test.rb'
|
|
277
229
|
- 'test/operation/contract_test.rb'
|
|
278
|
-
- 'test/operation/dsl/contract_test.rb'
|
|
279
230
|
- 'test/operation/persist_test.rb'
|
|
280
231
|
|
|
281
232
|
# Offense count: 2
|
|
@@ -294,7 +245,7 @@ Style/SingleLineMethods:
|
|
|
294
245
|
- 'test/operation/persist_test.rb'
|
|
295
246
|
- 'test/test_helper.rb'
|
|
296
247
|
|
|
297
|
-
# Offense count:
|
|
248
|
+
# Offense count: 14
|
|
298
249
|
# Cop supports --auto-correct.
|
|
299
250
|
# Configuration parameters: EnforcedStyle, ConsistentQuotesInMultiline.
|
|
300
251
|
# SupportedStyles: single_quotes, double_quotes
|
|
@@ -302,20 +253,11 @@ Style/StringLiterals:
|
|
|
302
253
|
Exclude:
|
|
303
254
|
- 'Gemfile'
|
|
304
255
|
- 'Rakefile'
|
|
305
|
-
- 'lib/trailblazer/macro/contract.rb'
|
|
306
|
-
- 'lib/trailblazer/macro/contract/version.rb'
|
|
307
|
-
- 'lib/trailblazer/operation/contract.rb'
|
|
308
|
-
- 'lib/trailblazer/operation/persist.rb'
|
|
309
|
-
- 'lib/trailblazer/operation/validate.rb'
|
|
310
|
-
- 'test/docs/contract_test.rb'
|
|
311
|
-
- 'test/docs/dry_test.rb'
|
|
312
256
|
- 'test/operation/contract_test.rb'
|
|
313
|
-
- 'test/operation/dsl/contract_test.rb'
|
|
314
|
-
- 'test/operation/persist_test.rb'
|
|
315
257
|
- 'test/test_helper.rb'
|
|
316
258
|
- 'trailblazer-macro-contract.gemspec'
|
|
317
259
|
|
|
318
|
-
# Offense count:
|
|
260
|
+
# Offense count: 75
|
|
319
261
|
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
|
|
320
262
|
# URISchemes: http, https
|
|
321
263
|
Metrics/LineLength:
|
data/CHANGES.md
CHANGED
|
@@ -1,3 +1,14 @@
|
|
|
1
|
+
# 2.1.0.rc1
|
|
2
|
+
|
|
3
|
+
* Add a separate End to Validate. When the key extraction fails, the Validate activity will
|
|
4
|
+
end in a new end End.extract_failure.
|
|
5
|
+
This end is, per default, connected to the outer failure track, exposing the exact same
|
|
6
|
+
behavior it did before, but is now deviatable in the outer "real" operation to a separate
|
|
7
|
+
flow.
|
|
8
|
+
* Add `Validate( constant: MySchema )` to allow using `Dry::Schema` without the need for `Contract::Build()`.
|
|
9
|
+
This replaces a hack that used `contract MySchema` to achieve the same.
|
|
10
|
+
* Change back to MIT license.
|
|
11
|
+
|
|
1
12
|
# 2.1.0.beta4
|
|
2
13
|
|
|
3
14
|
* New activity API update.
|
data/Gemfile
CHANGED
|
@@ -1,18 +1,22 @@
|
|
|
1
1
|
source 'https://rubygems.org'
|
|
2
|
-
|
|
3
2
|
# Specify your gem's dependencies in trailblazer.gemspec
|
|
4
3
|
gemspec
|
|
5
4
|
|
|
6
|
-
gem "reform-rails"
|
|
7
|
-
gem "activesupport"
|
|
8
|
-
|
|
9
|
-
gem "reform"
|
|
10
|
-
gem "multi_json"
|
|
11
|
-
|
|
12
5
|
gem "dry-auto_inject"
|
|
13
6
|
gem "dry-matcher"
|
|
14
7
|
gem "dry-validation"
|
|
15
8
|
|
|
9
|
+
# if ENV['USE_LOCAL_GEMS']
|
|
10
|
+
gem "reform", path: "../reform"
|
|
11
|
+
gem "reform-rails", path: "../reform-rails"
|
|
12
|
+
gem "trailblazer-operation", path: "../trailblazer-operation"
|
|
13
|
+
gem "trailblazer-macro", path: "../trailblazer-macro"
|
|
14
|
+
gem "trailblazer-activity", path: "../trailblazer-activity"
|
|
15
|
+
# gem "trailblazer-context", path: "../trailblazer-context"
|
|
16
|
+
# else
|
|
17
|
+
# gem "reform"
|
|
18
|
+
# end
|
|
19
|
+
|
|
16
20
|
# gem "trailblazer-operation", github: "trailblazer/trailblazer-operation"
|
|
17
21
|
# gem "trailblazer-macro", github: "trailblazer/trailblazer-macro"
|
|
18
22
|
|
data/LICENSE.txt
CHANGED
|
@@ -1,9 +1,27 @@
|
|
|
1
|
-
|
|
1
|
+
The MIT License (MIT)
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
Copyright (c) 2018 Trailblazer GmbH
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
|
22
|
+
|
|
23
|
+
---------
|
|
6
24
|
|
|
7
25
|
Trailblazer Enterprise has a commercial-friendly license allowing private forks
|
|
8
26
|
and modifications of Trailblazer. Please see http://trailblazer.to/enterprise/ for
|
|
9
|
-
more detail.
|
|
27
|
+
more detail.
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
require "trailblazer/macro/contract/version"
|
|
2
|
-
require "trailblazer/macro/contract"
|
|
2
|
+
require "trailblazer/macro/contract"
|
|
@@ -5,24 +5,26 @@ module Trailblazer
|
|
|
5
5
|
# result.contract.errors = {..}
|
|
6
6
|
# Deviate to left track if optional key is not found in params.
|
|
7
7
|
# Deviate to left if validation result falsey.
|
|
8
|
-
def self.Validate(skip_extract: false, name: "default", representer: false, key: nil) # DISCUSS: should we introduce something like Validate::Deserializer?
|
|
8
|
+
def self.Validate(skip_extract: false, name: "default", representer: false, key: nil, constant: nil) # DISCUSS: should we introduce something like Validate::Deserializer?
|
|
9
9
|
params_path = "contract.#{name}.params" # extract_params! save extracted params here.
|
|
10
10
|
|
|
11
11
|
extract = Validate::Extract.new( key: key, params_path: params_path ).freeze
|
|
12
|
-
validate = Validate.new( name: name, representer: representer, params_path: params_path ).freeze
|
|
12
|
+
validate = Validate.new( name: name, representer: representer, params_path: params_path, constant: constant ).freeze
|
|
13
13
|
|
|
14
14
|
# Build a simple Railway {Activity} for the internal flow.
|
|
15
15
|
activity = Module.new do
|
|
16
16
|
extend Activity::Railway(name: "Contract::Validate")
|
|
17
17
|
|
|
18
|
-
step extract, id: "#{params_path}_extract" unless skip_extract || representer
|
|
18
|
+
step extract, id: "#{params_path}_extract", Activity::DSL.Output(:failure) => Activity::DSL.End(:extract_failure) unless skip_extract || representer
|
|
19
19
|
step validate, id: "contract.#{name}.call"
|
|
20
20
|
end
|
|
21
21
|
|
|
22
|
-
|
|
22
|
+
options = { task: activity, id: "contract.#{name}.validate", outputs: activity.outputs}
|
|
23
23
|
|
|
24
|
-
#
|
|
25
|
-
|
|
24
|
+
# Deviate End.extract_failure to the standard failure track as a default. This can be changed from the user side.
|
|
25
|
+
options = options.merge(Activity::DSL.Output(:extract_failure) => Activity::DSL.Track(:failure)) unless skip_extract
|
|
26
|
+
|
|
27
|
+
options
|
|
26
28
|
end
|
|
27
29
|
|
|
28
30
|
class Validate
|
|
@@ -37,8 +39,8 @@ module Trailblazer
|
|
|
37
39
|
end
|
|
38
40
|
end
|
|
39
41
|
|
|
40
|
-
def initialize(name:"default", representer:false, params_path:nil)
|
|
41
|
-
@name, @representer, @params_path = name, representer, params_path
|
|
42
|
+
def initialize(name:"default", representer:false, params_path:nil, constant: nil)
|
|
43
|
+
@name, @representer, @params_path, @constant = name, representer, params_path, constant
|
|
42
44
|
end
|
|
43
45
|
|
|
44
46
|
# Task: Validates contract `:name`.
|
|
@@ -52,7 +54,7 @@ module Trailblazer
|
|
|
52
54
|
|
|
53
55
|
def validate!(options, representer:false, from: :document, params_path:nil)
|
|
54
56
|
path = "contract.#{@name}"
|
|
55
|
-
contract = options[path]
|
|
57
|
+
contract = @constant || options[path]
|
|
56
58
|
|
|
57
59
|
# this is for 1.1-style compatibility and should be removed once we have Deserializer in place:
|
|
58
60
|
options["result.#{path}"] = result =
|
data/test/docs/contract_test.rb
CHANGED
|
@@ -257,6 +257,46 @@ class DocsContractKeyTest < Minitest::Spec
|
|
|
257
257
|
end
|
|
258
258
|
end
|
|
259
259
|
|
|
260
|
+
#---
|
|
261
|
+
#- Validate( key: :song ), Output(:extract_failure) => End(:my_new_end)
|
|
262
|
+
class DocsContractKeyWithOutputTest < Minitest::Spec
|
|
263
|
+
Song = Class.new(ContractConstantTest::Song)
|
|
264
|
+
|
|
265
|
+
module Song::Contract
|
|
266
|
+
Create = ContractConstantTest::Song::Contract::Create
|
|
267
|
+
end
|
|
268
|
+
|
|
269
|
+
#:key-output
|
|
270
|
+
class Song::Create < Trailblazer::Operation
|
|
271
|
+
step Model( Song, :new )
|
|
272
|
+
step Contract::Build( constant: Song::Contract::Create )
|
|
273
|
+
step Contract::Validate( key: "song" ), Output(:extract_failure) => End(:key_not_found)
|
|
274
|
+
step Contract::Persist( )
|
|
275
|
+
end
|
|
276
|
+
#:key-output end
|
|
277
|
+
|
|
278
|
+
it do
|
|
279
|
+
result = Song::Create.(params: {})
|
|
280
|
+
|
|
281
|
+
result.event.inspect.must_equal %{#<Trailblazer::Activity::End semantic=:key_not_found>}
|
|
282
|
+
result.inspect(:model, "result.contract.default.extract").must_equal %{<Result:false [#<struct DocsContractKeyWithOutputTest::Song title=nil, length=nil>, nil] >}
|
|
283
|
+
end
|
|
284
|
+
|
|
285
|
+
it { Song::Create.(params: {"song" => { title: "SVG", length: 13 }}).inspect(:model).must_equal %{<Result:true [#<struct DocsContractKeyWithOutputTest::Song title=\"SVG\", length=13>] >} }
|
|
286
|
+
it do
|
|
287
|
+
#:key-output-res
|
|
288
|
+
result = Song::Create.(params: { "song" => { title: "Rising Force", length: 13 } })
|
|
289
|
+
result.success? #=> true
|
|
290
|
+
#:key-output-res end
|
|
291
|
+
|
|
292
|
+
#:key-output-res-false
|
|
293
|
+
result = Song::Create.(params: { title: "Rising Force", length: 13 })
|
|
294
|
+
result.success? #=> false
|
|
295
|
+
result.event #=> #<Trailblazer::Activity::End semantic=:key_not_found>
|
|
296
|
+
#:key-output-res-false end
|
|
297
|
+
end
|
|
298
|
+
end
|
|
299
|
+
|
|
260
300
|
#- Contract::Build[ constant: XXX, name: AAA ]
|
|
261
301
|
class ContractNamedConstantTest < Minitest::Spec
|
|
262
302
|
Song = Class.new(ContractConstantTest::Song)
|
|
@@ -361,6 +401,29 @@ class DryValidationContractTest < Minitest::Spec
|
|
|
361
401
|
it { Create.(params: { id: 1, title: "" }).inspect(:model).must_equal %{<Result:false [#<struct DryValidationContractTest::Song id=nil, title=nil>] >} }
|
|
362
402
|
it { Create.(params: { id: 1, title: "Y" }).inspect(:model).must_equal %{<Result:false [#<struct DryValidationContractTest::Song id=nil, title=nil>] >} }
|
|
363
403
|
it { Create.(params: { id: 1, title: "Yo" }).inspect(:model).must_equal %{<Result:true [#<struct DryValidationContractTest::Song id=1, title="Yo">] >} }
|
|
404
|
+
|
|
405
|
+
#---
|
|
406
|
+
# Contract::Validate(constant: DrySchema)
|
|
407
|
+
class OpWithSchema < Trailblazer::Operation
|
|
408
|
+
Schema = Dry::Validation.Schema do
|
|
409
|
+
required(:title).filled
|
|
410
|
+
end
|
|
411
|
+
|
|
412
|
+
step Model( Song, :new ) # FIXME.
|
|
413
|
+
step Contract::Validate( constant: Schema, key: :song) # generic validate call for you.
|
|
414
|
+
end
|
|
415
|
+
|
|
416
|
+
# success
|
|
417
|
+
it { OpWithSchema.(params: {song: { title: "SVG" }}).success?.must_equal true }
|
|
418
|
+
# failure
|
|
419
|
+
it { OpWithSchema.(params: {song: { title: nil }}).success?.must_equal false }
|
|
420
|
+
it "shows error messages" do
|
|
421
|
+
result = OpWithSchema.(params: {song: { title: nil }})
|
|
422
|
+
|
|
423
|
+
result["result.contract.default"].errors.must_equal(title: ["must be filled"])
|
|
424
|
+
end
|
|
425
|
+
# key not found
|
|
426
|
+
it { OpWithSchema.(params: {}).success?.must_equal false }
|
|
364
427
|
end
|
|
365
428
|
|
|
366
429
|
class DocContractBuilderTest < Minitest::Spec
|
|
@@ -31,7 +31,7 @@ class PersistTest < Minitest::Spec
|
|
|
31
31
|
# failure
|
|
32
32
|
it do
|
|
33
33
|
result = Create.(params: { title: "Fail!" })
|
|
34
|
-
result[:model].saved
|
|
34
|
+
assert_nil result[:model].saved
|
|
35
35
|
result[:model].title.must_equal "Fail!"
|
|
36
36
|
result["2. fail"].must_equal "Persist"
|
|
37
37
|
result.success?.must_equal false
|
|
@@ -42,7 +42,7 @@ class PersistTest < Minitest::Spec
|
|
|
42
42
|
class Update < Create
|
|
43
43
|
end
|
|
44
44
|
|
|
45
|
-
it { Operation::Inspect.( Update ).must_equal %{[>model.build,>contract.build,>contract.default.validate,<<PersistTest::Create::Fail1,>persist.save,<<PersistTest::Create::Fail2]} }
|
|
45
|
+
it { Trailblazer::Operation::Inspect.( Update ).must_equal %{[>model.build,>contract.build,>contract.default.validate,<<PersistTest::Create::Fail1,>persist.save,<<PersistTest::Create::Fail2]} }
|
|
46
46
|
|
|
47
47
|
#---
|
|
48
48
|
it do
|
data/test/test_helper.rb
CHANGED
|
@@ -7,33 +7,26 @@ Gem::Specification.new do |spec|
|
|
|
7
7
|
spec.version = Trailblazer::Macro::Contract::VERSION
|
|
8
8
|
spec.authors = ["Nick Sutterer"]
|
|
9
9
|
spec.email = ["apotonick@gmail.com"]
|
|
10
|
-
spec.description = 'Trailblazer operation
|
|
11
|
-
spec.summary = '
|
|
10
|
+
spec.description = 'Trailblazer operation form object specific macros'
|
|
11
|
+
spec.summary = 'Macros for form-objects: Build, Validate, Persist'
|
|
12
12
|
spec.homepage = "http://trailblazer.to"
|
|
13
|
-
spec.license = "
|
|
13
|
+
spec.license = "MIT"
|
|
14
14
|
|
|
15
|
-
spec.files = `git ls-files`.split(
|
|
16
|
-
|
|
17
|
-
|
|
15
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
|
16
|
+
f.match(%r{^test/})
|
|
17
|
+
end
|
|
18
|
+
spec.test_files = `git ls-files -z test`.split("\x0")
|
|
18
19
|
spec.require_paths = ["lib"]
|
|
19
20
|
|
|
20
|
-
spec.add_dependency "declarative"
|
|
21
21
|
spec.add_dependency "reform", ">= 2.2.0", "< 3.0.0"
|
|
22
|
-
spec.add_dependency "trailblazer-operation", ">= 0.3.0", "< 0.4.0"
|
|
23
22
|
|
|
24
23
|
spec.add_development_dependency "bundler"
|
|
25
|
-
spec.add_development_dependency "trailblazer-macro", ">= 2.1.0.
|
|
26
|
-
|
|
24
|
+
spec.add_development_dependency "trailblazer-macro", ">= 2.1.0.rc1", "< 2.2.0"
|
|
27
25
|
spec.add_development_dependency "reform-rails"
|
|
28
26
|
spec.add_development_dependency "dry-validation"
|
|
29
|
-
spec.add_development_dependency "activemodel"
|
|
30
27
|
|
|
31
28
|
spec.add_development_dependency "minitest"
|
|
32
|
-
spec.add_development_dependency "nokogiri"
|
|
33
29
|
spec.add_development_dependency "rake"
|
|
34
30
|
|
|
35
|
-
spec.add_development_dependency "roar"
|
|
36
|
-
spec.add_development_dependency "multi_json"
|
|
37
|
-
|
|
38
31
|
spec.required_ruby_version = '>= 2.0.0'
|
|
39
32
|
end
|
metadata
CHANGED
|
@@ -1,29 +1,15 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: trailblazer-macro-contract
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 2.1.0.
|
|
4
|
+
version: 2.1.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: 2018-
|
|
11
|
+
date: 2018-06-18 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
|
-
- !ruby/object:Gem::Dependency
|
|
14
|
-
name: declarative
|
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
|
16
|
-
requirements:
|
|
17
|
-
- - ">="
|
|
18
|
-
- !ruby/object:Gem::Version
|
|
19
|
-
version: '0'
|
|
20
|
-
type: :runtime
|
|
21
|
-
prerelease: false
|
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
-
requirements:
|
|
24
|
-
- - ">="
|
|
25
|
-
- !ruby/object:Gem::Version
|
|
26
|
-
version: '0'
|
|
27
13
|
- !ruby/object:Gem::Dependency
|
|
28
14
|
name: reform
|
|
29
15
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -44,26 +30,6 @@ dependencies:
|
|
|
44
30
|
- - "<"
|
|
45
31
|
- !ruby/object:Gem::Version
|
|
46
32
|
version: 3.0.0
|
|
47
|
-
- !ruby/object:Gem::Dependency
|
|
48
|
-
name: trailblazer-operation
|
|
49
|
-
requirement: !ruby/object:Gem::Requirement
|
|
50
|
-
requirements:
|
|
51
|
-
- - ">="
|
|
52
|
-
- !ruby/object:Gem::Version
|
|
53
|
-
version: 0.3.0
|
|
54
|
-
- - "<"
|
|
55
|
-
- !ruby/object:Gem::Version
|
|
56
|
-
version: 0.4.0
|
|
57
|
-
type: :runtime
|
|
58
|
-
prerelease: false
|
|
59
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
60
|
-
requirements:
|
|
61
|
-
- - ">="
|
|
62
|
-
- !ruby/object:Gem::Version
|
|
63
|
-
version: 0.3.0
|
|
64
|
-
- - "<"
|
|
65
|
-
- !ruby/object:Gem::Version
|
|
66
|
-
version: 0.4.0
|
|
67
33
|
- !ruby/object:Gem::Dependency
|
|
68
34
|
name: bundler
|
|
69
35
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -84,7 +50,7 @@ dependencies:
|
|
|
84
50
|
requirements:
|
|
85
51
|
- - ">="
|
|
86
52
|
- !ruby/object:Gem::Version
|
|
87
|
-
version: 2.1.0.
|
|
53
|
+
version: 2.1.0.rc1
|
|
88
54
|
- - "<"
|
|
89
55
|
- !ruby/object:Gem::Version
|
|
90
56
|
version: 2.2.0
|
|
@@ -94,7 +60,7 @@ dependencies:
|
|
|
94
60
|
requirements:
|
|
95
61
|
- - ">="
|
|
96
62
|
- !ruby/object:Gem::Version
|
|
97
|
-
version: 2.1.0.
|
|
63
|
+
version: 2.1.0.rc1
|
|
98
64
|
- - "<"
|
|
99
65
|
- !ruby/object:Gem::Version
|
|
100
66
|
version: 2.2.0
|
|
@@ -126,20 +92,6 @@ dependencies:
|
|
|
126
92
|
- - ">="
|
|
127
93
|
- !ruby/object:Gem::Version
|
|
128
94
|
version: '0'
|
|
129
|
-
- !ruby/object:Gem::Dependency
|
|
130
|
-
name: activemodel
|
|
131
|
-
requirement: !ruby/object:Gem::Requirement
|
|
132
|
-
requirements:
|
|
133
|
-
- - ">="
|
|
134
|
-
- !ruby/object:Gem::Version
|
|
135
|
-
version: '0'
|
|
136
|
-
type: :development
|
|
137
|
-
prerelease: false
|
|
138
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
139
|
-
requirements:
|
|
140
|
-
- - ">="
|
|
141
|
-
- !ruby/object:Gem::Version
|
|
142
|
-
version: '0'
|
|
143
95
|
- !ruby/object:Gem::Dependency
|
|
144
96
|
name: minitest
|
|
145
97
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -154,20 +106,6 @@ dependencies:
|
|
|
154
106
|
- - ">="
|
|
155
107
|
- !ruby/object:Gem::Version
|
|
156
108
|
version: '0'
|
|
157
|
-
- !ruby/object:Gem::Dependency
|
|
158
|
-
name: nokogiri
|
|
159
|
-
requirement: !ruby/object:Gem::Requirement
|
|
160
|
-
requirements:
|
|
161
|
-
- - ">="
|
|
162
|
-
- !ruby/object:Gem::Version
|
|
163
|
-
version: '0'
|
|
164
|
-
type: :development
|
|
165
|
-
prerelease: false
|
|
166
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
167
|
-
requirements:
|
|
168
|
-
- - ">="
|
|
169
|
-
- !ruby/object:Gem::Version
|
|
170
|
-
version: '0'
|
|
171
109
|
- !ruby/object:Gem::Dependency
|
|
172
110
|
name: rake
|
|
173
111
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -182,35 +120,7 @@ dependencies:
|
|
|
182
120
|
- - ">="
|
|
183
121
|
- !ruby/object:Gem::Version
|
|
184
122
|
version: '0'
|
|
185
|
-
|
|
186
|
-
name: roar
|
|
187
|
-
requirement: !ruby/object:Gem::Requirement
|
|
188
|
-
requirements:
|
|
189
|
-
- - ">="
|
|
190
|
-
- !ruby/object:Gem::Version
|
|
191
|
-
version: '0'
|
|
192
|
-
type: :development
|
|
193
|
-
prerelease: false
|
|
194
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
195
|
-
requirements:
|
|
196
|
-
- - ">="
|
|
197
|
-
- !ruby/object:Gem::Version
|
|
198
|
-
version: '0'
|
|
199
|
-
- !ruby/object:Gem::Dependency
|
|
200
|
-
name: multi_json
|
|
201
|
-
requirement: !ruby/object:Gem::Requirement
|
|
202
|
-
requirements:
|
|
203
|
-
- - ">="
|
|
204
|
-
- !ruby/object:Gem::Version
|
|
205
|
-
version: '0'
|
|
206
|
-
type: :development
|
|
207
|
-
prerelease: false
|
|
208
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
209
|
-
requirements:
|
|
210
|
-
- - ">="
|
|
211
|
-
- !ruby/object:Gem::Version
|
|
212
|
-
version: '0'
|
|
213
|
-
description: Trailblazer operation macros to integrate Reform
|
|
123
|
+
description: Trailblazer operation form object specific macros
|
|
214
124
|
email:
|
|
215
125
|
- apotonick@gmail.com
|
|
216
126
|
executables: []
|
|
@@ -241,7 +151,7 @@ files:
|
|
|
241
151
|
- trailblazer-macro-contract.gemspec
|
|
242
152
|
homepage: http://trailblazer.to
|
|
243
153
|
licenses:
|
|
244
|
-
-
|
|
154
|
+
- MIT
|
|
245
155
|
metadata: {}
|
|
246
156
|
post_install_message:
|
|
247
157
|
rdoc_options: []
|
|
@@ -262,7 +172,7 @@ rubyforge_project:
|
|
|
262
172
|
rubygems_version: 2.7.3
|
|
263
173
|
signing_key:
|
|
264
174
|
specification_version: 4
|
|
265
|
-
summary:
|
|
175
|
+
summary: 'Macros for form-objects: Build, Validate, Persist'
|
|
266
176
|
test_files:
|
|
267
177
|
- test/docs/contract_test.rb
|
|
268
178
|
- test/docs/dry_test.rb
|