monolens 0.6.1 → 0.6.2
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/lib/monolens/stdlib/core/mapping.rb +7 -1
- data/lib/monolens/version.rb +1 -1
- data/spec/monolens/stdlib/core/test_mapping.rb +41 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e0de27df8fbe83531b35a1b3c4b92d94669108ef10f17df849d9127a07698ad2
|
4
|
+
data.tar.gz: abf82eebdd9511578b0cd73524430335f9b9c8ecb60fe74598eec3e6c0d5f5e5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3909ab4f03d872d0083884ddea46e3d2546caeef268c83e1145204789050c89e34cd219161a672e07a5b34727c40f21a23be501b85ea7aaed2dd9c1eb54abf66
|
7
|
+
data.tar.gz: 394d89daddae630912035d43eefc6ab1a591a45eee3b305b203983cc40c673ad83feb65a3c9510d9a6534311f5c70af7726c83356a64cc6c35a4d2e6949512ee
|
@@ -8,12 +8,18 @@ module Monolens
|
|
8
8
|
values: [Type::Object, false], # deprecated
|
9
9
|
default: [Type::Any, false],
|
10
10
|
fallback: [Type::Callback, false],
|
11
|
+
key_hash: [Type::Lenses, false],
|
11
12
|
on_missing: [Type::Strategy.missing(%w{default fail fallback keep null}), false]
|
12
13
|
})
|
13
14
|
|
14
15
|
def call(arg, world = {})
|
16
|
+
original_arg = arg
|
17
|
+
if key_hash = option(:key_hash, nil)
|
18
|
+
arg = key_hash.call(arg, world)
|
19
|
+
end
|
20
|
+
|
15
21
|
option(:defn, option(:values, {})).fetch(arg) do
|
16
|
-
on_missing(
|
22
|
+
on_missing(original_arg, world)
|
17
23
|
end
|
18
24
|
end
|
19
25
|
|
data/lib/monolens/version.rb
CHANGED
@@ -21,6 +21,47 @@ describe Monolens, 'core.mapping' do
|
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
24
|
+
context 'with key_hash option' do
|
25
|
+
let(:mapping) do
|
26
|
+
{
|
27
|
+
'key_hash' => 'str.downcase',
|
28
|
+
'defn' => { 'todo' => 'open' }
|
29
|
+
}
|
30
|
+
end
|
31
|
+
|
32
|
+
subject do
|
33
|
+
Monolens.lens('core.mapping' => mapping)
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'replaces the value by its mapped' do
|
37
|
+
expect(subject.call('todo')).to eql('open')
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'uses the key_hash before looking for mapping' do
|
41
|
+
expect(subject.call('TODO')).to eql('open')
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'raises if not found' do
|
45
|
+
expect {
|
46
|
+
subject.call('nosuchone')
|
47
|
+
}.to raise_error(Monolens::LensError)
|
48
|
+
end
|
49
|
+
|
50
|
+
context 'with on_missing: keep' do
|
51
|
+
subject do
|
52
|
+
Monolens.lens('core.mapping' => mapping.merge('on_missing' => 'keep'))
|
53
|
+
end
|
54
|
+
|
55
|
+
it 'keeps it if missing' do
|
56
|
+
expect(subject.call('nosuchone')).to eql('nosuchone')
|
57
|
+
end
|
58
|
+
|
59
|
+
it 'keeps the original one, not the key_hashed one' do
|
60
|
+
expect(subject.call('NOSUCHONE')).to eql('NOSUCHONE')
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
24
65
|
context 'on_missing: default' do
|
25
66
|
subject do
|
26
67
|
Monolens.lens('core.mapping' => mapping.merge('on_missing' => 'default', 'default' => 'foo'))
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: monolens
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.6.
|
4
|
+
version: 0.6.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bernard Lambeau
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-09-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: minitest
|