trailblazer-macro-contract 2.1.2 → 2.1.3.beta1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 88187712c7881802a2e78f5b21107505d78cb3a7fec0727503f92b02d6064115
4
- data.tar.gz: 4a661ef7c3041fe6abad2222f913e32d86ee705e5c33d13496dd12f067520ee7
3
+ metadata.gz: c9c3c0092a4bd1f8b71d4506ed24e77af326b28d2991a88bdb45d67586dad746
4
+ data.tar.gz: 6de99c14b4bc553a0e32e568a9c31a74abf839f0d82f36dac33884300d979777
5
5
  SHA512:
6
- metadata.gz: 929fe8f1bc30baacfea1e0b256bd73f3c522593ffac98c44ff02ebea3a93c9e4e871b2fc426502e98c71f5b0909f04cbc4d2863136da000eec0197b06db83911
7
- data.tar.gz: b348716b5567c9288b1909282c9c058c53fb775650cff6b10ed19eb6ad7dac179f379508012fa7ce50dca6f67ca671397d8cb9d546551a0ff07d4d4b35341fca
6
+ metadata.gz: 15de139140c545de9ab6d1b6d19a83053815b78b7e4ae990a9b5a57dea89e77566524d2eb84326694f5399f41d3d7f367a761572badf465fdaa58cd32c2e1a79
7
+ data.tar.gz: 4b9fc7eb3a4f30a7f57f2ec95c6b0459ad5ccff8e4adbfd3ddc324570d8647b1046277e61f7f1b402bbbb663e28fbe3b1161d649db5036e74c91da66b9e6b8c1
@@ -6,7 +6,7 @@ jobs:
6
6
  fail-fast: false
7
7
  matrix:
8
8
  # Due to https://github.com/actions/runner/issues/849, we have to use quotes for '3.0'
9
- ruby: [2.5, 2.6, 2.7, '3.0', head, jruby, jruby-head]
9
+ ruby: [2.6, 2.7, '3.0', jruby]
10
10
  runs-on: ubuntu-latest
11
11
  steps:
12
12
  - uses: actions/checkout@v2
data/CHANGES.md CHANGED
@@ -1,3 +1,8 @@
1
+ # 2.1.3
2
+
3
+ * Use `trailblazer-activity-dsl-linear` >= 1.0.0.
4
+ * Use Inject() API instead of `:inject`, `:input` etc in macros.
5
+
1
6
  # 2.1.2
2
7
 
3
8
  * Refactor `Contract::Build` to use TRB mechanics:
data/Gemfile CHANGED
@@ -9,6 +9,8 @@ gem "dry-matcher"
9
9
  # gem "trailblazer-macro", path: "../trailblazer-macro"
10
10
  # gem "trailblazer-activity", path: "../trailblazer-activity"
11
11
  # gem "trailblazer-activity-dsl-linear", path: "../trailblazer-activity-dsl-linear"
12
+ # gem "trailblazer-errors", path: "../trailblazer-errors"
13
+ # gem "trailblazer-developer", path: "../trailblazer-developer"
12
14
 
13
15
  gem "minitest-line"
14
16
 
@@ -22,14 +22,25 @@ module Trailblazer
22
22
  def self.Build(name: "default", constant: nil, builder: nil)
23
23
  contract_path = :"contract.#{name}"
24
24
 
25
- build_injections = {"#{contract_path}.class": ->(*) { constant }} # default to {constant} if not injected.
25
+ injections = {
26
+ Activity::Railway.Inject() => {
27
+ "#{contract_path}.class": ->(*) { constant }, # default to {constant} if not injected.
28
+ }
29
+ }
26
30
 
27
- input = ->(ctx, **) do
28
- ctx.to_hash.merge(
29
- constant: constant,
30
- name: contract_path
31
- )
32
- end
31
+ # DISCUSS: can we force-default this via Inject()?
32
+ input = {
33
+ Activity::Railway.In() => ->(ctx, **) do
34
+ ctx.to_hash.merge(
35
+ constant: constant,
36
+ name: contract_path
37
+ )
38
+ end
39
+ }
40
+
41
+ output = {
42
+ Activity::Railway.Out() => [contract_path]
43
+ }
33
44
 
34
45
  default_contract_builder = ->(ctx, model: nil, **) { ctx[:"#{contract_path}.class"].new(model) }
35
46
 
@@ -43,10 +54,10 @@ module Trailblazer
43
54
 
44
55
  {
45
56
  task: task, id: "contract.build",
46
- inject: [build_injections],
47
- input: input,
48
- output: [contract_path]
49
- }
57
+ }.
58
+ merge(injections).
59
+ merge(input).
60
+ merge(output)
50
61
  end
51
62
 
52
63
  module DSL
@@ -20,8 +20,8 @@ module Trailblazer
20
20
 
21
21
  # Build a simple Railway {Activity} for the internal flow.
22
22
  activity = Class.new(Activity::Railway(name: "Contract::Validate")) do
23
- step extract, id: "#{params_path}_extract", Output(:failure) => End(:extract_failure), inject: [extract_injections] unless skip_extract# || representer
24
- step validate, id: "contract.#{name}.call", inject: [validate_injections]
23
+ step extract, id: "#{params_path}_extract", Output(:failure) => End(:extract_failure), Activity::Railway.Inject() => extract_injections unless skip_extract# || representer
24
+ step validate, id: "contract.#{name}.call", Activity::Railway.Inject() => validate_injections
25
25
  end
26
26
 
27
27
  options = activity.Subprocess(activity)
@@ -2,7 +2,7 @@ module Trailblazer
2
2
  module Version
3
3
  module Macro
4
4
  module Contract
5
- VERSION = "2.1.2"
5
+ VERSION = "2.1.3.beta1"
6
6
  end
7
7
  end
8
8
  end
@@ -13,7 +13,5 @@ module Trailblazer
13
13
 
14
14
  # All macros sit in the {Trailblazer::Macro::Contract} namespace, where we forward calls from
15
15
  # operations and activities to.
16
- module Activity::DSL::Linear::Helper
17
- Contract = Macro::Contract
18
- end
16
+ Activity::DSL::Linear::Helper::Constants::Contract = Macro::Contract
19
17
  end
@@ -294,7 +294,7 @@ class DocsContractInjectedKeyTest < Minitest::Spec
294
294
  "contract.default.extract_key": "song"
295
295
  )
296
296
  #:inject-key-call end
297
- .inspect(:model).must_equal %{<Result:true [#<struct DocsContractInjectedKeyTest::Song title=\"SVG\", length=13>] >} }
297
+ res.inspect(:model).must_equal %{<Result:true [#<struct DocsContractInjectedKeyTest::Song title=\"SVG\", length=13>] >} }
298
298
  end
299
299
 
300
300
  #---
@@ -517,30 +517,47 @@ class DryValidationContractTest < Minitest::Spec
517
517
  it { Create.(params: { id: 1, title: "Y" }).inspect(:model).must_equal %{<Result:false [#<struct DryValidationContractTest::Song id=nil, title=nil>] >} }
518
518
  it { Create.(params: { id: 1, title: "Yo" }).inspect(:model).must_equal %{<Result:true [#<struct DryValidationContractTest::Song id=1, title="Yo">] >} }
519
519
 
520
- #---
520
+ ##---
521
521
  # Contract::Validate(constant: DrySchema)
522
- class OpWithSchema < Trailblazer::Operation
523
- Schema = Dry::Validation.Contract do
524
- params do
525
- required(:title).filled
522
+
523
+ #:dry-schema-contract
524
+ module Song::Operation
525
+ class Archive < Trailblazer::Operation
526
+ Schema = Dry::Validation.Contract do
527
+ params do
528
+ required(:id).filled
529
+ end
526
530
  end
527
- end
528
531
 
529
- step Model( Song, :new ) # FIXME.
530
- step Contract::Validate( constant: Schema, key: :song) # generic validate call for you.
532
+ # step Model(Song, :new) # You don't need {ctx[:model]}.
533
+ step Contract::Validate(constant: Schema, key: :song) # Your validation.
534
+ #~methods
535
+ # step Contract::Persist() # this is not possible!
536
+ #~methods end
537
+ end
531
538
  end
539
+ #:dry-schema-contract end
532
540
 
533
541
  # success
534
- it { OpWithSchema.(params: {song: { title: "SVG" }}).success?.must_equal true }
542
+ it { _(Song::Operation::Archive.(params: {song: {id: "SVG"}}).success?).must_equal true }
535
543
  # failure
536
- it { OpWithSchema.(params: {song: { title: nil }}).success?.must_equal false }
544
+ it { _(Song::Operation::Archive.(params: {song: {id: nil}}).success?).must_equal false }
545
+ # shows error messages
537
546
  it "shows error messages" do
538
- result = OpWithSchema.(params: {song: { title: nil }})
547
+ #:dry-contract-call
548
+ result = Song::Operation::Archive.(params: {song: {id: nil}})
549
+ #:dry-contract-call end
550
+
551
+ _(result[:"result.contract.default"].errors.inspect).must_equal %{#<Dry::Validation::MessageSet messages=[#<Dry::Schema::Message text=\"must be filled\" path=[:id] predicate=:filled? input=nil>] options={:source=>[#<Dry::Schema::Message text=\"must be filled\" path=[:id] predicate=:filled? input=nil>], :hints=>false}>}
539
552
 
540
- 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}>}
553
+ # raise result[:"result.contract.default"].errors.messages[0].to_s.inspect
554
+ assert_equal result[:"result.contract.default"].errors[:id].inspect, %{["must be filled"]}
555
+ #:dry-contract-result
556
+ result[:"result.contract.default"].errors[:id] #=> ["must be filled"]
557
+ #:dry-contract-result end
541
558
  end
542
559
  # key not found
543
- it { OpWithSchema.(params: {}).success?.must_equal false }
560
+ it { _(Song::Operation::Archive.(params: {}).success?).must_equal false }
544
561
  end
545
562
 
546
563
  class DocContractBuilderTest < Minitest::Spec
@@ -30,7 +30,7 @@ Gem::Specification.new do |spec|
30
30
  spec.add_development_dependency "minitest"
31
31
  spec.add_development_dependency "rake"
32
32
 
33
- spec.add_dependency "trailblazer-activity-dsl-linear", ">= 0.5.0", "< 0.6.0"
33
+ spec.add_dependency "trailblazer-activity-dsl-linear", ">= 1.0.0.beta1", "< 1.1.0"
34
34
 
35
35
  spec.required_ruby_version = ">= 2.0.0"
36
36
  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.2
4
+ version: 2.1.3.beta1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nick Sutterer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-12-13 00:00:00.000000000 Z
11
+ date: 2022-07-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: reform
@@ -148,20 +148,20 @@ dependencies:
148
148
  requirements:
149
149
  - - ">="
150
150
  - !ruby/object:Gem::Version
151
- version: 0.5.0
151
+ version: 1.0.0.beta1
152
152
  - - "<"
153
153
  - !ruby/object:Gem::Version
154
- version: 0.6.0
154
+ version: 1.1.0
155
155
  type: :runtime
156
156
  prerelease: false
157
157
  version_requirements: !ruby/object:Gem::Requirement
158
158
  requirements:
159
159
  - - ">="
160
160
  - !ruby/object:Gem::Version
161
- version: 0.5.0
161
+ version: 1.0.0.beta1
162
162
  - - "<"
163
163
  - !ruby/object:Gem::Version
164
- version: 0.6.0
164
+ version: 1.1.0
165
165
  description: Operation macros for form objects
166
166
  email:
167
167
  - apotonick@gmail.com
@@ -207,9 +207,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
207
207
  version: 2.0.0
208
208
  required_rubygems_version: !ruby/object:Gem::Requirement
209
209
  requirements:
210
- - - ">="
210
+ - - ">"
211
211
  - !ruby/object:Gem::Version
212
- version: '0'
212
+ version: 1.3.1
213
213
  requirements: []
214
214
  rubygems_version: 3.2.3
215
215
  signing_key: