trailblazer-context 0.2.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -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