trailblazer-context 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGES.md +7 -0
- data/lib/trailblazer/context.rb +17 -6
- data/lib/trailblazer/context/version.rb +1 -1
- data/lib/trailblazer/option.rb +8 -8
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: eb81fa6ece2d3615f46a7b72a066a8316c48065a
|
4
|
+
data.tar.gz: d720c68f9154786ef561e97f67e29ff15e58be6c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 720a50aab05ec4de810b88227c7405f5bffaef9e2685419849f09cd56159e5e216c0ae5959b4d6502e2edabc7559bdfcbe5a01b61f9a141bfc01508f407e39a6
|
7
|
+
data.tar.gz: 2aa161d5f6de1b93210f3e1f5f9c187f0dd8b44cc0bf2d335dbc36c6479d6891d1a4ac002dd729d3b824a5fd04304fe952b0038fa16e4105ac242ec584905020
|
data/CHANGES.md
ADDED
data/lib/trailblazer/context.rb
CHANGED
@@ -3,6 +3,9 @@
|
|
3
3
|
# collects mutable runtime-computed data while providing access to compile-time
|
4
4
|
# information.
|
5
5
|
# The runtime-data takes precedence over the class data.
|
6
|
+
#
|
7
|
+
# notes
|
8
|
+
# a context is a ContainerChain with two elements (when reading)
|
6
9
|
module Trailblazer
|
7
10
|
# Holds local options (aka `mutable_options`) and "original" options from the "outer"
|
8
11
|
# activity (aka wrapped_options).
|
@@ -11,13 +14,23 @@ module Trailblazer
|
|
11
14
|
class Context # :data object:
|
12
15
|
def initialize(wrapped_options, mutable_options)
|
13
16
|
@wrapped_options, @mutable_options = wrapped_options, mutable_options
|
17
|
+
# TODO: wrapped_options should be optimized for lookups here since it could also be a Context instance, but should be a ContainerChain.
|
14
18
|
end
|
15
19
|
|
16
20
|
def [](name)
|
17
|
-
ContainerChain.find( [@mutable_options, @wrapped_options], name )
|
21
|
+
# ContainerChain.find( [@mutable_options, @wrapped_options], name )
|
22
|
+
|
23
|
+
# in 99.9% or cases @mutable_options will be a Hash, and these are already optimized for lookups.
|
24
|
+
# it's up to the ContainerChain to optimize itself.
|
25
|
+
return @mutable_options[name] if @mutable_options.key?(name)
|
26
|
+
@wrapped_options[name]
|
18
27
|
end
|
19
28
|
|
29
|
+
# TODO: use ContainerChain.find here for a generic optimization
|
30
|
+
#
|
31
|
+
# the version here is about 4x faster for now.
|
20
32
|
def key?(name)
|
33
|
+
# ContainerChain.find( [@mutable_options, @wrapped_options], name )
|
21
34
|
@mutable_options.key?(name) || @wrapped_options.key?(name)
|
22
35
|
end
|
23
36
|
|
@@ -25,6 +38,9 @@ module Trailblazer
|
|
25
38
|
@mutable_options[name] = value
|
26
39
|
end
|
27
40
|
|
41
|
+
# @private
|
42
|
+
#
|
43
|
+
# This method might be removed.
|
28
44
|
def merge(hash)
|
29
45
|
original, mutable_options = decompose
|
30
46
|
|
@@ -37,11 +53,6 @@ module Trailblazer
|
|
37
53
|
[ @wrapped_options, @mutable_options ]
|
38
54
|
end
|
39
55
|
|
40
|
-
def key?(name)
|
41
|
-
ContainerChain.find( [@mutable_options, @wrapped_options], name )
|
42
|
-
end
|
43
|
-
|
44
|
-
|
45
56
|
def keys
|
46
57
|
@mutable_options.keys + @wrapped_options.keys # FIXME.
|
47
58
|
end
|
data/lib/trailblazer/option.rb
CHANGED
@@ -11,30 +11,30 @@ module Trailblazer
|
|
11
11
|
# @return [Proc] when called, this proc will evaluate its option (at run-time).
|
12
12
|
def self.build(call_implementation, proc)
|
13
13
|
if proc.is_a? Symbol
|
14
|
-
->(*args) { call_implementation.evaluate_method(proc, *args) }
|
14
|
+
->(*args, &block) { call_implementation.evaluate_method(proc, *args, &block) }
|
15
15
|
else
|
16
|
-
->(*args) { call_implementation.evaluate_callable(proc, *args) }
|
16
|
+
->(*args, &block) { call_implementation.evaluate_callable(proc, *args, &block) }
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
20
20
|
# A call implementation invoking `proc.(*args)` and plainly forwarding all arguments.
|
21
21
|
# Override this for your own step strategy (see KW#call!).
|
22
22
|
# @private
|
23
|
-
def self.call!(proc, *args)
|
24
|
-
proc.(*args)
|
23
|
+
def self.call!(proc, *args, &block)
|
24
|
+
proc.(*args, &block)
|
25
25
|
end
|
26
26
|
|
27
27
|
# Note that both #evaluate_callable and #evaluate_method drop most of the args.
|
28
28
|
# If you need those, override this class.
|
29
29
|
# @private
|
30
|
-
def self.evaluate_callable(proc, *args, **flow_options)
|
31
|
-
call!(proc, *args)
|
30
|
+
def self.evaluate_callable(proc, *args, **flow_options, &block)
|
31
|
+
call!(proc, *args, &block)
|
32
32
|
end
|
33
33
|
|
34
34
|
# Make the context's instance method a "lambda" and reuse #call!.
|
35
35
|
# @private
|
36
|
-
def self.evaluate_method(proc, *args, exec_context:raise, **flow_options)
|
37
|
-
call!(exec_context.method(proc), *args)
|
36
|
+
def self.evaluate_method(proc, *args, exec_context:raise, **flow_options, &block)
|
37
|
+
call!(exec_context.method(proc), *args, &block)
|
38
38
|
end
|
39
39
|
|
40
40
|
# Returns a {Proc} that, when called, invokes the `proc` argument with keyword arguments.
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: trailblazer-context
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
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-12-
|
11
|
+
date: 2017-12-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -61,6 +61,7 @@ extensions: []
|
|
61
61
|
extra_rdoc_files: []
|
62
62
|
files:
|
63
63
|
- ".gitignore"
|
64
|
+
- CHANGES.md
|
64
65
|
- Gemfile
|
65
66
|
- LICENSE
|
66
67
|
- README.md
|