trailblazer-operation 0.0.11 → 0.0.12

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: fa4ab9036f38cd68c0237c2498b0a37445c52d8a
4
- data.tar.gz: c8a30650151fb381614dce92b2babfc40c952b07
3
+ metadata.gz: ea04dd0790a33b1d8ed216bc6c38b2051c8879dd
4
+ data.tar.gz: 5950c507d31e4ae46c90ef9b1b22789bdcb5c87b
5
5
  SHA512:
6
- metadata.gz: e4547a6ac0d1c5cde8319ed1e00f99dde8cacf8801affb7ea0ab892f86fc087ac481416f48528ae8caab3b6e8c8a48701655e4ae22ef7bc0d5d2f2fd589da71f
7
- data.tar.gz: 97148b9ef2c060f48bd23172e8b88d46cbb8dee2954a2935a6458a48155325bb04691a16c189838e46c26d1d3456696ed23dc25590baecd33816ec8e91cc0508
6
+ metadata.gz: 9a0b2ec25620b01f1f3ddef0ef93bae31de3b7df540d7c6048252ab8d3d1ed294ba9744cf751fdeeffdd1771a8cefd05aba100b3f15a1f1b9750e094ef0602dc
7
+ data.tar.gz: bc2d57beb613557e4594dba1734424cb39fa4d49e88247fa9d9d800ca1a7c6d7e3f30157a5a2360f9355adad9214f8af63deebde0a04caec53dc13abfc60e63a
data/.travis.yml CHANGED
@@ -9,7 +9,7 @@ matrix:
9
9
  # gemfile: "test/gemfiles/Gemfile.ruby-2.0"
10
10
  - rvm: 2.1
11
11
  gemfile: Gemfile
12
- - rvm: 2.2.3
12
+ - rvm: 2.2.4
13
13
  gemfile: Gemfile
14
14
  - rvm: 2.3.1
15
15
  gemfile: Gemfile
data/CHANGES.md CHANGED
@@ -1,3 +1,16 @@
1
+ ## 0.0.12
2
+
3
+ * Allow passing tmp options into `KW::Option` that will be merged with `options` and then transformed into kw args, but only locally for the step scope (or wherever you do `Option.()`). The API:
4
+
5
+ ```ruby
6
+ Option::KW.(proc).(input, options, some: "more", ...)
7
+ ```
8
+ Note that `KW::Option` could be massively sped up with simple optimizations.
9
+
10
+ ## 0.0.11
11
+
12
+ * Use `Forwardable` instead of `Uber::Delegates`.
13
+
1
14
  ## 0.0.10
2
15
 
3
16
  * `Flow` is now `Railway`.
@@ -35,19 +35,19 @@ class Trailblazer::Operation
35
35
 
36
36
  # Call the option with keyword arguments. Ruby <= 2.0.
37
37
  class KW < Option
38
- def self.call_proc(proc, input, options)
38
+ def self.call_proc(proc, input, options, tmp_options={})
39
39
  return proc.(options) if proc.arity == 1
40
- proc.(options, **options)
40
+ proc.(options, **options.to_hash(tmp_options))
41
41
  end
42
42
 
43
- def self.call_method(proc, input, options)
43
+ def self.call_method(proc, input, options, tmp_options={})
44
44
  return input.send(proc, options) if input.method(proc).arity == 1 # TODO: remove this
45
- input.send(proc, options, **options)
45
+ input.send(proc, options, **options.to_hash(tmp_options))
46
46
  end
47
47
 
48
- def self.call_callable(callable, input, options)
48
+ def self.call_callable(callable, input, options, tmp_options={})
49
49
  return callable.(options) if callable.method(:call).arity == 1
50
- callable.(options, **options)
50
+ callable.(options, **options.to_hash(tmp_options))
51
51
  end
52
52
  end
53
53
  end
@@ -1,5 +1,5 @@
1
1
  module Trailblazer
2
2
  class Operation
3
- VERSION = "0.0.11"
3
+ VERSION = "0.0.12"
4
4
  end
5
5
  end
@@ -32,15 +32,16 @@ module Trailblazer
32
32
 
33
33
  # Called when Ruby transforms options into kw args, via **options.
34
34
  # TODO: this method has massive potential for speed improvements.
35
- def to_hash
35
+ # The `tmp_options` argument is experimental. It allows adding temporary options
36
+ # to the kw args.
37
+ #:private:
38
+ def to_hash(tmp_options={})
36
39
  {}.tap do |h|
37
- arr = to_runtime_data << to_mutable_data
38
-
40
+ arr = to_runtime_data << to_mutable_data << tmp_options
39
41
 
40
42
  arr.each { |hsh|
41
- hsh.each { |k, v| h[k.to_sym] = v }
43
+ hsh.each { |k, v| h[k.to_sym] = v }
42
44
  }
43
-
44
45
  end
45
46
  end
46
47
 
@@ -18,6 +18,22 @@ class KWBugsTest < Minitest::Spec
18
18
  it { Merchant::New.( {}, { "yo"=> nil } ) }
19
19
  end
20
20
 
21
+ class KWOptionsTest < Minitest::Spec
22
+ X = Trailblazer::Operation::Option::KW.( ->(options, **) { options["x"] = true } )
23
+ Y = Trailblazer::Operation::Option::KW.( ->(options, params:nil, **) { options["y"] = params } )
24
+ Z = Trailblazer::Operation::Option::KW.( ->(options, params:nil, z:nil, **) { options["kw_z"] = z } )
25
+ A = Trailblazer::Operation::Option::KW.( ->(options, params:nil, z:nil, **) { options["options_z"] = options["z"] } )
26
+
27
+ class Create < Trailblazer::Operation
28
+ step [ ->(input, options) { X.(input, options, z: "Z!") }, name: "X" ]
29
+ step [ ->(input, options) { Y.(input, options, z: "Z!") }, name: "Y" ]
30
+ step [ ->(input, options) { Z.(input, options, z: "Z!") }, name: "Z" ]
31
+ step [ ->(input, options) { A.(input, options, z: "Z!") }, name: "A" ]
32
+ end
33
+
34
+ it { Create.({ params: "yo" }, "z" => 1).inspect("x", "y", "kw_z", "options_z").must_equal %{<Result:true [true, {:params=>\"yo\"}, "Z!", 1] >} }
35
+ end
36
+
21
37
 
22
38
  class Ruby200PipetreeTest < Minitest::Spec
23
39
  class Create < Trailblazer::Operation
@@ -18,6 +18,22 @@ class KWBugsTest < Minitest::Spec
18
18
  it { Merchant::New.( {}, { "yo"=> nil } ) }
19
19
  end
20
20
 
21
+ class KWOptionsTest < Minitest::Spec
22
+ X = Trailblazer::Operation::Option::KW.( ->(options, **) { options["x"] = true } )
23
+ Y = Trailblazer::Operation::Option::KW.( ->(options, params:, **) { options["y"] = params } )
24
+ Z = Trailblazer::Operation::Option::KW.( ->(options, params:, z:, **) { options["kw_z"] = z } )
25
+ A = Trailblazer::Operation::Option::KW.( ->(options, params:, z:, **) { options["options_z"] = options["z"] } )
26
+
27
+ class Create < Trailblazer::Operation
28
+ step [ ->(input, options) { X.(input, options, z: "Z!") }, name: "X" ]
29
+ step [ ->(input, options) { Y.(input, options, z: "Z!") }, name: "Y" ]
30
+ step [ ->(input, options) { Z.(input, options, z: "Z!") }, name: "Z" ]
31
+ step [ ->(input, options) { A.(input, options, z: "Z!") }, name: "A" ]
32
+ end
33
+
34
+ it { Create.({ params: "yo" }, "z" => 1).inspect("x", "y", "kw_z", "options_z").must_equal %{<Result:true [true, {:params=>\"yo\"}, "Z!", 1] >} }
35
+ end
36
+
21
37
 
22
38
  class Ruby200PipetreeTest < Minitest::Spec
23
39
  class Create < Trailblazer::Operation
data/test/skill_test.rb CHANGED
@@ -46,12 +46,3 @@ class SkillTest < Minitest::Spec
46
46
  end
47
47
  end
48
48
  end
49
- # resolve: prefer @instance_attrs over competences
50
- # or instace_atrt is competences
51
-
52
- # dependencies = { current_user: Runtime::User..., container: BLA }
53
- # dependencies[:current_user]
54
- # dependencies["user.create.contract"] # delegates to container, somehow.
55
-
56
- # Create.(params, dependencies) # not sure if op should build this runtime dependencies hash or if it comes from outside.
57
-
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: trailblazer-operation
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.11
4
+ version: 0.0.12
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-20 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: uber