trailblazer-circuit 0.0.9 → 0.0.10

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: f95ca61bfed92118f9831c970dd69d6a7295588d
4
- data.tar.gz: 16c1a84d09e530d319f831cf8c381d6f683f71d0
3
+ metadata.gz: e4720cd4250498f880e6d24166a0abaf2bf9281e
4
+ data.tar.gz: de3f4d50b0dc2ac8a68cb5d870723dce2dabc959
5
5
  SHA512:
6
- metadata.gz: 7cd64582812530676cdd18c1389d811b0c2d97e38c4aa11561d427349fe8563fe345cb3ce64232690c9ed8a4aab8237078fa3d893387b21203c2baf35a187b79
7
- data.tar.gz: e26c00db184a221e78d3685e8dcc055afc0fcf044a97a6f4e238273222b00a085f525d0acf76daa6d549225f355e18a8ef7b9107be668c07bdc3cf3a2d36b37e
6
+ metadata.gz: 2afcf342be6a11ffa098eb934d4b938cd4a71cce30843818d6121891b2d0189a70df99ebcf7cb7a9c287b477c6dc455ec78012007b2f0b8c9177270b05ad83eb
7
+ data.tar.gz: 49f4d688f2dc7ca968904d8b949285f0f12855963bbf28c7ce3158a4b2880593ea4fb16c91ebb139cf80c801605fa0a5f779bffeb81619209f49ec8147d2fb2b
data/CHANGES.md CHANGED
@@ -1,3 +1,8 @@
1
+ # 0.0.10
2
+
3
+ * Introduce `Context::ContainerChain` to eventually replace the heavy-weight `Skill` object.
4
+ * Fix a bug in `Option` where wrong args were passed when used without `flow_options`.
5
+
1
6
  # 0.0.9
2
7
 
3
8
  * Fix `Context#[]`, it returned `nil` when it should return `false`.
@@ -127,3 +127,4 @@ require "trailblazer/circuit/present"
127
127
  require "trailblazer/circuit/wrap"
128
128
 
129
129
  require "trailblazer/context"
130
+ require "trailblazer/container_chain"
@@ -1,5 +1,5 @@
1
1
  module Trailblazer
2
2
  class Circuit
3
- VERSION = "0.0.9"
3
+ VERSION = "0.0.10"
4
4
  end
5
5
  end
@@ -0,0 +1,42 @@
1
+ class Trailblazer::Context::ContainerChain # used to be called Resolver.
2
+ # Keeps a list of containers. When looking up a key/value, containers are traversed in
3
+ # the order they were added until key is found.
4
+ #
5
+ # Required Container interface: `#key?`, `#[]`.
6
+ #
7
+ # @note ContainerChain is an immutable data structure, it does not support writing.
8
+ # @param containers Array of <Container> objects (splatted)
9
+ def initialize(*containers)
10
+ @containers = containers
11
+ end
12
+
13
+ # @param name Symbol or String to lookup a value stored in one of the containers.
14
+ def [](name)
15
+ self.class.find(@containers, name)
16
+ end
17
+
18
+ # @private
19
+ def key?(name)
20
+ @containers.find { |container| container.key?(name) }
21
+ end
22
+
23
+ def self.find(containers, name)
24
+ containers.find { |container| container.key?(name) && (return container[name]) }
25
+ end
26
+
27
+
28
+
29
+
30
+
31
+ def to_hash
32
+ # FIXME: dry container, etc?
33
+ @containers.each_with_object({}) { |container, hash| hash.merge!(container.to_hash) }
34
+ end
35
+ end
36
+
37
+ # alternative implementation:
38
+ # containers.reverse.each do |container| @mutable_options.merge!(container) end
39
+ #
40
+ # benchmark, merging in #initialize vs. this resolver.
41
+ # merge 39.678k (± 9.1%) i/s - 198.700k in 5.056653s
42
+ # resolver 68.928k (± 6.4%) i/s - 342.836k in 5.001610s
@@ -30,8 +30,7 @@ module Trailblazer
30
30
  end
31
31
 
32
32
  def [](name)
33
- return @mutable_options[name] if @mutable_options.key?(name)
34
- @wrapped_options[name]
33
+ ContainerChain.find( [@mutable_options, @wrapped_options], name )
35
34
  end
36
35
 
37
36
  def []=(name, value)
@@ -47,30 +46,23 @@ module Trailblazer
47
46
  # Return the Context's two components. Used when computing the new output for
48
47
  # the next activity.
49
48
  def decompose
50
- # it would be cool if that could "destroy" the original object.
51
- # also, if those hashes were immutable, that'd be amazing.
52
49
  [ @wrapped_options, @mutable_options ]
53
50
  end
54
51
 
52
+
53
+
54
+
55
55
  # TODO: massive performance bottleneck. also, we could already "know" here what keys the
56
56
  # transformation wants.
57
+ # FIXME: ToKeywordArguments()
57
58
  def to_hash
58
59
  {}.tap do |hash|
59
- # arr = to_runtime_data << to_mutable_data << tmp_options
60
-
61
60
  # the "key" here is to call to_hash on all containers.
62
61
  [ @wrapped_options.to_hash, @mutable_options.to_hash ].each do |options|
63
62
  options.each { |k, v| hash[k.to_sym] = v }
64
63
  end
65
64
  end
66
65
  end
67
-
68
- def Build
69
- wrapped_options, mutable_options = *decompose
70
- wrapped_options = yield(wrapped_options, mutable_options) if block_given?
71
-
72
- Trailblazer::Context(wrapped_options)
73
- end
74
66
  end
75
67
 
76
68
  def self.Context(wrapped_options, mutable_options={})
@@ -1,5 +1,3 @@
1
- # TODO: test all this, for christ's sake.
2
-
3
1
  module Trailblazer
4
2
  # @note This might go to trailblazer-args along with `Context` at some point.
5
3
  def self.Option(proc)
@@ -29,7 +27,7 @@ module Trailblazer
29
27
  # Note that both #evaluate_callable and #evaluate_method drop most of the args.
30
28
  # If you need those, override this class.
31
29
  # @private
32
- def self.evaluate_callable(proc, *args)
30
+ def self.evaluate_callable(proc, *args, **flow_options)
33
31
  call!(proc, *args)
34
32
  end
35
33
 
@@ -67,6 +65,7 @@ module Trailblazer
67
65
  Option.build(KW, proc)
68
66
  end
69
67
 
68
+ # TODO: It would be cool if call! was typed and had `options SymbolizedHash` or something.
70
69
  class KW < Option
71
70
  # A different call implementation that calls `proc` with a "step interface".
72
71
  # your_code.(options, **options)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: trailblazer-circuit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.9
4
+ version: 0.0.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nick Sutterer
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-07-18 00:00:00.000000000 Z
11
+ date: 2017-07-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -104,6 +104,7 @@ files:
104
104
  - lib/trailblazer/circuit/trace.rb
105
105
  - lib/trailblazer/circuit/version.rb
106
106
  - lib/trailblazer/circuit/wrap.rb
107
+ - lib/trailblazer/container_chain.rb
107
108
  - lib/trailblazer/context.rb
108
109
  - lib/trailblazer/option.rb
109
110
  - trailblazer-circuit.gemspec