trailblazer-macro-contract 2.1.0.rc1 → 2.1.0.rc11
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-https---raw-githubusercontent-com-trailblazer-meta-master-rubocop-yml +136 -0
- data/.rubocop.yml +3 -6
- data/.rubocop_todo.yml +31 -58
- data/.travis.yml +1 -1
- data/CHANGES.md +4 -0
- data/Gemfile +4 -14
- data/lib/trailblazer/macro/contract/version.rb +5 -3
- data/lib/trailblazer/operation/contract.rb +14 -12
- data/lib/trailblazer/operation/persist.rb +2 -2
- data/lib/trailblazer/operation/validate.rb +12 -13
- data/test/docs/contract_test.rb +11 -11
- data/test/docs/dry_test.rb +6 -4
- data/trailblazer-macro-contract.gemspec +5 -5
- metadata +21 -20
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 1b6413a7b945e393b8baa3a495aac23add0b441a4355eab849f9fbe04c88302f
|
|
4
|
+
data.tar.gz: 8ff7bbec10e5c54bdd441210490ac4821e1af9883712b7e402a823326c7a5709
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 485c18523ff12598036bc545a9d4198e7a6c8caf55151d2408c8ca8a1102c53b8e161542e414092ec1afed01a23272c0f225435698f1a60d46689413dbc1b34e
|
|
7
|
+
data.tar.gz: df126c3051524791589a7822a76f22d8807cd8f434b8e4401256714c8f3a7ee077f1aecfbbe74f2f0f8e09bb7029ae001298382ce47b6f5b2d13b5bd80d733ed
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
AllCops:
|
|
2
|
+
TargetRubyVersion: 2.5.0
|
|
3
|
+
DisplayCopNames: true
|
|
4
|
+
Layout/CaseIndentation:
|
|
5
|
+
IndentOneStep: true
|
|
6
|
+
Layout/FirstArrayElementLineBreak:
|
|
7
|
+
Enabled: true
|
|
8
|
+
Layout/FirstHashElementLineBreak:
|
|
9
|
+
Enabled: true
|
|
10
|
+
Layout/FirstMethodArgumentLineBreak:
|
|
11
|
+
Enabled: true
|
|
12
|
+
Layout/FirstMethodParameterLineBreak:
|
|
13
|
+
Enabled: true
|
|
14
|
+
Layout/MultilineAssignmentLayout:
|
|
15
|
+
Enabled: true
|
|
16
|
+
EnforcedStyle: same_line
|
|
17
|
+
Layout/SpaceInsideHashLiteralBraces:
|
|
18
|
+
EnforcedStyle: no_space
|
|
19
|
+
Metrics/LineLength:
|
|
20
|
+
Max: 130
|
|
21
|
+
Metrics/ParameterLists:
|
|
22
|
+
Max: 5
|
|
23
|
+
Naming/VariableNumber:
|
|
24
|
+
EnforcedStyle: snake_case
|
|
25
|
+
Style/AndOr:
|
|
26
|
+
EnforcedStyle: conditionals
|
|
27
|
+
Style/AutoResourceCleanup:
|
|
28
|
+
Enabled: true
|
|
29
|
+
Style/CollectionMethods:
|
|
30
|
+
Enabled: true
|
|
31
|
+
Style/Documentation:
|
|
32
|
+
Enabled: false
|
|
33
|
+
Style/EmptyLiteral:
|
|
34
|
+
Enabled: false
|
|
35
|
+
Style/EmptyMethod:
|
|
36
|
+
EnforcedStyle: expanded
|
|
37
|
+
Style/FormatStringToken:
|
|
38
|
+
EnforcedStyle: template
|
|
39
|
+
Style/ImplicitRuntimeError:
|
|
40
|
+
Enabled: true
|
|
41
|
+
Style/MethodCalledOnDoEndBlock:
|
|
42
|
+
Enabled: true
|
|
43
|
+
Style/MethodDefParentheses:
|
|
44
|
+
EnforcedStyle: require_parentheses
|
|
45
|
+
Style/MissingElse:
|
|
46
|
+
Enabled: true
|
|
47
|
+
EnforcedStyle: case
|
|
48
|
+
Style/NumericLiterals:
|
|
49
|
+
Enabled: false
|
|
50
|
+
Style/OptionHash:
|
|
51
|
+
Enabled: true
|
|
52
|
+
Style/PercentLiteralDelimiters:
|
|
53
|
+
PreferredDelimiters:
|
|
54
|
+
"%w": "[]"
|
|
55
|
+
"%W": "[]"
|
|
56
|
+
"%i": "[]"
|
|
57
|
+
"%I": "[]"
|
|
58
|
+
"%r": "()"
|
|
59
|
+
Style/ReturnNil:
|
|
60
|
+
Enabled: true
|
|
61
|
+
Style/SafeNavigation:
|
|
62
|
+
Enabled: false
|
|
63
|
+
Style/Send:
|
|
64
|
+
Enabled: true
|
|
65
|
+
Style/SignalException:
|
|
66
|
+
EnforcedStyle: semantic
|
|
67
|
+
Style/StringLiterals:
|
|
68
|
+
EnforcedStyle: double_quotes
|
|
69
|
+
Style/StringLiteralsInInterpolation:
|
|
70
|
+
EnforcedStyle: double_quotes
|
|
71
|
+
Style/StringMethods:
|
|
72
|
+
Enabled: true
|
|
73
|
+
Style/SymbolArray:
|
|
74
|
+
Enabled: true
|
|
75
|
+
# this allows in rspec to have expect { } with multiple lines
|
|
76
|
+
Style/BlockDelimiters:
|
|
77
|
+
EnforcedStyle: braces_for_chaining
|
|
78
|
+
Layout/EndOfLine:
|
|
79
|
+
Enabled: false
|
|
80
|
+
# don't need these checks in test folders
|
|
81
|
+
Metrics/ModuleLength:
|
|
82
|
+
Exclude:
|
|
83
|
+
- "spec/**/*"
|
|
84
|
+
- "test/**/*"
|
|
85
|
+
Metrics/BlockLength:
|
|
86
|
+
Exclude:
|
|
87
|
+
- "spec/**/*"
|
|
88
|
+
- "test/**/*"
|
|
89
|
+
- "*.gemspec" # definitely not in the gemspec
|
|
90
|
+
Metrics/MethodLength:
|
|
91
|
+
Max: 20
|
|
92
|
+
Lint/UnreachableCode:
|
|
93
|
+
Description: 'Unreachable code.'
|
|
94
|
+
Enabled: false
|
|
95
|
+
Lint/Void:
|
|
96
|
+
Enabled: false
|
|
97
|
+
Layout/AlignHash:
|
|
98
|
+
EnforcedLastArgumentHashStyle: ignore_implicit
|
|
99
|
+
Metrics/AbcSize:
|
|
100
|
+
Max: 25
|
|
101
|
+
Style/LambdaCall:
|
|
102
|
+
Enabled: false
|
|
103
|
+
Style/Semicolon:
|
|
104
|
+
Enabled: false
|
|
105
|
+
Naming/UncommunicativeMethodParamName:
|
|
106
|
+
Enabled: false
|
|
107
|
+
Style/ClassAndModuleChildren:
|
|
108
|
+
Enabled: false
|
|
109
|
+
Layout/LeadingCommentSpace:
|
|
110
|
+
Exclude:
|
|
111
|
+
- 'test/docs/**/*'
|
|
112
|
+
Layout/AlignHash:
|
|
113
|
+
EnforcedHashRocketStyle: table
|
|
114
|
+
Style/FrozenStringLiteralComment:
|
|
115
|
+
Enabled: false
|
|
116
|
+
Layout/AlignHash:
|
|
117
|
+
EnforcedColonStyle: table
|
|
118
|
+
SingleLineMethods:
|
|
119
|
+
Enabled: false
|
|
120
|
+
Style/Lambda:
|
|
121
|
+
EnforcedStyle: literal
|
|
122
|
+
Style/AsciiComments:
|
|
123
|
+
Enabled: false
|
|
124
|
+
Style/CollectionMethods:
|
|
125
|
+
Enabled: false
|
|
126
|
+
Style/RedundantReturn:
|
|
127
|
+
Enabled: false
|
|
128
|
+
Style/PercentLiteralDelimiters:
|
|
129
|
+
PreferredDelimiters:
|
|
130
|
+
default: {}
|
|
131
|
+
"%q": '()'
|
|
132
|
+
"%r": '{}'
|
|
133
|
+
"%w": '[]'
|
|
134
|
+
"%": '{}'
|
|
135
|
+
Style/HashSyntax:
|
|
136
|
+
Enabled: false
|
data/.rubocop.yml
CHANGED
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
inherit_from:
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
EnforcedStyle: double_quotes
|
|
5
|
-
Style/StringLiteralsInInterpolation:
|
|
6
|
-
EnforcedStyle: double_quotes
|
|
1
|
+
inherit_from:
|
|
2
|
+
- https://raw.githubusercontent.com/trailblazer/meta/master/rubocop.yml
|
|
3
|
+
- .rubocop_todo.yml
|
|
7
4
|
|
|
8
5
|
Naming/MethodName:
|
|
9
6
|
Exclude:
|
data/.rubocop_todo.yml
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# This configuration was generated by
|
|
2
2
|
# `rubocop --auto-gen-config`
|
|
3
|
-
# on 2018-
|
|
3
|
+
# on 2018-06-19 17:19:28 +0800 using RuboCop version 0.57.2.
|
|
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
|
|
@@ -21,14 +21,6 @@ Bundler/OrderedGems:
|
|
|
21
21
|
Exclude:
|
|
22
22
|
- 'Gemfile'
|
|
23
23
|
|
|
24
|
-
# Offense count: 2
|
|
25
|
-
# Cop supports --auto-correct.
|
|
26
|
-
# Configuration parameters: Include, TreatCommentsAsGroupSeparators.
|
|
27
|
-
# Include: **/*.gemspec
|
|
28
|
-
Gemspec/OrderedDependencies:
|
|
29
|
-
Exclude:
|
|
30
|
-
- 'trailblazer-macro-contract.gemspec'
|
|
31
|
-
|
|
32
24
|
# Offense count: 1
|
|
33
25
|
# Configuration parameters: Include.
|
|
34
26
|
# Include: **/*.gemspec
|
|
@@ -71,20 +63,20 @@ Layout/LeadingCommentSpace:
|
|
|
71
63
|
Exclude:
|
|
72
64
|
- 'test/docs/contract_test.rb'
|
|
73
65
|
|
|
74
|
-
# Offense count:
|
|
66
|
+
# Offense count: 1
|
|
75
67
|
# Cop supports --auto-correct.
|
|
76
|
-
|
|
68
|
+
# Configuration parameters: EnforcedStyle.
|
|
69
|
+
# SupportedTypes: block, case, class, if, kwbegin, module
|
|
70
|
+
# SupportedStyles: same_line, new_line
|
|
71
|
+
Layout/MultilineAssignmentLayout:
|
|
77
72
|
Exclude:
|
|
78
|
-
- 'lib/trailblazer/operation/contract.rb'
|
|
79
73
|
- 'lib/trailblazer/operation/validate.rb'
|
|
80
|
-
- 'test/docs/contract_test.rb'
|
|
81
74
|
|
|
82
|
-
# Offense count:
|
|
75
|
+
# Offense count: 3
|
|
83
76
|
# Cop supports --auto-correct.
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
EnforcedStyle: no_space
|
|
77
|
+
Layout/SpaceAfterColon:
|
|
78
|
+
Exclude:
|
|
79
|
+
- 'test/docs/contract_test.rb'
|
|
88
80
|
|
|
89
81
|
# Offense count: 7
|
|
90
82
|
# Cop supports --auto-correct.
|
|
@@ -104,7 +96,7 @@ Layout/SpaceInsideBlockBraces:
|
|
|
104
96
|
Exclude:
|
|
105
97
|
- 'test/docs/contract_test.rb'
|
|
106
98
|
|
|
107
|
-
# Offense count:
|
|
99
|
+
# Offense count: 92
|
|
108
100
|
# Cop supports --auto-correct.
|
|
109
101
|
# Configuration parameters: EnforcedStyle, EnforcedStyleForEmptyBraces.
|
|
110
102
|
# SupportedStyles: space, no_space, compact
|
|
@@ -112,20 +104,17 @@ Layout/SpaceInsideBlockBraces:
|
|
|
112
104
|
Layout/SpaceInsideHashLiteralBraces:
|
|
113
105
|
Exclude:
|
|
114
106
|
- 'test/docs/contract_test.rb'
|
|
107
|
+
- 'test/docs/dry_test.rb'
|
|
115
108
|
- 'test/operation/contract_test.rb'
|
|
116
|
-
- 'test/
|
|
109
|
+
- 'test/operation/persist_test.rb'
|
|
117
110
|
|
|
118
|
-
# Offense count:
|
|
111
|
+
# Offense count: 95
|
|
119
112
|
# Cop supports --auto-correct.
|
|
120
113
|
# Configuration parameters: EnforcedStyle.
|
|
121
114
|
# SupportedStyles: space, no_space
|
|
122
115
|
Layout/SpaceInsideParens:
|
|
123
116
|
Exclude:
|
|
124
|
-
- 'lib/trailblazer/operation/contract.rb'
|
|
125
|
-
- 'lib/trailblazer/operation/persist.rb'
|
|
126
|
-
- 'lib/trailblazer/operation/validate.rb'
|
|
127
117
|
- 'test/docs/contract_test.rb'
|
|
128
|
-
- 'test/docs/dry_test.rb'
|
|
129
118
|
- 'test/operation/contract_test.rb'
|
|
130
119
|
- 'test/operation/persist_test.rb'
|
|
131
120
|
|
|
@@ -142,11 +131,6 @@ Lint/ParenthesesAsGroupedExpression:
|
|
|
142
131
|
Exclude:
|
|
143
132
|
- 'test/docs/contract_test.rb'
|
|
144
133
|
|
|
145
|
-
# Offense count: 1
|
|
146
|
-
Lint/UnreachableCode:
|
|
147
|
-
Exclude:
|
|
148
|
-
- 'test/operation/persist_test.rb'
|
|
149
|
-
|
|
150
134
|
# Offense count: 2
|
|
151
135
|
# Cop supports --auto-correct.
|
|
152
136
|
# Configuration parameters: IgnoreEmptyBlocks, AllowUnusedKeywordArguments.
|
|
@@ -154,6 +138,12 @@ Lint/UnusedBlockArgument:
|
|
|
154
138
|
Exclude:
|
|
155
139
|
- 'test/test_helper.rb'
|
|
156
140
|
|
|
141
|
+
# Offense count: 33
|
|
142
|
+
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
|
|
143
|
+
# URISchemes: http, https
|
|
144
|
+
Metrics/LineLength:
|
|
145
|
+
Max: 214
|
|
146
|
+
|
|
157
147
|
# Offense count: 1
|
|
158
148
|
# Cop supports --auto-correct.
|
|
159
149
|
Style/BlockComments:
|
|
@@ -168,7 +158,7 @@ Style/BracesAroundHashParameters:
|
|
|
168
158
|
Exclude:
|
|
169
159
|
- 'test/operation/contract_test.rb'
|
|
170
160
|
|
|
171
|
-
# Offense count:
|
|
161
|
+
# Offense count: 10
|
|
172
162
|
# Cop supports --auto-correct.
|
|
173
163
|
# Configuration parameters: AutoCorrect, EnforcedStyle.
|
|
174
164
|
# SupportedStyles: nested, compact
|
|
@@ -181,15 +171,6 @@ Style/CommentedKeyword:
|
|
|
181
171
|
Exclude:
|
|
182
172
|
- 'lib/trailblazer/operation/validate.rb'
|
|
183
173
|
|
|
184
|
-
# Offense count: 6
|
|
185
|
-
Style/Documentation:
|
|
186
|
-
Exclude:
|
|
187
|
-
- 'spec/**/*'
|
|
188
|
-
- 'test/**/*'
|
|
189
|
-
- 'lib/trailblazer/operation/contract.rb'
|
|
190
|
-
- 'lib/trailblazer/operation/persist.rb'
|
|
191
|
-
- 'lib/trailblazer/operation/validate.rb'
|
|
192
|
-
|
|
193
174
|
# Offense count: 1
|
|
194
175
|
# Cop supports --auto-correct.
|
|
195
176
|
Style/ExpandPathArguments:
|
|
@@ -206,20 +187,13 @@ Style/HashSyntax:
|
|
|
206
187
|
- 'test/docs/contract_test.rb'
|
|
207
188
|
- 'test/operation/contract_test.rb'
|
|
208
189
|
|
|
209
|
-
# Offense count: 66
|
|
210
|
-
# Cop supports --auto-correct.
|
|
211
|
-
# Configuration parameters: .
|
|
212
|
-
# SupportedStyles: call, braces
|
|
213
|
-
Style/LambdaCall:
|
|
214
|
-
EnforcedStyle: braces
|
|
215
|
-
|
|
216
190
|
# Offense count: 2
|
|
217
191
|
# Cop supports --auto-correct.
|
|
218
192
|
Style/ParallelAssignment:
|
|
219
193
|
Exclude:
|
|
220
194
|
- 'lib/trailblazer/operation/validate.rb'
|
|
221
195
|
|
|
222
|
-
# Offense count:
|
|
196
|
+
# Offense count: 34
|
|
223
197
|
# Cop supports --auto-correct.
|
|
224
198
|
# Configuration parameters: PreferredDelimiters.
|
|
225
199
|
Style/PercentLiteralDelimiters:
|
|
@@ -228,14 +202,20 @@ Style/PercentLiteralDelimiters:
|
|
|
228
202
|
- 'test/docs/dry_test.rb'
|
|
229
203
|
- 'test/operation/contract_test.rb'
|
|
230
204
|
- 'test/operation/persist_test.rb'
|
|
205
|
+
- 'trailblazer-macro-contract.gemspec'
|
|
231
206
|
|
|
232
|
-
# Offense count:
|
|
207
|
+
# Offense count: 1
|
|
208
|
+
Style/Send:
|
|
209
|
+
Exclude:
|
|
210
|
+
- 'lib/trailblazer/operation/persist.rb'
|
|
211
|
+
|
|
212
|
+
# Offense count: 3
|
|
233
213
|
# Cop supports --auto-correct.
|
|
234
214
|
# Configuration parameters: EnforcedStyle.
|
|
235
215
|
# SupportedStyles: only_raise, only_fail, semantic
|
|
236
216
|
Style/SignalException:
|
|
237
217
|
Exclude:
|
|
238
|
-
- '
|
|
218
|
+
- 'lib/trailblazer/operation/contract.rb'
|
|
239
219
|
|
|
240
220
|
# Offense count: 6
|
|
241
221
|
# Cop supports --auto-correct.
|
|
@@ -245,7 +225,7 @@ Style/SingleLineMethods:
|
|
|
245
225
|
- 'test/operation/persist_test.rb'
|
|
246
226
|
- 'test/test_helper.rb'
|
|
247
227
|
|
|
248
|
-
# Offense count:
|
|
228
|
+
# Offense count: 11
|
|
249
229
|
# Cop supports --auto-correct.
|
|
250
230
|
# Configuration parameters: EnforcedStyle, ConsistentQuotesInMultiline.
|
|
251
231
|
# SupportedStyles: single_quotes, double_quotes
|
|
@@ -253,12 +233,5 @@ Style/StringLiterals:
|
|
|
253
233
|
Exclude:
|
|
254
234
|
- 'Gemfile'
|
|
255
235
|
- 'Rakefile'
|
|
256
|
-
- 'test/operation/contract_test.rb'
|
|
257
236
|
- 'test/test_helper.rb'
|
|
258
237
|
- 'trailblazer-macro-contract.gemspec'
|
|
259
|
-
|
|
260
|
-
# Offense count: 75
|
|
261
|
-
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
|
|
262
|
-
# URISchemes: http, https
|
|
263
|
-
Metrics/LineLength:
|
|
264
|
-
Max: 214
|
data/.travis.yml
CHANGED
data/CHANGES.md
CHANGED
data/Gemfile
CHANGED
|
@@ -4,21 +4,11 @@ gemspec
|
|
|
4
4
|
|
|
5
5
|
gem "dry-auto_inject"
|
|
6
6
|
gem "dry-matcher"
|
|
7
|
-
gem "dry-validation"
|
|
8
7
|
|
|
9
|
-
#
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
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
|
-
|
|
20
|
-
# gem "trailblazer-operation", github: "trailblazer/trailblazer-operation"
|
|
21
|
-
# gem "trailblazer-macro", github: "trailblazer/trailblazer-macro"
|
|
8
|
+
# gem "trailblazer-operation", path: "../trailblazer-operation"
|
|
9
|
+
# gem "trailblazer-macro", path: "../trailblazer-macro"
|
|
10
|
+
# gem "trailblazer-activity", path: "../trailblazer-activity"
|
|
11
|
+
# gem "trailblazer-activity-dsl-linear", path: "../trailblazer-activity-dsl-linear"
|
|
22
12
|
|
|
23
13
|
gem "minitest-line"
|
|
24
14
|
|
|
@@ -5,11 +5,11 @@ module Trailblazer
|
|
|
5
5
|
task = lambda do |(options, flow_options), **circuit_options|
|
|
6
6
|
result = Build.(options, circuit_options, name: name, constant: constant, builder: builder)
|
|
7
7
|
|
|
8
|
-
return Activity::TaskBuilder.binary_signal_for(
|
|
8
|
+
return Activity::TaskBuilder.binary_signal_for(result, Activity::Right, Activity::Left),
|
|
9
9
|
[options, flow_options]
|
|
10
10
|
end
|
|
11
11
|
|
|
12
|
-
{
|
|
12
|
+
{task: task, id: "contract.build"}
|
|
13
13
|
end
|
|
14
14
|
|
|
15
15
|
module Build
|
|
@@ -20,20 +20,19 @@ module Trailblazer
|
|
|
20
20
|
model = options[:model]
|
|
21
21
|
name = "contract.#{name}"
|
|
22
22
|
|
|
23
|
-
options[name] =
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
end
|
|
23
|
+
options[name] = if builder
|
|
24
|
+
call_builder(options, circuit_options, builder: builder, constant: contract_class, name: name)
|
|
25
|
+
else
|
|
26
|
+
contract_class.new(model)
|
|
27
|
+
end
|
|
29
28
|
end
|
|
30
29
|
|
|
31
|
-
def self.call_builder(options, circuit_options, builder:raise, constant:raise, name:raise)
|
|
30
|
+
def self.call_builder(options, circuit_options, builder: raise, constant: raise, name: raise)
|
|
32
31
|
tmp_options = options.to_hash.merge(
|
|
33
32
|
constant: constant,
|
|
34
33
|
name: name
|
|
35
34
|
)
|
|
36
|
-
Trailblazer::Option(builder).(
|
|
35
|
+
Trailblazer::Option(builder).(options, tmp_options, circuit_options)
|
|
37
36
|
end
|
|
38
37
|
end
|
|
39
38
|
|
|
@@ -48,10 +47,13 @@ module Trailblazer
|
|
|
48
47
|
# Op.contract do .. end # defines contract
|
|
49
48
|
# Op.contract CommentForm # copies (and subclasses) external contract.
|
|
50
49
|
# Op.contract CommentForm do .. end # copies and extends contract.
|
|
51
|
-
def contract(name
|
|
50
|
+
def contract(name = :default, constant = nil, base: Reform::Form, &block)
|
|
52
51
|
heritage.record(:contract, name, constant, &block)
|
|
53
52
|
|
|
54
|
-
path, form_class = Trailblazer::DSL::Build.new.(
|
|
53
|
+
path, form_class = Trailblazer::DSL::Build.new.(
|
|
54
|
+
{prefix: :contract, class: base, container: self},
|
|
55
|
+
name, constant, block
|
|
56
|
+
)
|
|
55
57
|
|
|
56
58
|
self[path] = form_class
|
|
57
59
|
end
|
|
@@ -5,9 +5,9 @@ module Trailblazer
|
|
|
5
5
|
path = "contract.#{name}"
|
|
6
6
|
step = ->(options, **) { options[path].send(method) }
|
|
7
7
|
|
|
8
|
-
task = Activity::TaskBuilder::Binary(
|
|
8
|
+
task = Activity::TaskBuilder::Binary(step)
|
|
9
9
|
|
|
10
|
-
{
|
|
10
|
+
{task: task, id: "persist.save"}
|
|
11
11
|
end
|
|
12
12
|
end
|
|
13
13
|
end
|
|
@@ -8,21 +8,20 @@ module Trailblazer
|
|
|
8
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
|
-
extract = Validate::Extract.new(
|
|
12
|
-
validate = Validate.new(
|
|
11
|
+
extract = Validate::Extract.new(key: key, 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
|
-
activity =
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
step extract, id: "#{params_path}_extract", Activity::DSL.Output(:failure) => Activity::DSL.End(:extract_failure) unless skip_extract || representer
|
|
15
|
+
activity = Class.new(Activity::Railway(name: "Contract::Validate")) do
|
|
16
|
+
step extract, id: "#{params_path}_extract", Output(:failure) => End(:extract_failure) unless skip_extract# || representer
|
|
19
17
|
step validate, id: "contract.#{name}.call"
|
|
20
18
|
end
|
|
21
19
|
|
|
22
|
-
options =
|
|
20
|
+
options = activity.Subprocess(activity)
|
|
21
|
+
options = options.merge(id: "contract.#{name}.validate")
|
|
23
22
|
|
|
24
23
|
# Deviate End.extract_failure to the standard failure track as a default. This can be changed from the user side.
|
|
25
|
-
options = options.merge(
|
|
24
|
+
options = options.merge(activity.Output(:extract_failure) => activity.Track(:failure)) unless skip_extract
|
|
26
25
|
|
|
27
26
|
options
|
|
28
27
|
end
|
|
@@ -30,21 +29,21 @@ module Trailblazer
|
|
|
30
29
|
class Validate
|
|
31
30
|
# Task: extract the contract's input from params by reading `:key`.
|
|
32
31
|
class Extract
|
|
33
|
-
def initialize(key:nil, params_path:nil)
|
|
32
|
+
def initialize(key: nil, params_path: nil)
|
|
34
33
|
@key, @params_path = key, params_path
|
|
35
34
|
end
|
|
36
35
|
|
|
37
|
-
def call(
|
|
36
|
+
def call(ctx, params:, **)
|
|
38
37
|
ctx[@params_path] = @key ? params[@key] : params
|
|
39
38
|
end
|
|
40
39
|
end
|
|
41
40
|
|
|
42
|
-
def initialize(name:"default", representer:false, params_path:nil, constant: nil)
|
|
41
|
+
def initialize(name: "default", representer: false, params_path: nil, constant: nil)
|
|
43
42
|
@name, @representer, @params_path, @constant = name, representer, params_path, constant
|
|
44
43
|
end
|
|
45
44
|
|
|
46
45
|
# Task: Validates contract `:name`.
|
|
47
|
-
def call(
|
|
46
|
+
def call(ctx, **)
|
|
48
47
|
validate!(
|
|
49
48
|
ctx,
|
|
50
49
|
representer: ctx["representer.#{@name}.class"] ||= @representer, # FIXME: maybe @representer should use DI.
|
|
@@ -52,7 +51,7 @@ module Trailblazer
|
|
|
52
51
|
)
|
|
53
52
|
end
|
|
54
53
|
|
|
55
|
-
def validate!(options, representer:false, from: :document, params_path:nil)
|
|
54
|
+
def validate!(options, representer: false, from: :document, params_path: nil)
|
|
56
55
|
path = "contract.#{@name}"
|
|
57
56
|
contract = @constant || options[path]
|
|
58
57
|
|
data/test/docs/contract_test.rb
CHANGED
|
@@ -57,15 +57,15 @@ class DocsContractOverviewTest < Minitest::Spec
|
|
|
57
57
|
it "shows 2-level tracing" do
|
|
58
58
|
result = Create.trace( params: { length: "A" } )
|
|
59
59
|
result.wtf.gsub(/0x\w+/, "").must_equal %{`-- DocsContractOverviewTest::Create
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
60
|
+
|-- Start.default
|
|
61
|
+
|-- model.build
|
|
62
|
+
|-- contract.build
|
|
63
|
+
|-- contract.default.validate
|
|
64
|
+
| |-- Start.default
|
|
65
|
+
| |-- contract.default.params_extract
|
|
66
|
+
| |-- contract.default.call
|
|
67
|
+
| `-- End.failure
|
|
68
|
+
`-- End.failure}
|
|
69
69
|
end
|
|
70
70
|
end
|
|
71
71
|
#---
|
|
@@ -392,10 +392,10 @@ class DryValidationContractTest < Minitest::Spec
|
|
|
392
392
|
puts "@@@@@ #{Trailblazer::Operation::Inspect.(Create, style: :rows)}"
|
|
393
393
|
|
|
394
394
|
it { Create.(params: {}).inspect("result.contract.default").must_include "Result:false"}
|
|
395
|
-
it { Create.(params: {}).inspect("result.contract.default").must_include "
|
|
395
|
+
it { Create.(params: {}).inspect("result.contract.default").must_include "errors={:id=>[\"must be filled\""}
|
|
396
396
|
|
|
397
397
|
it { Create.(params: { id: 1 }).inspect(:model, "result.contract.default").must_include "Result:false"}
|
|
398
|
-
it { Create.(params: { id: 1 }).inspect(:model, "result.contract.default").must_include "
|
|
398
|
+
it { Create.(params: { id: 1 }).inspect(:model, "result.contract.default").must_include "errors={:title=>[\"must be filled\", \"size cannot be less than 2\"]}"}
|
|
399
399
|
it { Create.(params: { id: 1 }).inspect(:model, "result.contract.default").wont_include ":id=>[\"must be filled\""}
|
|
400
400
|
|
|
401
401
|
it { Create.(params: { id: 1, title: "" }).inspect(:model).must_equal %{<Result:false [#<struct DryValidationContractTest::Song id=nil, title=nil>] >} }
|
data/test/docs/dry_test.rb
CHANGED
|
@@ -19,13 +19,15 @@ class DryContainerTest < Minitest::Spec
|
|
|
19
19
|
#- dependency injection
|
|
20
20
|
#- with Dry-container
|
|
21
21
|
class Create < Trailblazer::Operation
|
|
22
|
-
|
|
22
|
+
extend Trailblazer::Operation::Container
|
|
23
|
+
|
|
24
|
+
step Model(Song, :new)
|
|
23
25
|
step Contract::Build()
|
|
24
26
|
step Contract::Validate()
|
|
25
|
-
step Contract::Persist(
|
|
27
|
+
step Contract::Persist(method: :sync)
|
|
26
28
|
end
|
|
27
29
|
#:key end
|
|
28
30
|
|
|
29
|
-
it { Create.({
|
|
30
|
-
it { Create.({
|
|
31
|
+
it { Create.({params: {title: "A" } }, my_container).inspect(:model).must_equal %{<Result:false [#<struct DryContainerTest::Song id=nil, title=nil>] >} }
|
|
32
|
+
it { Create.({params: {title: "Anthony's Song" } }, my_container).inspect(:model).must_equal %{<Result:true [#<struct DryContainerTest::Song id=nil, title="Anthony's Song">] >} }
|
|
31
33
|
end
|
|
@@ -4,7 +4,7 @@ require 'trailblazer/macro/contract/version'
|
|
|
4
4
|
|
|
5
5
|
Gem::Specification.new do |spec|
|
|
6
6
|
spec.name = "trailblazer-macro-contract"
|
|
7
|
-
spec.version = Trailblazer::Macro::Contract::VERSION
|
|
7
|
+
spec.version = Trailblazer::Version::Macro::Contract::VERSION
|
|
8
8
|
spec.authors = ["Nick Sutterer"]
|
|
9
9
|
spec.email = ["apotonick@gmail.com"]
|
|
10
10
|
spec.description = 'Trailblazer operation form object specific macros'
|
|
@@ -21,12 +21,12 @@ Gem::Specification.new do |spec|
|
|
|
21
21
|
spec.add_dependency "reform", ">= 2.2.0", "< 3.0.0"
|
|
22
22
|
|
|
23
23
|
spec.add_development_dependency "bundler"
|
|
24
|
-
spec.add_development_dependency "
|
|
25
|
-
spec.add_development_dependency "reform-rails"
|
|
26
|
-
spec.add_development_dependency "
|
|
24
|
+
spec.add_development_dependency "dry-validation", "0.11.1" # FIXME: upgrade example code
|
|
25
|
+
spec.add_development_dependency "reform-rails", "~> 0.2.0.rc2"
|
|
26
|
+
spec.add_development_dependency "trailblazer-macro", ">= 2.1.0.rc11", "< 2.2.0"
|
|
27
27
|
|
|
28
28
|
spec.add_development_dependency "minitest"
|
|
29
29
|
spec.add_development_dependency "rake"
|
|
30
30
|
|
|
31
|
-
spec.required_ruby_version =
|
|
31
|
+
spec.required_ruby_version = ">= 2.0.0"
|
|
32
32
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
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.rc11
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Nick Sutterer
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2019-06-16 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: reform
|
|
@@ -45,53 +45,53 @@ dependencies:
|
|
|
45
45
|
- !ruby/object:Gem::Version
|
|
46
46
|
version: '0'
|
|
47
47
|
- !ruby/object:Gem::Dependency
|
|
48
|
-
name:
|
|
48
|
+
name: dry-validation
|
|
49
49
|
requirement: !ruby/object:Gem::Requirement
|
|
50
50
|
requirements:
|
|
51
|
-
- -
|
|
51
|
+
- - '='
|
|
52
52
|
- !ruby/object:Gem::Version
|
|
53
|
-
version:
|
|
54
|
-
- - "<"
|
|
55
|
-
- !ruby/object:Gem::Version
|
|
56
|
-
version: 2.2.0
|
|
53
|
+
version: 0.11.1
|
|
57
54
|
type: :development
|
|
58
55
|
prerelease: false
|
|
59
56
|
version_requirements: !ruby/object:Gem::Requirement
|
|
60
57
|
requirements:
|
|
61
|
-
- -
|
|
62
|
-
- !ruby/object:Gem::Version
|
|
63
|
-
version: 2.1.0.rc1
|
|
64
|
-
- - "<"
|
|
58
|
+
- - '='
|
|
65
59
|
- !ruby/object:Gem::Version
|
|
66
|
-
version:
|
|
60
|
+
version: 0.11.1
|
|
67
61
|
- !ruby/object:Gem::Dependency
|
|
68
62
|
name: reform-rails
|
|
69
63
|
requirement: !ruby/object:Gem::Requirement
|
|
70
64
|
requirements:
|
|
71
|
-
- - "
|
|
65
|
+
- - "~>"
|
|
72
66
|
- !ruby/object:Gem::Version
|
|
73
|
-
version:
|
|
67
|
+
version: 0.2.0.rc2
|
|
74
68
|
type: :development
|
|
75
69
|
prerelease: false
|
|
76
70
|
version_requirements: !ruby/object:Gem::Requirement
|
|
77
71
|
requirements:
|
|
78
|
-
- - "
|
|
72
|
+
- - "~>"
|
|
79
73
|
- !ruby/object:Gem::Version
|
|
80
|
-
version:
|
|
74
|
+
version: 0.2.0.rc2
|
|
81
75
|
- !ruby/object:Gem::Dependency
|
|
82
|
-
name:
|
|
76
|
+
name: trailblazer-macro
|
|
83
77
|
requirement: !ruby/object:Gem::Requirement
|
|
84
78
|
requirements:
|
|
85
79
|
- - ">="
|
|
86
80
|
- !ruby/object:Gem::Version
|
|
87
|
-
version:
|
|
81
|
+
version: 2.1.0.rc11
|
|
82
|
+
- - "<"
|
|
83
|
+
- !ruby/object:Gem::Version
|
|
84
|
+
version: 2.2.0
|
|
88
85
|
type: :development
|
|
89
86
|
prerelease: false
|
|
90
87
|
version_requirements: !ruby/object:Gem::Requirement
|
|
91
88
|
requirements:
|
|
92
89
|
- - ">="
|
|
93
90
|
- !ruby/object:Gem::Version
|
|
94
|
-
version:
|
|
91
|
+
version: 2.1.0.rc11
|
|
92
|
+
- - "<"
|
|
93
|
+
- !ruby/object:Gem::Version
|
|
94
|
+
version: 2.2.0
|
|
95
95
|
- !ruby/object:Gem::Dependency
|
|
96
96
|
name: minitest
|
|
97
97
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -128,6 +128,7 @@ extensions: []
|
|
|
128
128
|
extra_rdoc_files: []
|
|
129
129
|
files:
|
|
130
130
|
- ".gitignore"
|
|
131
|
+
- ".rubocop-https---raw-githubusercontent-com-trailblazer-meta-master-rubocop-yml"
|
|
131
132
|
- ".rubocop.yml"
|
|
132
133
|
- ".rubocop_todo.yml"
|
|
133
134
|
- ".travis.yml"
|