-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
88 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
module Helpers | ||
def myDig(input, path) | ||
curr = input | ||
for segment in path do | ||
if curr != nil && curr.is_a?(Hash) | ||
if curr[segment] == nil # segment is not a symbol | ||
curr = curr[segment.to_s] # segment as string | ||
else | ||
curr = curr[segment] # segment as symbol | ||
end | ||
else | ||
return nil | ||
end | ||
end | ||
curr | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
module FilterMasking | ||
VERSION = "1.1.0" | ||
VERSION = "1.1.1" | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
require "test/unit" | ||
require "./lib/fluent/plugin/helpers.rb" | ||
|
||
class HelpersTest < Test::Unit::TestCase | ||
m = Class.new do | ||
include Helpers | ||
end.new | ||
sub_test_case "myDig function" do | ||
test "Call function with nil" do | ||
t = m.myDig(nil ,[:a]) | ||
assert_equal(t, nil) | ||
end | ||
test "Not found" do | ||
t = m.myDig({:b => "t"},[:a]) | ||
assert_equal(t, nil) | ||
end | ||
test "Found symbol" do | ||
t = m.myDig({:a => "t"},[:a]) | ||
assert_equal(t, "t") | ||
end | ||
test "Found string when given symbol" do | ||
t = m.myDig({"a" => "t"},[:a]) | ||
assert_equal(t, "t") | ||
end | ||
test "Found symbol nested" do | ||
t = m.myDig({:a => {:b => "t"}},[:a, :b]) | ||
assert_equal(t, "t") | ||
end | ||
test "Found string when given symbol nested" do | ||
t = m.myDig({"a" => {"b" => "t"}},[:a, :b]) | ||
assert_equal(t, "t") | ||
end | ||
test "Found hybrid string/symbol when given symbol nested" do | ||
t = m.myDig({"a" => {:b => "t"}},[:a, :b]) | ||
assert_equal(t, "t") | ||
end | ||
test "Does not dig in string" do | ||
t = m.myDig({"a" => {:b => "t"}},[:a, :b, :c]) | ||
assert_equal(t, nil) | ||
end | ||
end | ||
end |