trailblazer-macro-contract 2.1.0.rc1 → 2.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop-https---raw-githubusercontent-com-trailblazer-meta-master-rubocop-yml +127 -0
- data/.rubocop.yml +3 -6
- data/.rubocop_todo.yml +31 -58
- data/.travis.yml +1 -1
- data/CHANGES.md +20 -0
- data/Gemfile +5 -14
- data/LICENSE +9 -0
- data/lib/trailblazer/macro/contract.rb +19 -5
- data/lib/trailblazer/{operation/contract.rb → macro/contract/build.rb} +22 -17
- data/lib/trailblazer/{operation → macro/contract}/persist.rb +4 -4
- data/lib/trailblazer/{operation → macro/contract}/validate.rb +22 -20
- data/lib/trailblazer/macro/contract/version.rb +5 -3
- data/test/docs/contract_test.rb +74 -28
- data/test/docs/dry_test.rb +28 -26
- data/test/operation/contract_test.rb +9 -7
- data/test/operation/persist_test.rb +2 -2
- data/test/test_helper.rb +5 -1
- data/trailblazer-macro-contract.gemspec +12 -7
- metadata +80 -24
- data/LICENSE.txt +0 -27
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 523435b29f2464a1677f6b430e8285b62841e4b24f4ebfdf19bcab531239ba70
|
4
|
+
data.tar.gz: 30cda42970110b3d8b280d002b785ada64445cb8212b1a6040432df5218f8fa4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b9922fdf9cfac45598fe3d1d4672e708bacf54e41779b38d35e28dbfbee78de92eafe29bdabcda01369bbcf96265917129d0cdc0d8abcc85b1bf3cb2c3c4bbf3
|
7
|
+
data.tar.gz: bb8f91f57343237ac0995fa8f2516558ccabf799c9b0bf64c0c6024bae6a61285ba867bb97e1d10d2b99fc8e510ad611a6a523bf439d2df01f9ced40c6eeefa7
|
@@ -0,0 +1,127 @@
|
|
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/Documentation:
|
30
|
+
Enabled: false
|
31
|
+
Style/EmptyLiteral:
|
32
|
+
Enabled: false
|
33
|
+
Style/EmptyMethod:
|
34
|
+
EnforcedStyle: expanded
|
35
|
+
Style/FormatStringToken:
|
36
|
+
EnforcedStyle: template
|
37
|
+
Style/ImplicitRuntimeError:
|
38
|
+
Enabled: true
|
39
|
+
Style/MethodCalledOnDoEndBlock:
|
40
|
+
Enabled: true
|
41
|
+
Style/MethodDefParentheses:
|
42
|
+
EnforcedStyle: require_parentheses
|
43
|
+
Style/MissingElse:
|
44
|
+
Enabled: true
|
45
|
+
EnforcedStyle: case
|
46
|
+
Style/NumericLiterals:
|
47
|
+
Enabled: false
|
48
|
+
Style/OptionHash:
|
49
|
+
Enabled: true
|
50
|
+
Style/ReturnNil:
|
51
|
+
Enabled: true
|
52
|
+
Style/SafeNavigation:
|
53
|
+
Enabled: false
|
54
|
+
Style/Send:
|
55
|
+
Enabled: true
|
56
|
+
Style/SignalException:
|
57
|
+
EnforcedStyle: semantic
|
58
|
+
Style/StringLiterals:
|
59
|
+
EnforcedStyle: double_quotes
|
60
|
+
Style/StringLiteralsInInterpolation:
|
61
|
+
EnforcedStyle: double_quotes
|
62
|
+
Style/StringMethods:
|
63
|
+
Enabled: true
|
64
|
+
Style/SymbolArray:
|
65
|
+
Enabled: true
|
66
|
+
# this allows in rspec to have expect { } with multiple lines
|
67
|
+
Style/BlockDelimiters:
|
68
|
+
EnforcedStyle: braces_for_chaining
|
69
|
+
Layout/EndOfLine:
|
70
|
+
Enabled: false
|
71
|
+
# don't need these checks in test folders
|
72
|
+
Metrics/ModuleLength:
|
73
|
+
Exclude:
|
74
|
+
- "spec/**/*"
|
75
|
+
- "test/**/*"
|
76
|
+
Metrics/BlockLength:
|
77
|
+
Exclude:
|
78
|
+
- "spec/**/*"
|
79
|
+
- "test/**/*"
|
80
|
+
- "*.gemspec" # definitely not in the gemspec
|
81
|
+
Metrics/MethodLength:
|
82
|
+
Max: 20
|
83
|
+
Lint/UnreachableCode:
|
84
|
+
Description: 'Unreachable code.'
|
85
|
+
Enabled: false
|
86
|
+
Lint/Void:
|
87
|
+
Enabled: false
|
88
|
+
Metrics/AbcSize:
|
89
|
+
Max: 25
|
90
|
+
Style/LambdaCall:
|
91
|
+
Enabled: false
|
92
|
+
Style/Semicolon:
|
93
|
+
Enabled: false
|
94
|
+
Naming/MethodParameterName:
|
95
|
+
Enabled: false
|
96
|
+
Style/ClassAndModuleChildren:
|
97
|
+
Enabled: false
|
98
|
+
Layout/LeadingCommentSpace:
|
99
|
+
Exclude:
|
100
|
+
- 'test/docs/**/*'
|
101
|
+
Layout/HashAlignment:
|
102
|
+
EnforcedHashRocketStyle: table
|
103
|
+
EnforcedColonStyle: table
|
104
|
+
Style/FrozenStringLiteralComment:
|
105
|
+
Enabled: false
|
106
|
+
SingleLineMethods:
|
107
|
+
Enabled: false
|
108
|
+
Style/Lambda:
|
109
|
+
EnforcedStyle: literal
|
110
|
+
Style/AsciiComments:
|
111
|
+
Enabled: false
|
112
|
+
Style/CollectionMethods:
|
113
|
+
Enabled: false
|
114
|
+
Style/RedundantReturn:
|
115
|
+
Enabled: false
|
116
|
+
Style/PercentLiteralDelimiters:
|
117
|
+
PreferredDelimiters:
|
118
|
+
default: {}
|
119
|
+
"%q": '()'
|
120
|
+
"%r": '{}'
|
121
|
+
"%w": '[]'
|
122
|
+
"%": '{}'
|
123
|
+
"%W": '[]'
|
124
|
+
"%i": '[]'
|
125
|
+
"%I": '[]'
|
126
|
+
Style/HashSyntax:
|
127
|
+
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
@@ -1,3 +1,23 @@
|
|
1
|
+
# 2.1.1
|
2
|
+
|
3
|
+
* Support for Ruby 3.0.
|
4
|
+
|
5
|
+
# 2.1.0
|
6
|
+
|
7
|
+
* Finally.
|
8
|
+
|
9
|
+
# 2.1.0.rc13
|
10
|
+
|
11
|
+
* Use symbol keys on `ctx`, only.
|
12
|
+
|
13
|
+
# 2.1.0.rc12
|
14
|
+
|
15
|
+
* Dependencies updated.
|
16
|
+
|
17
|
+
# 2.1.0.rc11
|
18
|
+
|
19
|
+
* Use `>= activity-0.8`.
|
20
|
+
|
1
21
|
# 2.1.0.rc1
|
2
22
|
|
3
23
|
* Add a separate End to Validate. When the key extraction fails, the Validate activity will
|
data/Gemfile
CHANGED
@@ -4,21 +4,12 @@ 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
|
-
|
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"
|
12
|
+
# gem "reform", path: "../reform"
|
22
13
|
|
23
14
|
gem "minitest-line"
|
24
15
|
|
data/LICENSE
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
Copyright (c) 2018 Trailblazer GmbH
|
2
|
+
|
3
|
+
Trailblazer is an Open Source project licensed under the terms of
|
4
|
+
the LGPLv3 license. Please see <http://www.gnu.org/licenses/lgpl-3.0.html>
|
5
|
+
for license text.
|
6
|
+
|
7
|
+
Trailblazer PRO has a commercial-friendly license allowing private forks
|
8
|
+
and modifications of Trailblazer. Please see http://trailblazer.to/pro for
|
9
|
+
more detail.
|
@@ -1,5 +1,19 @@
|
|
1
|
-
require "
|
2
|
-
require "trailblazer/
|
3
|
-
|
4
|
-
require "trailblazer/
|
5
|
-
require "trailblazer/
|
1
|
+
require "trailblazer/activity"
|
2
|
+
require "trailblazer/activity/dsl/linear"
|
3
|
+
|
4
|
+
require "trailblazer/macro/contract/build"
|
5
|
+
require "trailblazer/macro/contract/validate"
|
6
|
+
require "trailblazer/macro/contract/persist"
|
7
|
+
|
8
|
+
module Trailblazer
|
9
|
+
module Macro
|
10
|
+
module Contract
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
# All macros sit in the {Trailblazer::Macro::Contract} namespace, where we forward calls from
|
15
|
+
# operations and activities to.
|
16
|
+
module Activity::DSL::Linear::Helper
|
17
|
+
Contract = Macro::Contract
|
18
|
+
end
|
19
|
+
end
|
@@ -1,39 +1,41 @@
|
|
1
|
+
require "reform"
|
2
|
+
|
1
3
|
module Trailblazer
|
2
|
-
|
4
|
+
module Macro
|
3
5
|
module Contract
|
4
6
|
def self.Build(name: "default", constant: nil, builder: nil)
|
5
7
|
task = lambda do |(options, flow_options), **circuit_options|
|
6
8
|
result = Build.(options, circuit_options, name: name, constant: constant, builder: builder)
|
7
9
|
|
8
|
-
return Activity::TaskBuilder.binary_signal_for(
|
10
|
+
return Activity::TaskBuilder.binary_signal_for(result, Activity::Right, Activity::Left),
|
9
11
|
[options, flow_options]
|
10
12
|
end
|
11
13
|
|
12
|
-
{
|
14
|
+
{task: task, id: "contract.build"}
|
13
15
|
end
|
14
16
|
|
15
17
|
module Build
|
16
18
|
# Build contract at runtime.
|
17
19
|
def self.call(options, circuit_options, name: "default", constant: nil, builder: nil)
|
18
20
|
# TODO: we could probably clean this up a bit at some point.
|
19
|
-
contract_class = constant || options["contract.#{name}.class"] # DISCUSS: Injection possible here?
|
21
|
+
contract_class = constant || options[:"contract.#{name}.class"] # DISCUSS: Injection possible here?
|
20
22
|
model = options[:model]
|
21
|
-
name = "contract.#{name}"
|
22
|
-
|
23
|
-
options[name] =
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
end
|
23
|
+
name = :"contract.#{name}"
|
24
|
+
|
25
|
+
options[name] = if builder
|
26
|
+
call_builder(options, circuit_options, builder: builder, constant: contract_class, name: name)
|
27
|
+
else
|
28
|
+
contract_class.new(model)
|
29
|
+
end
|
29
30
|
end
|
30
31
|
|
31
|
-
def self.call_builder(
|
32
|
-
tmp_options =
|
32
|
+
def self.call_builder(ctx, circuit_options, builder: raise, constant: raise, name: raise)
|
33
|
+
tmp_options = ctx.to_hash.merge(
|
33
34
|
constant: constant,
|
34
35
|
name: name
|
35
36
|
)
|
36
|
-
|
37
|
+
|
38
|
+
Trailblazer::Option(builder).(ctx, keyword_arguments: tmp_options, **circuit_options) # TODO: why can't we build the {builder} at compile time?
|
37
39
|
end
|
38
40
|
end
|
39
41
|
|
@@ -48,10 +50,13 @@ module Trailblazer
|
|
48
50
|
# Op.contract do .. end # defines contract
|
49
51
|
# Op.contract CommentForm # copies (and subclasses) external contract.
|
50
52
|
# Op.contract CommentForm do .. end # copies and extends contract.
|
51
|
-
def contract(name
|
53
|
+
def contract(name = :default, constant = nil, base: Reform::Form, &block)
|
52
54
|
heritage.record(:contract, name, constant, &block)
|
53
55
|
|
54
|
-
path, form_class = Trailblazer::DSL::Build.new.(
|
56
|
+
path, form_class = Trailblazer::DSL::Build.new.(
|
57
|
+
{prefix: :contract, class: base, container: self},
|
58
|
+
name, constant, block
|
59
|
+
)
|
55
60
|
|
56
61
|
self[path] = form_class
|
57
62
|
end
|
@@ -1,13 +1,13 @@
|
|
1
1
|
module Trailblazer
|
2
|
-
|
2
|
+
module Macro
|
3
3
|
module Contract
|
4
4
|
def self.Persist(method: :save, name: "default")
|
5
|
-
path = "contract.#{name}"
|
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
|
@@ -1,28 +1,30 @@
|
|
1
1
|
module Trailblazer
|
2
|
-
|
2
|
+
module Macro
|
3
3
|
module Contract
|
4
4
|
# result.contract = {..}
|
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, constant: nil) # DISCUSS: should we introduce something like Validate::Deserializer?
|
9
|
-
params_path = "contract.#{name}.params" # extract_params! save extracted params here.
|
8
|
+
def self.Validate(skip_extract: false, name: "default", representer: false, key: nil, constant: nil, invalid_data_terminus: false) # DISCUSS: should we introduce something like Validate::Deserializer?
|
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
|
25
|
+
|
26
|
+
# Halt failure track to End with {contract.name.invalid}.
|
27
|
+
options = options.merge(activity.Output(:failure) => activity.End(:invalid_data)) if invalid_data_terminus
|
26
28
|
|
27
29
|
options
|
28
30
|
end
|
@@ -30,34 +32,34 @@ module Trailblazer
|
|
30
32
|
class Validate
|
31
33
|
# Task: extract the contract's input from params by reading `:key`.
|
32
34
|
class Extract
|
33
|
-
def initialize(key:nil, params_path:nil)
|
35
|
+
def initialize(key: nil, params_path: nil)
|
34
36
|
@key, @params_path = key, params_path
|
35
37
|
end
|
36
38
|
|
37
|
-
def call(
|
39
|
+
def call(ctx, params: {}, **)
|
38
40
|
ctx[@params_path] = @key ? params[@key] : params
|
39
41
|
end
|
40
42
|
end
|
41
43
|
|
42
|
-
def initialize(name:"default", representer:false, params_path:nil, constant: nil)
|
44
|
+
def initialize(name: "default", representer: false, params_path: nil, constant: nil)
|
43
45
|
@name, @representer, @params_path, @constant = name, representer, params_path, constant
|
44
46
|
end
|
45
47
|
|
46
48
|
# Task: Validates contract `:name`.
|
47
|
-
def call(
|
49
|
+
def call(ctx, **)
|
48
50
|
validate!(
|
49
51
|
ctx,
|
50
|
-
representer: ctx["representer.#{@name}.class"] ||= @representer, # FIXME: maybe @representer should use DI.
|
52
|
+
representer: ctx[:"representer.#{@name}.class"] ||= @representer, # FIXME: maybe @representer should use DI.
|
51
53
|
params_path: @params_path
|
52
54
|
)
|
53
55
|
end
|
54
56
|
|
55
|
-
def validate!(options, representer:false, from: :document, params_path:nil)
|
56
|
-
path = "contract.#{@name}"
|
57
|
+
def validate!(options, representer: false, from: :document, params_path: nil)
|
58
|
+
path = :"contract.#{@name}"
|
57
59
|
contract = @constant || options[path]
|
58
60
|
|
59
61
|
# this is for 1.1-style compatibility and should be removed once we have Deserializer in place:
|
60
|
-
options["result.#{path}"] = result =
|
62
|
+
options[:"result.#{path}"] = result =
|
61
63
|
if representer
|
62
64
|
# use :document as the body and let the representer deserialize to the contract.
|
63
65
|
# this will be simplified once we have Deserializer.
|
@@ -72,5 +74,5 @@ module Trailblazer
|
|
72
74
|
end
|
73
75
|
end
|
74
76
|
end
|
75
|
-
end #
|
77
|
+
end # Macro
|
76
78
|
end
|
data/test/docs/contract_test.rb
CHANGED
@@ -24,7 +24,7 @@ class DocsContractOverviewTest < Minitest::Spec
|
|
24
24
|
end
|
25
25
|
#:overv-reform end
|
26
26
|
|
27
|
-
puts Trailblazer::
|
27
|
+
puts Trailblazer::Developer.railway(Create, style: :rows)
|
28
28
|
|
29
29
|
=begin
|
30
30
|
#:overv-reform-pipe
|
@@ -37,7 +37,7 @@ class DocsContractOverviewTest < Minitest::Spec
|
|
37
37
|
=end
|
38
38
|
|
39
39
|
it do
|
40
|
-
assert Create.(params: {})["contract.default"].must_be_instance_of DocsContractOverviewTest::Create::MyContract
|
40
|
+
assert Create.(params: {})[:"contract.default"].must_be_instance_of DocsContractOverviewTest::Create::MyContract
|
41
41
|
end
|
42
42
|
|
43
43
|
#- result
|
@@ -45,13 +45,13 @@ class DocsContractOverviewTest < Minitest::Spec
|
|
45
45
|
#:result
|
46
46
|
result = Create.(params: { length: "A" })
|
47
47
|
|
48
|
-
result["result.contract.default"].success? #=> false
|
49
|
-
result["result.contract.default"].errors #=> Errors object
|
50
|
-
result["result.contract.default"].errors.messages #=> {:length=>["is not a number"]}
|
48
|
+
result[:"result.contract.default"].success? #=> false
|
49
|
+
result[:"result.contract.default"].errors #=> Errors object
|
50
|
+
result[:"result.contract.default"].errors.messages #=> {:length=>["is not a number"]}
|
51
51
|
|
52
52
|
#:result end
|
53
|
-
result["result.contract.default"].success?.must_equal false
|
54
|
-
result["result.contract.default"].errors.messages.must_equal ({:title=>["can't be blank"], :length=>["is not a number"]})
|
53
|
+
result[:"result.contract.default"].success?.must_equal false
|
54
|
+
result[:"result.contract.default"].errors.messages.must_equal ({:title=>["can't be blank"], :length=>["is not a number"]})
|
55
55
|
end
|
56
56
|
|
57
57
|
it "shows 2-level tracing" do
|
@@ -114,7 +114,7 @@ class DocsContractSeparateKeyTest < Minitest::Spec
|
|
114
114
|
step Contract::Persist( method: :sync )
|
115
115
|
|
116
116
|
def extract_params!(options, **)
|
117
|
-
options["contract.default.params"] = options[:params][type]
|
117
|
+
options[:"contract.default.params"] = options[:params][type]
|
118
118
|
end
|
119
119
|
end
|
120
120
|
#:key-extr end
|
@@ -160,7 +160,7 @@ class ContractConstantTest < Minitest::Spec
|
|
160
160
|
#:constant-result
|
161
161
|
result = Song::Create.(params: { title: "A" })
|
162
162
|
result.success? #=> false
|
163
|
-
result["contract.default"].errors.messages
|
163
|
+
result[:"contract.default"].errors.messages
|
164
164
|
#=> {:title=>["is too short (minimum is 2 characters)"], :length=>["is not a number"]}
|
165
165
|
#:constant-result end
|
166
166
|
|
@@ -181,7 +181,7 @@ class ContractConstantTest < Minitest::Spec
|
|
181
181
|
#:constant-new end
|
182
182
|
|
183
183
|
it { Song::New.(params: {}).inspect(:model).must_equal %{<Result:true [#<struct ContractConstantTest::Song title=nil, length=nil>] >} }
|
184
|
-
it { Song::New.(params: {})["contract.default"].model.inspect.must_equal %{#<struct ContractConstantTest::Song title=nil, length=nil>} }
|
184
|
+
it { Song::New.(params: {})[:"contract.default"].model.inspect.must_equal %{#<struct ContractConstantTest::Song title=nil, length=nil>} }
|
185
185
|
it do
|
186
186
|
#:constant-new-result
|
187
187
|
result = Song::New.(params: {})
|
@@ -218,8 +218,8 @@ class ContractConstantTest < Minitest::Spec
|
|
218
218
|
result = Song::ValidateOnly.(params: { title: "Rising Force", length: 13 })
|
219
219
|
|
220
220
|
result.success? #=> true
|
221
|
-
result[
|
222
|
-
result["contract.default"].title #=> "Rising Force"
|
221
|
+
result[:model] #=> #<struct Song title=nil, length=nil>
|
222
|
+
result[:"contract.default"].title #=> "Rising Force"
|
223
223
|
#:validate-only-result end
|
224
224
|
end
|
225
225
|
end
|
@@ -297,6 +297,46 @@ class DocsContractKeyWithOutputTest < Minitest::Spec
|
|
297
297
|
end
|
298
298
|
end
|
299
299
|
|
300
|
+
#---
|
301
|
+
#- Validate( name: "default", invalid_data_terminus: true )
|
302
|
+
class DocsContractInvalidEndTest < Minitest::Spec
|
303
|
+
Song = Class.new(ContractConstantTest::Song)
|
304
|
+
|
305
|
+
module Song::Contract
|
306
|
+
Create = ContractConstantTest::Song::Contract::Create
|
307
|
+
end
|
308
|
+
|
309
|
+
#:invalid-end
|
310
|
+
class Song::Create < Trailblazer::Operation
|
311
|
+
step Model( Song, :new )
|
312
|
+
step Contract::Build( constant: Song::Contract::Create )
|
313
|
+
step Contract::Validate( key: :song, invalid_data_terminus: true )
|
314
|
+
step Contract::Persist( )
|
315
|
+
end
|
316
|
+
#:invalid-end end
|
317
|
+
|
318
|
+
it do
|
319
|
+
result = Song::Create.(params: {song: { title: nil, length: nil }})
|
320
|
+
result.event.inspect.must_equal %{#<Trailblazer::Activity::End semantic=:invalid_data>}
|
321
|
+
end
|
322
|
+
|
323
|
+
it { Song::Create.(params: {song: { title: "SVG", length: 13 }}).inspect(:model).must_equal %{<Result:true [#<struct DocsContractInvalidEndTest::Song title=\"SVG\", length=13>] >} }
|
324
|
+
|
325
|
+
it do
|
326
|
+
#:invalid-end-res
|
327
|
+
result = Song::Create.(params: { title: "Rising Force", length: 13 })
|
328
|
+
result.success? #=> false
|
329
|
+
result.event #=> #<Trailblazer::Activity::End semantic=:"contract.default.invalid">
|
330
|
+
#:invalid-end-res end
|
331
|
+
|
332
|
+
#:invalid-end-res-false
|
333
|
+
result = Song::Create.(params: { "song" => { title: "Rising Force", length: 13 } })
|
334
|
+
result.success? #=> true
|
335
|
+
#:invalid-end-res-false end
|
336
|
+
end
|
337
|
+
end
|
338
|
+
|
339
|
+
|
300
340
|
#- Contract::Build[ constant: XXX, name: AAA ]
|
301
341
|
class ContractNamedConstantTest < Minitest::Spec
|
302
342
|
Song = Class.new(ContractConstantTest::Song)
|
@@ -320,7 +360,7 @@ class ContractNamedConstantTest < Minitest::Spec
|
|
320
360
|
it do
|
321
361
|
#:name-res
|
322
362
|
result = Song::Create.(params: { title: "A" })
|
323
|
-
result["contract.form"].errors.messages #=> {:title=>["is too short (minimum is 2 ch...
|
363
|
+
result[:"contract.form"].errors.messages #=> {:title=>["is too short (minimum is 2 ch...
|
324
364
|
#:name-res end
|
325
365
|
end
|
326
366
|
end
|
@@ -349,12 +389,12 @@ class ContractInjectConstantTest < Minitest::Spec
|
|
349
389
|
#:di-contract-call
|
350
390
|
Create.(
|
351
391
|
params: { title: "Anthony's Song" },
|
352
|
-
"contract.default.class" => MyContract
|
392
|
+
:"contract.default.class" => MyContract
|
353
393
|
)
|
354
394
|
#:di-contract-call end
|
355
395
|
end
|
356
|
-
it { Create.(params: { title: "A" }, "contract.default.class" => MyContract).inspect(:model).must_equal %{<Result:false [#<struct ContractInjectConstantTest::Song id=nil, title=nil>] >} }
|
357
|
-
it { Create.(params: { title: "Anthony's Song" }, "contract.default.class" => MyContract).inspect(:model).must_equal %{<Result:true [#<struct ContractInjectConstantTest::Song id=nil, title="Anthony's Song">] >} }
|
396
|
+
it { Create.(params: { title: "A" }, :"contract.default.class" => MyContract).inspect(:model).must_equal %{<Result:false [#<struct ContractInjectConstantTest::Song id=nil, title=nil>] >} }
|
397
|
+
it { Create.(params: { title: "Anthony's Song" }, :"contract.default.class" => MyContract).inspect(:model).must_equal %{<Result:true [#<struct ContractInjectConstantTest::Song id=nil, title="Anthony's Song">] >} }
|
358
398
|
end
|
359
399
|
|
360
400
|
class DryValidationContractTest < Minitest::Spec
|
@@ -367,16 +407,20 @@ class DryValidationContractTest < Minitest::Spec
|
|
367
407
|
class Create < Trailblazer::Operation
|
368
408
|
# contract to verify params formally.
|
369
409
|
class MyContract < Reform::Form
|
370
|
-
feature
|
410
|
+
feature Dry
|
371
411
|
property :id
|
372
412
|
property :title
|
373
413
|
|
374
414
|
validation name: :default do
|
375
|
-
|
415
|
+
params do
|
416
|
+
required(:id).filled
|
417
|
+
end
|
376
418
|
end
|
377
419
|
|
378
420
|
validation name: :extra, if: :default do
|
379
|
-
|
421
|
+
params do
|
422
|
+
required(:title).filled(min_size?: 2)
|
423
|
+
end
|
380
424
|
end
|
381
425
|
end
|
382
426
|
#~form end
|
@@ -389,14 +433,14 @@ class DryValidationContractTest < Minitest::Spec
|
|
389
433
|
end
|
390
434
|
#:dry-schema end
|
391
435
|
|
392
|
-
puts "@@@@@ #{Trailblazer::
|
436
|
+
puts "@@@@@ #{Trailblazer::Developer.railway(Create, style: :rows)}"
|
393
437
|
|
394
|
-
it { Create.(params: {}).inspect("result.contract.default").must_include "Result:false"}
|
395
|
-
it { Create.(params: {}).inspect("result.contract.default").must_include "
|
438
|
+
it { Create.(params: {}).inspect(:"result.contract.default").must_include "Result:false"}
|
439
|
+
it { Create.(params: {}).inspect(:"result.contract.default").must_include "errors={:id=>[\"must be filled\""}
|
396
440
|
|
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 "
|
399
|
-
it { Create.(params: { id: 1 }).inspect(:model, "result.contract.default").wont_include ":id=>[\"must be filled\""}
|
441
|
+
it { Create.(params: { id: 1 }).inspect(:model, :"result.contract.default").must_include "Result:false"}
|
442
|
+
it { Create.(params: { id: 1 }).inspect(:model, :"result.contract.default").must_include "errors={:title=>[\"must be filled\", \"size cannot be less than 2\"]}"}
|
443
|
+
it { Create.(params: { id: 1 }).inspect(:model, :"result.contract.default").wont_include ":id=>[\"must be filled\""}
|
400
444
|
|
401
445
|
it { Create.(params: { id: 1, title: "" }).inspect(:model).must_equal %{<Result:false [#<struct DryValidationContractTest::Song id=nil, title=nil>] >} }
|
402
446
|
it { Create.(params: { id: 1, title: "Y" }).inspect(:model).must_equal %{<Result:false [#<struct DryValidationContractTest::Song id=nil, title=nil>] >} }
|
@@ -405,8 +449,10 @@ class DryValidationContractTest < Minitest::Spec
|
|
405
449
|
#---
|
406
450
|
# Contract::Validate(constant: DrySchema)
|
407
451
|
class OpWithSchema < Trailblazer::Operation
|
408
|
-
Schema = Dry::Validation.
|
409
|
-
|
452
|
+
Schema = Dry::Validation.Contract do
|
453
|
+
params do
|
454
|
+
required(:title).filled
|
455
|
+
end
|
410
456
|
end
|
411
457
|
|
412
458
|
step Model( Song, :new ) # FIXME.
|
@@ -420,7 +466,7 @@ class DryValidationContractTest < Minitest::Spec
|
|
420
466
|
it "shows error messages" do
|
421
467
|
result = OpWithSchema.(params: {song: { title: nil }})
|
422
468
|
|
423
|
-
result["result.contract.default"].errors.must_equal
|
469
|
+
result[:"result.contract.default"].errors.inspect.must_equal %{#<Dry::Validation::MessageSet messages=[#<Dry::Schema::Message text=\"must be filled\" path=[:title] predicate=:filled? input=nil>] options={:source=>[#<Dry::Schema::Message text=\"must be filled\" path=[:title] predicate=:filled? input=nil>], :hints=>false}>}
|
424
470
|
end
|
425
471
|
# key not found
|
426
472
|
it { OpWithSchema.(params: {}).success?.must_equal false }
|
data/test/docs/dry_test.rb
CHANGED
@@ -1,31 +1,33 @@
|
|
1
|
-
require "test_helper"
|
2
|
-
require "dry/container"
|
1
|
+
# require "test_helper"
|
2
|
+
# require "dry/container"
|
3
3
|
|
4
|
-
class DryContainerTest < Minitest::Spec
|
5
|
-
|
4
|
+
# class DryContainerTest < Minitest::Spec
|
5
|
+
# Song = Struct.new(:id, :title)
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
7
|
+
# class MyContract < Reform::Form
|
8
|
+
# property :title
|
9
|
+
# validates :title, length: 2..33
|
10
|
+
# end
|
11
11
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
12
|
+
# my_container = Dry::Container.new
|
13
|
+
# my_container.register("contract.default.class", MyContract)
|
14
|
+
# # my_container.namespace("contract") do
|
15
|
+
# # register("create") { Array }
|
16
|
+
# # end
|
17
17
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
step Contract::Build()
|
24
|
-
step Contract::Validate()
|
25
|
-
step Contract::Persist( method: :sync )
|
26
|
-
end
|
27
|
-
#:key end
|
18
|
+
# #---
|
19
|
+
# #- dependency injection
|
20
|
+
# #- with Dry-container
|
21
|
+
# class Create < Trailblazer::Operation
|
22
|
+
# extend Trailblazer::Operation::Container
|
28
23
|
|
29
|
-
|
30
|
-
|
31
|
-
|
24
|
+
# step Model(Song, :new)
|
25
|
+
# step Contract::Build()
|
26
|
+
# step Contract::Validate()
|
27
|
+
# step Contract::Persist(method: :sync)
|
28
|
+
# end
|
29
|
+
# #:key end
|
30
|
+
|
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">] >} }
|
33
|
+
# end
|
@@ -26,16 +26,16 @@ class ContractTest < Minitest::Spec
|
|
26
26
|
it do
|
27
27
|
result = Update.(params: {title: "SVG"})
|
28
28
|
result.success?.must_equal true
|
29
|
-
result["result.contract.default"].success?.must_equal true
|
30
|
-
result["result.contract.default"].errors.messages.must_equal({})
|
29
|
+
result[:"result.contract.default"].success?.must_equal true
|
30
|
+
result[:"result.contract.default"].errors.messages.must_equal({})
|
31
31
|
end
|
32
32
|
|
33
33
|
# failure
|
34
34
|
it do
|
35
35
|
result = Update.(params: {title: nil})
|
36
36
|
result.success?.must_equal false
|
37
|
-
result["result.contract.default"].success?.must_equal false
|
38
|
-
result["result.contract.default"].errors.messages.must_equal({:title=>["can't be blank"]})
|
37
|
+
result[:"result.contract.default"].success?.must_equal false
|
38
|
+
result[:"result.contract.default"].errors.messages.must_equal({:title=>["can't be blank"]})
|
39
39
|
end
|
40
40
|
|
41
41
|
#---
|
@@ -59,25 +59,27 @@ class ContractTest < Minitest::Spec
|
|
59
59
|
it { Upsert.(params: {song: { title: nil }}).success?.must_equal false }
|
60
60
|
# key not found
|
61
61
|
it { Upsert.(params: {}).success?.must_equal false }
|
62
|
+
# no params passed
|
63
|
+
it { Upsert.().success?.must_equal false }
|
62
64
|
|
63
65
|
#---
|
64
66
|
# contract.default.params gets set (TODO: change in 2.1)
|
65
67
|
it { Upsert.( params: {song: { title: "SVG" }})[:params].must_equal({:song=>{:title=>"SVG"}} ) }
|
66
|
-
it { Upsert.( params: {song: { title: "SVG" }})["contract.default.params"].must_equal({:title=>"SVG"} ) }
|
68
|
+
it { Upsert.( params: {song: { title: "SVG" }})[:"contract.default.params"].must_equal({:title=>"SVG"} ) }
|
67
69
|
|
68
70
|
#---
|
69
71
|
#- inheritance
|
70
72
|
class New < Upsert
|
71
73
|
end
|
72
74
|
|
73
|
-
it { Trailblazer::
|
75
|
+
it { Trailblazer::Developer.railway(New).must_equal %{[>model.build,>contract.build,>contract.default.validate,>persist.save]} }
|
74
76
|
|
75
77
|
#- overwriting Validate
|
76
78
|
class NewHit < Upsert
|
77
79
|
step Contract::Validate( key: :hit ), override: true
|
78
80
|
end
|
79
81
|
|
80
|
-
it { Trailblazer::
|
82
|
+
it { Trailblazer::Developer.railway(NewHit).must_equal %{[>model.build,>contract.build,>contract.default.validate,>persist.save]} }
|
81
83
|
it { NewHit.(params: {:hit => { title: "Hooray For Me" }}).inspect(:model).must_equal %{<Result:true [#<struct ContractTest::Song title=\"Hooray For Me\">] >} }
|
82
84
|
end
|
83
85
|
end
|
@@ -42,10 +42,10 @@ class PersistTest < Minitest::Spec
|
|
42
42
|
class Update < Create
|
43
43
|
end
|
44
44
|
|
45
|
-
it { Trailblazer::
|
45
|
+
it { Trailblazer::Developer.railway(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
|
49
49
|
skip "show how save! could be applied and how we could rescue and deviate to left track"
|
50
50
|
end
|
51
|
-
end
|
51
|
+
end
|
data/test/test_helper.rb
CHANGED
@@ -1,7 +1,11 @@
|
|
1
|
+
$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
|
2
|
+
require "trailblazer-macro-contract"
|
3
|
+
|
1
4
|
require "pp"
|
2
5
|
require 'delegate'
|
6
|
+
require "trailblazer/operation"
|
7
|
+
require "trailblazer/developer"
|
3
8
|
require "trailblazer/macro"
|
4
|
-
require "trailblazer-macro-contract"
|
5
9
|
require "minitest/autorun"
|
6
10
|
|
7
11
|
# TODO: convert tests to non-rails.
|
@@ -4,13 +4,13 @@ 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
|
-
spec.description = '
|
11
|
-
spec.summary = 'Macros for form
|
10
|
+
spec.description = 'Operation macros for form objects'
|
11
|
+
spec.summary = 'Macros for form objects: Build, Validate, Persist'
|
12
12
|
spec.homepage = "http://trailblazer.to"
|
13
|
-
spec.license = "
|
13
|
+
spec.license = "LGPL-3.0"
|
14
14
|
|
15
15
|
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
16
16
|
f.match(%r{^test/})
|
@@ -21,12 +21,17 @@ 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 "trailblazer-macro", ">= 2.1.0.rc1", "< 2.2.0"
|
25
|
-
spec.add_development_dependency "reform-rails"
|
26
24
|
spec.add_development_dependency "dry-validation"
|
25
|
+
spec.add_development_dependency "reform-rails", "~> 0.2.0.rc2"
|
26
|
+
spec.add_development_dependency "trailblazer-operation", ">= 0.6.2"
|
27
|
+
spec.add_development_dependency "trailblazer-macro", ">= 2.1.5"
|
28
|
+
spec.add_development_dependency "trailblazer-developer"
|
29
|
+
spec.add_development_dependency "activemodel", "~> 6.0.0" # FIXME: we still don't support the Rails 6.1 errors object.
|
27
30
|
|
28
31
|
spec.add_development_dependency "minitest"
|
29
32
|
spec.add_development_dependency "rake"
|
30
33
|
|
31
|
-
spec.
|
34
|
+
spec.add_dependency "trailblazer-activity-dsl-linear", ">= 0.4.0", "< 0.5.0"
|
35
|
+
|
36
|
+
spec.required_ruby_version = ">= 2.0.0"
|
32
37
|
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.
|
4
|
+
version: 2.1.1
|
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: 2021-03-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: reform
|
@@ -45,41 +45,63 @@ 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
|
-
|
53
|
+
version: '0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
55
59
|
- !ruby/object:Gem::Version
|
56
|
-
version:
|
60
|
+
version: '0'
|
61
|
+
- !ruby/object:Gem::Dependency
|
62
|
+
name: reform-rails
|
63
|
+
requirement: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - "~>"
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: 0.2.0.rc2
|
57
68
|
type: :development
|
58
69
|
prerelease: false
|
59
70
|
version_requirements: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - "~>"
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: 0.2.0.rc2
|
75
|
+
- !ruby/object:Gem::Dependency
|
76
|
+
name: trailblazer-operation
|
77
|
+
requirement: !ruby/object:Gem::Requirement
|
60
78
|
requirements:
|
61
79
|
- - ">="
|
62
80
|
- !ruby/object:Gem::Version
|
63
|
-
version:
|
64
|
-
|
81
|
+
version: 0.6.2
|
82
|
+
type: :development
|
83
|
+
prerelease: false
|
84
|
+
version_requirements: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - ">="
|
65
87
|
- !ruby/object:Gem::Version
|
66
|
-
version:
|
88
|
+
version: 0.6.2
|
67
89
|
- !ruby/object:Gem::Dependency
|
68
|
-
name:
|
90
|
+
name: trailblazer-macro
|
69
91
|
requirement: !ruby/object:Gem::Requirement
|
70
92
|
requirements:
|
71
93
|
- - ">="
|
72
94
|
- !ruby/object:Gem::Version
|
73
|
-
version:
|
95
|
+
version: 2.1.5
|
74
96
|
type: :development
|
75
97
|
prerelease: false
|
76
98
|
version_requirements: !ruby/object:Gem::Requirement
|
77
99
|
requirements:
|
78
100
|
- - ">="
|
79
101
|
- !ruby/object:Gem::Version
|
80
|
-
version:
|
102
|
+
version: 2.1.5
|
81
103
|
- !ruby/object:Gem::Dependency
|
82
|
-
name:
|
104
|
+
name: trailblazer-developer
|
83
105
|
requirement: !ruby/object:Gem::Requirement
|
84
106
|
requirements:
|
85
107
|
- - ">="
|
@@ -92,6 +114,20 @@ dependencies:
|
|
92
114
|
- - ">="
|
93
115
|
- !ruby/object:Gem::Version
|
94
116
|
version: '0'
|
117
|
+
- !ruby/object:Gem::Dependency
|
118
|
+
name: activemodel
|
119
|
+
requirement: !ruby/object:Gem::Requirement
|
120
|
+
requirements:
|
121
|
+
- - "~>"
|
122
|
+
- !ruby/object:Gem::Version
|
123
|
+
version: 6.0.0
|
124
|
+
type: :development
|
125
|
+
prerelease: false
|
126
|
+
version_requirements: !ruby/object:Gem::Requirement
|
127
|
+
requirements:
|
128
|
+
- - "~>"
|
129
|
+
- !ruby/object:Gem::Version
|
130
|
+
version: 6.0.0
|
95
131
|
- !ruby/object:Gem::Dependency
|
96
132
|
name: minitest
|
97
133
|
requirement: !ruby/object:Gem::Requirement
|
@@ -120,7 +156,27 @@ dependencies:
|
|
120
156
|
- - ">="
|
121
157
|
- !ruby/object:Gem::Version
|
122
158
|
version: '0'
|
123
|
-
|
159
|
+
- !ruby/object:Gem::Dependency
|
160
|
+
name: trailblazer-activity-dsl-linear
|
161
|
+
requirement: !ruby/object:Gem::Requirement
|
162
|
+
requirements:
|
163
|
+
- - ">="
|
164
|
+
- !ruby/object:Gem::Version
|
165
|
+
version: 0.4.0
|
166
|
+
- - "<"
|
167
|
+
- !ruby/object:Gem::Version
|
168
|
+
version: 0.5.0
|
169
|
+
type: :runtime
|
170
|
+
prerelease: false
|
171
|
+
version_requirements: !ruby/object:Gem::Requirement
|
172
|
+
requirements:
|
173
|
+
- - ">="
|
174
|
+
- !ruby/object:Gem::Version
|
175
|
+
version: 0.4.0
|
176
|
+
- - "<"
|
177
|
+
- !ruby/object:Gem::Version
|
178
|
+
version: 0.5.0
|
179
|
+
description: Operation macros for form objects
|
124
180
|
email:
|
125
181
|
- apotonick@gmail.com
|
126
182
|
executables: []
|
@@ -128,21 +184,22 @@ extensions: []
|
|
128
184
|
extra_rdoc_files: []
|
129
185
|
files:
|
130
186
|
- ".gitignore"
|
187
|
+
- ".rubocop-https---raw-githubusercontent-com-trailblazer-meta-master-rubocop-yml"
|
131
188
|
- ".rubocop.yml"
|
132
189
|
- ".rubocop_todo.yml"
|
133
190
|
- ".travis.yml"
|
134
191
|
- CHANGES.md
|
135
192
|
- COMM-LICENSE
|
136
193
|
- Gemfile
|
137
|
-
- LICENSE
|
194
|
+
- LICENSE
|
138
195
|
- README.md
|
139
196
|
- Rakefile
|
140
197
|
- lib/trailblazer-macro-contract.rb
|
141
198
|
- lib/trailblazer/macro/contract.rb
|
199
|
+
- lib/trailblazer/macro/contract/build.rb
|
200
|
+
- lib/trailblazer/macro/contract/persist.rb
|
201
|
+
- lib/trailblazer/macro/contract/validate.rb
|
142
202
|
- lib/trailblazer/macro/contract/version.rb
|
143
|
-
- lib/trailblazer/operation/contract.rb
|
144
|
-
- lib/trailblazer/operation/persist.rb
|
145
|
-
- lib/trailblazer/operation/validate.rb
|
146
203
|
- test/docs/contract_test.rb
|
147
204
|
- test/docs/dry_test.rb
|
148
205
|
- test/operation/contract_test.rb
|
@@ -151,7 +208,7 @@ files:
|
|
151
208
|
- trailblazer-macro-contract.gemspec
|
152
209
|
homepage: http://trailblazer.to
|
153
210
|
licenses:
|
154
|
-
-
|
211
|
+
- LGPL-3.0
|
155
212
|
metadata: {}
|
156
213
|
post_install_message:
|
157
214
|
rdoc_options: []
|
@@ -164,15 +221,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
164
221
|
version: 2.0.0
|
165
222
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
166
223
|
requirements:
|
167
|
-
- - "
|
224
|
+
- - ">="
|
168
225
|
- !ruby/object:Gem::Version
|
169
|
-
version:
|
226
|
+
version: '0'
|
170
227
|
requirements: []
|
171
|
-
|
172
|
-
rubygems_version: 2.7.3
|
228
|
+
rubygems_version: 3.2.3
|
173
229
|
signing_key:
|
174
230
|
specification_version: 4
|
175
|
-
summary: 'Macros for form
|
231
|
+
summary: 'Macros for form objects: Build, Validate, Persist'
|
176
232
|
test_files:
|
177
233
|
- test/docs/contract_test.rb
|
178
234
|
- test/docs/dry_test.rb
|
data/LICENSE.txt
DELETED
@@ -1,27 +0,0 @@
|
|
1
|
-
The MIT License (MIT)
|
2
|
-
|
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
|
-
---------
|
24
|
-
|
25
|
-
Trailblazer Enterprise has a commercial-friendly license allowing private forks
|
26
|
-
and modifications of Trailblazer. Please see http://trailblazer.to/enterprise/ for
|
27
|
-
more detail.
|