Class: Fluent::Plugin::Mixin::MutateEvent
- Inherits:
-
SimpleDelegator
- Object
- SimpleDelegator
- Fluent::Plugin::Mixin::MutateEvent
- Defined in:
- lib/fluent/plugin/mixin/mutate_event.rb
Instance Attribute Summary collapse
-
#event_tag ⇒ Object
Returns the value of attribute event_tag.
-
#event_time ⇒ Object
Returns the value of attribute event_time.
Instance Method Summary collapse
- #dig(*keys) ⇒ Object
- #get(key_or_path, &block) ⇒ Object
- #include?(key_or_path) ⇒ Boolean
-
#initialize(record, expand_nesting: true) ⇒ MutateEvent
constructor
A new instance of MutateEvent.
- #parent(key_or_path, &block) ⇒ Object
- #prune ⇒ Object
- #remove(key_or_path) ⇒ Object
- #set(key_or_path, value) ⇒ Object
- #to_record ⇒ Object
Constructor Details
#initialize(record, expand_nesting: true) ⇒ MutateEvent
Returns a new instance of MutateEvent.
5 6 7 8 9 10 11 |
# File 'lib/fluent/plugin/mixin/mutate_event.rb', line 5 def initialize(record, expand_nesting: true) super(record) @record = record @event_time = nil @event_tag = nil @expand_nesting = end |
Instance Attribute Details
#event_tag ⇒ Object
Returns the value of attribute event_tag.
14 15 16 |
# File 'lib/fluent/plugin/mixin/mutate_event.rb', line 14 def event_tag @event_tag end |
#event_time ⇒ Object
Returns the value of attribute event_time.
13 14 15 |
# File 'lib/fluent/plugin/mixin/mutate_event.rb', line 13 def event_time @event_time end |
Instance Method Details
#dig(*keys) ⇒ Object
20 21 22 23 24 25 26 27 28 29 |
# File 'lib/fluent/plugin/mixin/mutate_event.rb', line 20 def dig(*keys) item = @record keys.each do |key| break if item.nil? item = item.is_a?(Hash) ? item[key] : nil end item end |
#get(key_or_path, &block) ⇒ Object
53 54 55 56 |
# File 'lib/fluent/plugin/mixin/mutate_event.rb', line 53 def get(key_or_path, &block) item = dig(*(key_or_path)) block_given? ? yield(item) : item end |
#include?(key_or_path) ⇒ Boolean
83 84 85 |
# File 'lib/fluent/plugin/mixin/mutate_event.rb', line 83 def include?(key_or_path) !get(key_or_path).nil? end |
#parent(key_or_path, &block) ⇒ Object
58 59 60 61 62 63 64 |
# File 'lib/fluent/plugin/mixin/mutate_event.rb', line 58 def parent(key_or_path, &block) path = (key_or_path) child = path.pop item = dig(*path) block_given? ? yield(item, child) : item end |
#prune ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/fluent/plugin/mixin/mutate_event.rb', line 31 def prune delete_proc = proc do |*args| v = args[-1] if v.respond_to?(:delete_if) v.delete_if(&delete_proc) end if v.respond_to?(:strip) v = v.strip end if v.respond_to?(:empty?) and v.empty? v = nil end v.nil? end @record.delete_if(&delete_proc) end |
#remove(key_or_path) ⇒ Object
77 78 79 80 81 |
# File 'lib/fluent/plugin/mixin/mutate_event.rb', line 77 def remove(key_or_path) parent(key_or_path) do |item, child| item.delete(child) unless item.nil? end end |
#set(key_or_path, value) ⇒ Object
66 67 68 69 70 71 72 73 74 75 |
# File 'lib/fluent/plugin/mixin/mutate_event.rb', line 66 def set(key_or_path, value) path = (key_or_path) child = path.pop item = @record path.each do |key| item = item[key] ||= {} end item[child] = value end |
#to_record ⇒ Object
16 17 18 |
# File 'lib/fluent/plugin/mixin/mutate_event.rb', line 16 def to_record @record end |