Class: Charrington::TransformPostgres

Inherits:
Object
  • Object
show all
Includes:
Service
Defined in:
lib/logstash/outputs/charrington/transform_postgres.rb

Overview

Inserts and modifies a Postgres database

Constant Summary collapse

Error =
Class.new(StandardError)
EventNil =
Class.new(Error)
TableNameNil =
Class.new(Error)
ColumnBlacklist =
Class.new(Error)
KEY_FILTER_BLACKLIST =
%w[host path jwt sequence].freeze
KEY_RAISE_BLACKLIST =
%w[id inserted_at].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Service

included

Constructor Details

#initialize(event) ⇒ TransformPostgres

Returns a new instance of TransformPostgres.

Raises:



20
21
22
23
24
25
26
27
# File 'lib/logstash/outputs/charrington/transform_postgres.rb', line 20

def initialize(event)
  raise EventNil, 'Event is nil' if event.nil?

  event = event.to_hash
  @event = drop_keys(event)
  @top_level_keys = @event.keys
  check_blacklist
end

Instance Attribute Details

#eventObject

Returns the value of attribute event.



9
10
11
# File 'lib/logstash/outputs/charrington/transform_postgres.rb', line 9

def event
  @event
end

#top_level_keysObject (readonly)

Returns the value of attribute top_level_keys.



10
11
12
# File 'lib/logstash/outputs/charrington/transform_postgres.rb', line 10

def top_level_keys
  @top_level_keys
end

Instance Method Details

#callObject



29
30
31
32
33
34
# File 'lib/logstash/outputs/charrington/transform_postgres.rb', line 29

def call
  flattened = flatten_hash(event)
  top_level_keys.each { |k| event.delete(k) }
  flattened.each_pair { |key, val| event[key] = val }
  event
end