dap 0.1.0 → 0.1.1
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/dap/filter/simple.rb +26 -0
- data/lib/dap/version.rb +1 -1
- data/spec/dap/filter/simple_filter_spec.rb +22 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 78d24bb7f83c5edce062ad60c427822ccc896723
|
4
|
+
data.tar.gz: 3b62b7361c6cdaa5e2ac94a8ee76d2e18eba8431
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 22aaf4462af2fe4d18bfb4ed0cc8d85dfbb34dedbcf263a0b99e76d57663d5f4a79f9b8c42618df862ddff0155bfa609e9c3c9ff1d5995240901afc83c760171
|
7
|
+
data.tar.gz: 9ccfacb005c24d24a97f79dd6cc9e5f84cfa4ec1e6aab5a307554d3ce015973e023997dedc995c3d2fdc6bda8671f97208400d3bed06ec65dd75a291e1152ceb
|
data/lib/dap/filter/simple.rb
CHANGED
@@ -39,6 +39,32 @@ class FilterRename
|
|
39
39
|
[ doc ]
|
40
40
|
end
|
41
41
|
end
|
42
|
+
|
43
|
+
# Example below replaces periods with underscores in the names of all keys
|
44
|
+
# one level below 'my_key'
|
45
|
+
# rename_subkey_match my_key '.' '_'
|
46
|
+
class FilterRenameSubkeyMatch
|
47
|
+
include Base
|
48
|
+
|
49
|
+
def initialize(args)
|
50
|
+
super
|
51
|
+
fail "Expected 3 arguments to '#{self.name}' but got #{args.size}" unless args.size == 3
|
52
|
+
self.opts = args
|
53
|
+
end
|
54
|
+
|
55
|
+
def process(doc)
|
56
|
+
temp_field = {}
|
57
|
+
field, original, updated = self.opts
|
58
|
+
return [ doc ] unless doc[field].is_a?(::Hash)
|
59
|
+
doc[field].each_key do |k|
|
60
|
+
new_k = k.gsub(original, updated)
|
61
|
+
temp_field[new_k] = doc[field][k]
|
62
|
+
end
|
63
|
+
doc[field] = temp_field
|
64
|
+
[ doc ]
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
42
68
|
class FilterMatchRemove
|
43
69
|
include Base
|
44
70
|
def process(doc)
|
data/lib/dap/version.rb
CHANGED
@@ -45,7 +45,7 @@ describe Dap::Filter::FilterExpand do
|
|
45
45
|
end
|
46
46
|
end
|
47
47
|
|
48
|
-
context 'ignore all but specified
|
48
|
+
context 'ignore all but specified unnested json' do
|
49
49
|
let(:process) { filter.process({"foo.bar" => "baz", "baf.blah" => "baz" }) }
|
50
50
|
it 'has new expanded keys' do
|
51
51
|
expect(process).to eq([{"foo" => {"bar" => "baz"}, "foo.bar" => "baz", "baf.blah" => "baz"}])
|
@@ -61,6 +61,27 @@ describe Dap::Filter::FilterExpand do
|
|
61
61
|
end
|
62
62
|
end
|
63
63
|
|
64
|
+
describe Dap::Filter::FilterRenameSubkeyMatch do
|
65
|
+
describe '.process' do
|
66
|
+
|
67
|
+
let(:filter) { described_class.new(['foo', '.', '_']) }
|
68
|
+
|
69
|
+
context 'with subkeys' do
|
70
|
+
let(:process) { filter.process({"foo" => {"bar.one" => "baz", "bar.two" => "baz"}, "foo.bar" => "baz", "bar" => {"bar.one" => "baz", "bar.two" => "baz"}}) }
|
71
|
+
it 'renames keys as expected' do
|
72
|
+
expect(process).to eq([{"foo" => {"bar_one" => "baz", "bar_two" => "baz"}, "foo.bar" => "baz", "bar" => {"bar.one" => "baz", "bar.two" => "baz"}}])
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
context 'without subkeys' do
|
77
|
+
let(:process) { filter.process({"foo" => "bar", "foo.blah" => "blah", "foo.bar" => "baz"}) }
|
78
|
+
it 'produces unchanged output without errors' do
|
79
|
+
expect(process).to eq([{"foo" => "bar", "foo.blah" => "blah", "foo.bar" => "baz"}])
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
64
85
|
describe Dap::Filter::FilterMatchRemove do
|
65
86
|
describe '.process' do
|
66
87
|
|