Skip to content

Commit

Permalink
Refactor: drop builder + lazy init event factories
Browse files Browse the repository at this point in the history
  • Loading branch information
kares committed Jun 21, 2021
1 parent 3abfd93 commit 81d6b71
Showing 1 changed file with 13 additions and 28 deletions.
41 changes: 13 additions & 28 deletions logstash-core/lib/logstash/plugins/event_factory_support.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,41 +2,26 @@ module LogStash
module Plugins
module EventFactorySupport

def event_factory
@event_factory ||= default_event_factory
end
attr_writer :event_factory
include LogStash::Util::ThreadSafeAttributes

def default_event_factory
DefaultEventFactory::INSTANCE
end

def event_factory_builder
EventFactoryBuilder.new default_event_factory
lazy_init_attr :event_factory do
create_event_factory
end

class EventFactoryBuilder

def initialize(factory)
@factory = factory
end

# @return an event factory
def event_factory
@factory
end
lazy_init_attr :targeted_event_factory do
raise ArgumentError.new('config.target not present') unless respond_to?(:target)
target.nil? ? event_factory : TargetedEventFactory(event_factory, target)
end

# @return [Builder] self
def with_target(target)
unless target.nil?
@factory = TargetedEventFactory.new(@factory, target)
end
self
end
private

# @private Internal API
def create_event_factory
BasicEventFactory::INSTANCE
end

class DefaultEventFactory
class BasicEventFactory
INSTANCE = new

# @param payload [Hash]
Expand All @@ -46,7 +31,7 @@ def new_event(payload)
end

end
private_constant :DefaultEventFactory
private_constant :BasicEventFactory

class TargetedEventFactory

Expand Down

0 comments on commit 81d6b71

Please sign in to comment.