trailblazer 2.0.1 → 2.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 22aa58ebd31de1635012c1ef3af5758a7279d99f
4
- data.tar.gz: bb3362c26f6efc71d04d97e156f59e89829aac3d
3
+ metadata.gz: 239150501ea57b15601c6e0a79ea03f383b0a0c8
4
+ data.tar.gz: 8bae46c25cd0f90ca228020c9e0344ddfb0bcaea
5
5
  SHA512:
6
- metadata.gz: 0397f1c22e99920dffedcbd093f2cc2da8300aea8e07cd711b89defdb91a2600639ef304f9c57dafdc7afed4bc2f5d319387ec94a408ca407a23f9842017c381
7
- data.tar.gz: c07b96c34bed66eee22f12477976010ddd9e094b7c0bb7581502abc79004afadf35f8b3d4351e79e1b89aac478c19e15aaef5ab1ebbcaf6434613e6843cba2e0
6
+ metadata.gz: a347bb971628f17168ba9d4ba826939da82d0a5bc536e837bbc97a413e64244526ac65de1be1c3da3e9054a5b2acd98e5481cca542aebca35c272e87af3e7629
7
+ data.tar.gz: a9fd02ed273e2ab581a053b1b3772a1035cef6e2e8f7f9810f0d7d32112c41c335bbae1e928547d4601f66378f59ac30c42a69b2b8ec5f2d07843399867883fa
data/CHANGES.md CHANGED
@@ -1,3 +1,14 @@
1
+ # 2.0.2
2
+
3
+ * Remove `uber` dependency as we use our own `Option::KW` now.
4
+ * In `Contract::Build( builder: )` you now also have access to the `name:` keyword. Note that you need to double-splat in builders.
5
+
6
+ ```ruby
7
+ Contract::Build( builder: ->(options, constant:, **) )
8
+ ```
9
+ Same for `:method` and `Callable`.
10
+ * `Policy::Guard( :method )` now works.
11
+
1
12
  # 2.0.1
2
13
 
3
14
  * Add `fail_fast: true` for `step` and `failure` to short-circuit the pipe. Note that more "eloquent" semantics are coming in `trailblazer-bpmn`.
data/Rakefile CHANGED
@@ -7,7 +7,6 @@ Rake::TestTask.new(:test) do |test|
7
7
  test.libs << 'test'
8
8
  # test.test_files = FileList['test/**/*_test.rb']
9
9
  test_files = FileList[%w{
10
- test/operation/guard_test.rb
11
10
  test/operation/pundit_test.rb
12
11
  test/operation/model_test.rb
13
12
  test/operation/contract_test.rb
@@ -20,10 +20,11 @@ class Trailblazer::Operation
20
20
  # TODO: we could probably clean this up a bit at some point.
21
21
  contract_class = constant || options["contract.#{name}.class"]
22
22
  model = options["model"] # FIXME: model.default
23
+ name = "contract.#{name}"
23
24
 
24
- return options["contract.#{name}"] = Uber::Option[builder].(operation, constant: contract_class, model: model) if builder
25
+ return options[name] = Option::KW.(builder).(operation, options, constant: contract_class, name: name) if builder
25
26
 
26
- options["contract.#{name}"] = contract_class.new(model)
27
+ options[name] = contract_class.new(model)
27
28
  end
28
29
  end
29
30
 
@@ -1,5 +1,4 @@
1
1
  require "trailblazer/operation/policy"
2
- require "uber/option"
3
2
 
4
3
  class Trailblazer::Operation
5
4
  module Policy
@@ -9,11 +8,10 @@ class Trailblazer::Operation
9
8
 
10
9
  module Guard
11
10
  def self.build(callable)
12
- value = Uber::Option[callable]
11
+ value = Option.(callable) # Operation::Option
13
12
 
14
- # call'ing the Uber::Option will run either proc or block.
15
13
  # this gets wrapped in a Operation::Result object.
16
- ->(options) { Result.new( !!value.(options), {} ) }
14
+ ->(input, options) { Result.new( !!value.(input, options), {} ) }
17
15
  end
18
16
  end # Guard
19
17
  end
@@ -10,7 +10,7 @@ class Trailblazer::Operation
10
10
 
11
11
  def call(input, options)
12
12
  condition = options[@path] # this allows dependency injection.
13
- result = condition.(options)
13
+ result = condition.(input, options)
14
14
 
15
15
  options["policy.#{@name}"] = result["policy"] # assign the policy as a skill.
16
16
  options["result.policy.#{@name}"] = result
@@ -16,7 +16,7 @@ class Trailblazer::Operation
16
16
  end
17
17
 
18
18
  # Instantiate the actual policy object, and call it.
19
- def call(options)
19
+ def call(input, options)
20
20
  policy = build_policy(options) # this translates to Pundit interface.
21
21
  result!(policy.send(@action), policy)
22
22
  end
@@ -1,3 +1,3 @@
1
1
  module Trailblazer
2
- VERSION = "2.0.1"
2
+ VERSION = "2.0.2"
3
3
  end
@@ -353,7 +353,7 @@ class DocContractBuilderTest < Minitest::Spec
353
353
  step Contract::Validate()
354
354
  step Contract::Persist( method: :sync )
355
355
 
356
- def default_contract!(constant:, model:)
356
+ def default_contract!(options, constant:, model:, **)
357
357
  constant.new(model, current_user: self["current_user"])
358
358
  end
359
359
  end
@@ -374,8 +374,8 @@ class DocContractBuilderTest < Minitest::Spec
374
374
 
375
375
  step Model( Song, :new )
376
376
  #:builder-proc
377
- step Contract::Build( builder: ->(operation, constant:, model:) {
378
- constant.new(model, current_user: operation["current_user"])
377
+ step Contract::Build( builder: ->(options, constant:, model:, **) {
378
+ constant.new(model, current_user: options["current_user"])
379
379
  })
380
380
  #:builder-proc end
381
381
  step Contract::Validate()
@@ -64,20 +64,21 @@ end
64
64
 
65
65
  #---
66
66
  # with method
67
- # class DocsGuardMethodTest < Minitest::Spec
68
- # #:method
69
- # class Create < Trailblazer::Operation
70
- # step Policy::Guard[ : ]
71
- # step :process
72
- # #~pipe-only
73
- # def process(*); self[:x] = true; end
74
- # #~pipe-only end
75
- # end
76
- # #:method end
77
-
78
- # it { Create.(pass: false)[:x].must_equal nil }
79
- # it { Create.(pass: true)[:x].must_equal true }
80
- # end
67
+ class DocsGuardMethodTest < Minitest::Spec
68
+ #:method
69
+ class Create < Trailblazer::Operation
70
+ step Policy::Guard( :pass? )
71
+ step :process
72
+ #~pipe-only
73
+ def pass?(options, *); options["params"][:pass] end
74
+ def process(*); self["x"] = true; end
75
+ #~pipe-only end
76
+ end
77
+ #:method end
78
+
79
+ it { Create.(pass: false).inspect("x").must_equal %{<Result:false [nil] >} }
80
+ it { Create.(pass: true).inspect("x").must_equal %{<Result:true [true] >} }
81
+ end
81
82
 
82
83
  #---
83
84
  # with name:
@@ -17,8 +17,7 @@ Gem::Specification.new do |spec|
17
17
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
18
  spec.require_paths = ["lib"]
19
19
 
20
- spec.add_dependency "trailblazer-operation", ">= 0.0.10", "< 0.1.0"
21
- spec.add_dependency "uber", ">= 0.1.0", "< 0.2.0"
20
+ spec.add_dependency "trailblazer-operation", ">= 0.0.12", "< 0.1.0"
22
21
  spec.add_dependency "reform", ">= 2.2.0", "< 3.0.0"
23
22
  spec.add_dependency "declarative"
24
23
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: trailblazer
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.1
4
+ version: 2.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nick Sutterer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-01-19 00:00:00.000000000 Z
11
+ date: 2017-01-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: trailblazer-operation
@@ -16,7 +16,7 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 0.0.10
19
+ version: 0.0.12
20
20
  - - "<"
21
21
  - !ruby/object:Gem::Version
22
22
  version: 0.1.0
@@ -26,30 +26,10 @@ dependencies:
26
26
  requirements:
27
27
  - - ">="
28
28
  - !ruby/object:Gem::Version
29
- version: 0.0.10
29
+ version: 0.0.12
30
30
  - - "<"
31
31
  - !ruby/object:Gem::Version
32
32
  version: 0.1.0
33
- - !ruby/object:Gem::Dependency
34
- name: uber
35
- requirement: !ruby/object:Gem::Requirement
36
- requirements:
37
- - - ">="
38
- - !ruby/object:Gem::Version
39
- version: 0.1.0
40
- - - "<"
41
- - !ruby/object:Gem::Version
42
- version: 0.2.0
43
- type: :runtime
44
- prerelease: false
45
- version_requirements: !ruby/object:Gem::Requirement
46
- requirements:
47
- - - ">="
48
- - !ruby/object:Gem::Version
49
- version: 0.1.0
50
- - - "<"
51
- - !ruby/object:Gem::Version
52
- version: 0.2.0
53
33
  - !ruby/object:Gem::Dependency
54
34
  name: reform
55
35
  requirement: !ruby/object:Gem::Requirement
@@ -230,7 +210,6 @@ files:
230
210
  - test/operation/dsl/callback_test.rb
231
211
  - test/operation/dsl/contract_test.rb
232
212
  - test/operation/dsl/representer_test.rb
233
- - test/operation/guard_test.rb
234
213
  - test/operation/model_test.rb
235
214
  - test/operation/params_test.rb
236
215
  - test/operation/persist_test.rb
@@ -291,7 +270,6 @@ test_files:
291
270
  - test/operation/dsl/callback_test.rb
292
271
  - test/operation/dsl/contract_test.rb
293
272
  - test/operation/dsl/representer_test.rb
294
- - test/operation/guard_test.rb
295
273
  - test/operation/model_test.rb
296
274
  - test/operation/params_test.rb
297
275
  - test/operation/persist_test.rb
@@ -1,6 +0,0 @@
1
- require "test_helper"
2
-
3
-
4
-
5
-
6
- # FIXME: what about block passed to ::policy?