Class: Stenotype::Adapters::Base Abstract

Inherits:
Object
  • Object
show all
Defined in:
lib/stenotype/adapters/base.rb

Overview

This class is abstract.

An abstract base class for implementing adapters

Examples:

Defining a custom adapter

MyCustomAdapter < Stenotype::Adapters::Base
  def publish(event_data, **additional_arguments)
    client.publish(event_data, **additional_arguments)
  end

  def client
    @client ||= SomeCustomClient.new(some_credential)
  end
end

Direct Known Subclasses

GoogleCloud, StdoutAdapter, TestAdapter

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client: nil) ⇒ #publish

Returns An adapter implementing method [#publish].



31
32
33
# File 'lib/stenotype/adapters/base.rb', line 31

def initialize(client: nil)
  @client = client
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



26
27
28
# File 'lib/stenotype/adapters/base.rb', line 26

def client
  @client
end

Instance Method Details

#auto_initialize!Object

This method is abstract.

Allows custom setup of the adapter. Noop by default



49
50
51
# File 'lib/stenotype/adapters/base.rb', line 49

def auto_initialize!
  # noop by default
end

#flush!Object

This method is abstract.

This method is expected to be implemented by subclasses. In case async publisher is used the process might end before the async queue of messages is processed, so this method is going to be used in a at_exit hook to flush the queue.

Raises:

  • (NotImplementedError)

    unless implemented in a subclass



61
62
63
64
# File 'lib/stenotype/adapters/base.rb', line 61

def flush!
  raise NotImplementedError,
        "#{self.class.name} must implement method #flush"
end

#publish(_event_data, **_additional_attrs) ⇒ Object

This method is abstract.

This method is expected to be implemented by subclasses

Raises:

  • (NotImplementedError)

    unless implemented in a subclass



40
41
42
43
# File 'lib/stenotype/adapters/base.rb', line 40

def publish(_event_data, **_additional_attrs)
  raise NotImplementedError,
        "#{self.class.name} must implement method #publish"
end