fluent-plugin-flatten 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |gem|
2
2
  gem.name = 'fluent-plugin-flatten'
3
- gem.version = '0.0.4'
3
+ gem.version = '0.0.5'
4
4
  gem.authors = ['Kentaro Kuribayashi']
5
5
  gem.email = ['kentarok@gmail.com']
6
6
  gem.homepage = 'http://github.com/kentaro/fluent-plugin-flatten'
@@ -41,14 +41,18 @@ module Fluent
41
41
  def flatten(record)
42
42
  flattened = {}
43
43
 
44
- if record.has_key?(key)
45
- hash = JSON.parse(record[key])
46
- processor = lambda do |root, hash|
47
- unless hash.is_a?(Hash)
48
- raise Error.new('The value to be flattened must be a Hash: #{hash}')
49
- end
44
+ if record.has_key?(key) && !record[key].empty?
45
+ hash = nil
50
46
 
47
+ begin
48
+ hash = JSON.parse(record[key])
49
+ rescue JSON::ParserError
50
+ return flattened
51
+ end
52
+
53
+ processor = lambda do |root, hash|
51
54
  flattened = {}
55
+ return flattened unless hash.is_a?(Hash)
52
56
 
53
57
  hash.each do |path, value|
54
58
  keypath = [root, path].join('.')
@@ -52,10 +52,13 @@ class FlattenOutputTest < Test::Unit::TestCase
52
52
  flattened = d.instance.flatten({ 'foo' => '{"bar" : "baz"}', 'hoge' => 'fuga' })
53
53
  assert_equal({ 'foo.bar' => { 'value' => 'baz' } }, flattened)
54
54
 
55
- # when not hash value is passed
56
- assert_raise(Fluent::FlattenOutput::Error) do
57
- d.instance.flatten({ 'foo' => '["bar", "baz"]' })
58
- end
55
+ # when empty value is passed
56
+ flattened = d.instance.flatten({ 'foo' => '' })
57
+ assert_equal({}, flattened)
58
+
59
+ # when invalid json value is passed
60
+ flattened = d.instance.flatten({ 'foo' => '-' })
61
+ assert_equal({}, flattened)
59
62
  end
60
63
 
61
64
  def test_emit
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluent-plugin-flatten
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-12-05 00:00:00.000000000 Z
12
+ date: 2012-12-10 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake