trailblazer-context 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGES.md +4 -0
- data/Rakefile +1 -1
- data/lib/trailblazer/context/indifferent_access.rb +6 -11
- data/lib/trailblazer/context/version.rb +1 -1
- data/test/context_test.rb +4 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f888d046e1096b02494a7a5fede3827027321d7553d6a01fb5f7ac2dc9fb43cc
|
4
|
+
data.tar.gz: 67f3bd4537ea2671a94ac3a74c55ed2f49ed9e9b58169af8eb2e1767fbc0416b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 950342604fd800574b188606453e5dbe2b685fe8bb49c8b4c042d27c4beb91be298c2a4a0e07cc509164b6c5ebc0987785e631f487179dbecffacfb180a11ca3
|
7
|
+
data.tar.gz: f8fafddb80a3441a623c0db104776919313ff99f4eea0d2c0aa8826c00ba0fb89319294e0c3f892db11061825d41f67e9d2d68637768ce67be984533c1d92230
|
data/CHANGES.md
CHANGED
@@ -1,3 +1,7 @@
|
|
1
|
+
# 0.1.4
|
2
|
+
|
3
|
+
* Fix the `IndifferentAccess` name lookup. Since we can't convert all keys to symbols internally (not every options structure has `collect`) we need to have a lookup chain.
|
4
|
+
|
1
5
|
# 0.1.3
|
2
6
|
|
3
7
|
* Introduce `Context::IndifferentAccess` which converts all keys to symbol. This, in turn, allows to use both string and symbol keys everywhere. Currently, the implementation is set via the global method `Context.implementation` and defaults to the new `IndifferentAccess`.
|
data/Rakefile
CHANGED
@@ -2,22 +2,17 @@ module Trailblazer
|
|
2
2
|
class Context
|
3
3
|
class IndifferentAccess < Context
|
4
4
|
def [](name)
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
5
|
+
# TODO: well...
|
6
|
+
@mutable_options.key?(name.to_sym) and return @mutable_options[name.to_sym]
|
7
|
+
@mutable_options.key?(name.to_s) and return @mutable_options[name.to_s]
|
8
|
+
@wrapped_options.key?(name.to_sym) and return @wrapped_options[name.to_sym]
|
9
|
+
@wrapped_options[name.to_s]
|
10
10
|
end
|
11
11
|
|
12
12
|
def key?(name)
|
13
|
-
super(name.to_sym)
|
13
|
+
super(name.to_sym) || super(name.to_s)
|
14
14
|
end
|
15
15
|
|
16
|
-
def merge(hash)
|
17
|
-
hash = Hash[hash.collect { |k,v| [k.to_sym, v] }]
|
18
|
-
|
19
|
-
super(hash)
|
20
|
-
end
|
21
16
|
end
|
22
17
|
end
|
23
18
|
end
|
data/test/context_test.rb
CHANGED
@@ -73,18 +73,21 @@ class ContextWithIndifferentAccessTest < Minitest::Spec
|
|
73
73
|
flow_options = {}
|
74
74
|
circuit_options = {}
|
75
75
|
|
76
|
-
immutable = {model: Object}
|
76
|
+
immutable = {model: Object, "policy" => Hash}
|
77
77
|
|
78
78
|
ctx = Trailblazer::Context.for(immutable, [immutable, flow_options], circuit_options)
|
79
79
|
|
80
80
|
ctx[:model].must_equal Object
|
81
81
|
ctx["model"].must_equal Object
|
82
|
+
ctx[:policy].must_equal Hash
|
83
|
+
ctx["policy"].must_equal Hash
|
82
84
|
|
83
85
|
ctx["contract.default"] = Module
|
84
86
|
ctx["contract.default"].must_equal Module
|
85
87
|
ctx[:"contract.default"].must_equal Module
|
86
88
|
|
87
89
|
# key?
|
90
|
+
ctx.key?("____contract.default").must_equal false
|
88
91
|
ctx.key?("contract.default").must_equal true
|
89
92
|
ctx.key?(:"contract.default").must_equal true
|
90
93
|
|