trailblazer-context 0.2.0 → 0.4.0
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 +4 -4
- data/.gitignore +1 -0
- data/.travis.yml +10 -5
- data/CHANGES.md +40 -0
- data/Gemfile +0 -1
- data/LICENSE +1 -1
- data/Rakefile +5 -2
- data/lib/trailblazer-context.rb +1 -0
- data/lib/trailblazer/container_chain.rb +0 -2
- data/lib/trailblazer/context.rb +13 -84
- data/lib/trailblazer/context/container.rb +100 -0
- data/lib/trailblazer/context/container/with_aliases.rb +102 -0
- data/lib/trailblazer/context/store/indifferent_access.rb +36 -0
- data/lib/trailblazer/context/version.rb +2 -2
- data/lib/trailblazer/option.rb +26 -57
- data/test/benchmark/benchmark_helper.rb +32 -0
- data/test/benchmark/indifferent_access_test.rb +89 -0
- data/test/benchmark/indifferent_access_with_aliasing_test.rb +73 -0
- data/test/context_test.rb +201 -91
- data/test/option_test.rb +34 -73
- data/test/test_helper.rb +0 -1
- data/trailblazer-context.gemspec +4 -3
- metadata +21 -17
- data/.rubocop-https---raw-githubusercontent-com-trailblazer-meta-master-rubocop-yml +0 -136
- data/.rubocop.yml +0 -40
- data/lib/trailblazer/context/aliasing.rb +0 -36
- data/lib/trailblazer/context/indifferent_access.rb +0 -35
@@ -1,36 +0,0 @@
|
|
1
|
-
module Trailblazer
|
2
|
-
class Context
|
3
|
-
module Aliasing
|
4
|
-
def initialize(wrapped_options, mutable_options, context_alias: {}, **)
|
5
|
-
super(wrapped_options, mutable_options)
|
6
|
-
|
7
|
-
@aliases = context_alias.invert
|
8
|
-
end
|
9
|
-
|
10
|
-
def [](key)
|
11
|
-
return super unless aka = @aliases[key] # yepp, nil/false won't work
|
12
|
-
super(aka)
|
13
|
-
end
|
14
|
-
|
15
|
-
def key?(key)
|
16
|
-
return super unless aka = @aliases[key] # yepp, nil/false won't work
|
17
|
-
super(aka)
|
18
|
-
end
|
19
|
-
|
20
|
-
# @private ?
|
21
|
-
def merge(hash)
|
22
|
-
original, mutable_options = decompose
|
23
|
-
|
24
|
-
self.class.new(
|
25
|
-
original,
|
26
|
-
mutable_options.merge(hash),
|
27
|
-
context_alias: @aliases.invert # DISCUSS: maybe we can speed up by remembering the original options?
|
28
|
-
)
|
29
|
-
end
|
30
|
-
|
31
|
-
def to_hash
|
32
|
-
super.merge(Hash[@aliases.collect { |aka, k| key?(k) ? [aka, self[k]] : nil }.compact]) # FIXME: performance!
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
@@ -1,35 +0,0 @@
|
|
1
|
-
require "trailblazer/context/aliasing"
|
2
|
-
|
3
|
-
module Trailblazer
|
4
|
-
class Context
|
5
|
-
class IndifferentAccess < Context
|
6
|
-
module InstanceMethods
|
7
|
-
def [](name)
|
8
|
-
# TODO: well...
|
9
|
-
@mutable_options.key?(name.to_sym) and return @mutable_options[name.to_sym]
|
10
|
-
@mutable_options.key?(name.to_s) and return @mutable_options[name.to_s]
|
11
|
-
@wrapped_options.key?(name.to_sym) and return @wrapped_options[name.to_sym]
|
12
|
-
@wrapped_options[name.to_s]
|
13
|
-
end
|
14
|
-
|
15
|
-
def self.build(wrapped_options, mutable_options, (ctx, flow_options), circuit_options)
|
16
|
-
new(wrapped_options, mutable_options, flow_options)
|
17
|
-
end
|
18
|
-
end
|
19
|
-
include InstanceMethods
|
20
|
-
|
21
|
-
def key?(name)
|
22
|
-
super(name.to_sym) || super(name.to_s)
|
23
|
-
end
|
24
|
-
|
25
|
-
include Aliasing # FIXME
|
26
|
-
|
27
|
-
# This also builds IndifferentAccess::Aliasing.
|
28
|
-
# The {#build} method is designed to take all args from {for_circuit} and then
|
29
|
-
# translate that to the constructor.
|
30
|
-
def self.build(wrapped_options, mutable_options, (ctx, flow_options), circuit_options)
|
31
|
-
new(wrapped_options, mutable_options, **flow_options)
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|