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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ce658733f9634e96a6258dcfc0caf74f91d2c6fa
4
- data.tar.gz: 93acca40858a6d0ad1f4a5869240dc0a85d9601c
3
+ metadata.gz: 78d24bb7f83c5edce062ad60c427822ccc896723
4
+ data.tar.gz: 3b62b7361c6cdaa5e2ac94a8ee76d2e18eba8431
5
5
  SHA512:
6
- metadata.gz: 995dc3db11fa7d501cc7bcb89520e161235a0c872a5b100ab2f80195486fb1989d594b00efaa88cdf7d354efc9e5bc87280bff287263a61a0138aadcc0b070c9
7
- data.tar.gz: c2426cc2d20170400f8aeee33d21b3f7ee41a0afd473323bfbaaf712cf96332da8f5e2957683958fddb6ec740c5ed94ed4125b731b2703c71214c357f934d1a4
6
+ metadata.gz: 22aaf4462af2fe4d18bfb4ed0cc8d85dfbb34dedbcf263a0b99e76d57663d5f4a79f9b8c42618df862ddff0155bfa609e9c3c9ff1d5995240901afc83c760171
7
+ data.tar.gz: 9ccfacb005c24d24a97f79dd6cc9e5f84cfa4ec1e6aab5a307554d3ce015973e023997dedc995c3d2fdc6bda8671f97208400d3bed06ec65dd75a291e1152ceb
@@ -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
@@ -1,3 +1,3 @@
1
1
  module Dap
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
@@ -45,7 +45,7 @@ describe Dap::Filter::FilterExpand do
45
45
  end
46
46
  end
47
47
 
48
- context 'ignore all but specified unnested json' do
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
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dap
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rapid7 Research