class Basquiat::Adapters::Base

Base implementation for an adapter in uses {HashRefinements} internally.

Attributes

options[R]
procs[R]

@!endgroup

Public Class Methods

new(procs: {}) click to toggle source

@param procs [Object]

It's a hash by default, but usually will be superseded by the adapter implementation
# File lib/basquiat/adapters/base_adapter.rb, line 39
def initialize(procs: {})
  @options = base_options
  @procs   = procs
  @retries = 0
end
register_strategy(config_name, klass) click to toggle source

Used to register a requeue/acknowledge strategy @param config_name [#to_sym] the named used on the config file for the Requeue Strategy @param klass [Class] the class name.

# File lib/basquiat/adapters/base_adapter.rb, line 22
def register_strategy(config_name, klass)
  strategies[config_name.to_sym] = klass
end
strategies() click to toggle source

A hash representing the registered requeue/acknowledge strategies @return [Hash] the registered RequeueStrategies

# File lib/basquiat/adapters/base_adapter.rb, line 15
def strategies
  @strategies ||= {}
end
strategy(key) click to toggle source

Return the Strategy Class registered on given key @param key [#to_sym] configured key for the wanted strategy @return [Class] the strategy class @raise [Errors::StrategyNotRegistered] if it fails to find the key

# File lib/basquiat/adapters/base_adapter.rb, line 30
def strategy(key)
  strategies.fetch(key)
rescue KeyError
  raise Basquiat::Errors::StrategyNotRegistered
end

Public Instance Methods

adapter_options(opts) click to toggle source

Allows the base_options to be superseded on the local level

You could have configured an exchange_name (on a config file) to +'awesome.sauce'+, but on this object you'd want to publish your messages to the +'killer.mailman'+ exchange. @example

class Mailmail
  extend Basquiat::Base
  adapter_options {exchange: {name: 'killer.mailman'}}
end

@param [Hash] opts an adapter dependant hash of options

# File lib/basquiat/adapters/base_adapter.rb, line 61
def adapter_options(opts)
  @options.deep_merge(opts)
end
base_options() click to toggle source

The default adapter options, merged with the {Basquiat::Configuration#adapter_options}. Used internally. @api private @return [Hash] the full options hash @todo rename this method

# File lib/basquiat/adapters/base_adapter.rb, line 69
def base_options
  default_options.merge(Basquiat.configuration.adapter_options)
end
default_options() click to toggle source

The adapter default options @return [Hash]

# File lib/basquiat/adapters/base_adapter.rb, line 75
def default_options
  {}
end
disconnect() click to toggle source

@abstract Disconnect from the message queue

# File lib/basquiat/adapters/base_adapter.rb, line 91
def disconnect
  raise Basquiat::Errors::SubclassResponsibility
end
publish() click to toggle source

@!group Adapter specific implementations @abstract Publish an event to the event stream

# File lib/basquiat/adapters/base_adapter.rb, line 81
def publish
  raise Basquiat::Errors::SubclassResponsibility
end
strategies() click to toggle source

Utility method to access the class instance variable

# File lib/basquiat/adapters/base_adapter.rb, line 46
def strategies
  self.class.strategies
end
subscribe_to() click to toggle source

@abstract subscribe_to the event stream

# File lib/basquiat/adapters/base_adapter.rb, line 86
def subscribe_to
  raise Basquiat::Errors::SubclassResponsibility
end