1
0
mirror of https://github.com/meineerde/rackstash.git synced 2025-12-20 15:21:12 +00:00

Set Encoder helper methods as private

That way, they don't pollute the public interface of the encoders
including the helpers modules.
This commit is contained in:
Holger Just 2017-08-24 23:06:09 +02:00
parent 3078bccafd
commit 96aaaa0348
4 changed files with 24 additions and 4 deletions

View File

@ -10,6 +10,8 @@ module Rackstash
# Some useful helper methods for {Encoders} which help in normalizing and # Some useful helper methods for {Encoders} which help in normalizing and
# handling the message list in the event Hash. # handling the message list in the event Hash.
module Message module Message
private
# Normalize the `"message"` field of the given log event Hash. # Normalize the `"message"` field of the given log event Hash.
# #
# While the filters still had access to the array of {Message} objects # While the filters still had access to the array of {Message} objects
@ -24,7 +26,7 @@ module Rackstash
# @param event [Hash] a log event Hash # @param event [Hash] a log event Hash
# @return [Hash] the given event with the `"message"` key set as a # @return [Hash] the given event with the `"message"` key set as a
# single string. # single string.
def normalize_message(event) def normalize_message(event) #:doc:
event[FIELD_MESSAGE] = event[FIELD_MESSAGE] =
case event[FIELD_MESSAGE] case event[FIELD_MESSAGE]
when Array when Array

View File

@ -14,6 +14,8 @@ module Rackstash
# handling timestamps in the event Hash, especially the {FIELD_TIMESTAMP} # handling timestamps in the event Hash, especially the {FIELD_TIMESTAMP}
# field. # field.
module Timestamp module Timestamp
private
# Normalize the `"@timestamp"` field of the given log event Hash. # Normalize the `"@timestamp"` field of the given log event Hash.
# Before any filters, only the `"@timestamp"` fueld contains a `Time` # Before any filters, only the `"@timestamp"` fueld contains a `Time`
# object denoting the timestamp of the log event. To represent this # object denoting the timestamp of the log event. To represent this
@ -25,7 +27,7 @@ module Rackstash
# hash. By default, we use the `"@timestamp"` field. # hash. By default, we use the `"@timestamp"` field.
# @return [Hash] the given event with the `field` key set as an ISO 8601 # @return [Hash] the given event with the `field` key set as an ISO 8601
# formatted time string. # formatted time string.
def normalize_timestamp(event, field: FIELD_TIMESTAMP) def normalize_timestamp(event, field: FIELD_TIMESTAMP) #:doc:
time = event[field] time = event[field]
if time.is_a?(Time) || time.is_a?(DateTime) if time.is_a?(Time) || time.is_a?(DateTime)

View File

@ -9,7 +9,15 @@ require 'spec_helper'
require 'rackstash/encoders/helpers/message' require 'rackstash/encoders/helpers/message'
describe Rackstash::Encoders::Helpers::Message do describe Rackstash::Encoders::Helpers::Message do
let(:helper) { Object.new.extend(described_class) } let(:helper) {
helper = Object.new.extend(described_class)
described_class.private_instance_methods(false).each do |method|
helper.define_singleton_method(method) do |*args|
super(*args)
end
end
helper
}
let(:event) { {} } let(:event) { {} }
describe '#normalize_message' do describe '#normalize_message' do

View File

@ -9,7 +9,15 @@ require 'spec_helper'
require 'rackstash/encoders/helpers/timestamp' require 'rackstash/encoders/helpers/timestamp'
describe Rackstash::Encoders::Helpers::Timestamp do describe Rackstash::Encoders::Helpers::Timestamp do
let(:helper) { Object.new.extend(described_class) } let(:helper) {
helper = Object.new.extend(described_class)
described_class.private_instance_methods(false).each do |method|
helper.define_singleton_method(method) do |*args|
super(*args)
end
end
helper
}
let(:event) { {} } let(:event) { {} }
describe '#normalize_timestamp' do describe '#normalize_timestamp' do