Class: Ductr::Adapter

Inherits:
Object
  • Object
show all
Defined in:
lib/ductr/adapter.rb

Overview

Base adapter class, your adapter should inherit of this class.

Direct Known Subclasses

SequelBase::Adapter

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, **config) ⇒ Adapter

Creates a new adapter instance.

Parameters:

  • name (Symbol)

    The adapter instance name, mandatory, must be unique

  • **config (Hash<Symbol: Object>)

    The adapter configuration hash



58
59
60
61
# File 'lib/ductr/adapter.rb', line 58

def initialize(name, **config)
  @name = name
  @config = config
end

Instance Attribute Details

#configHash<Symbol: Object> (readonly)

Returns the adapter configuration hash.

Returns:

  • (Hash<Symbol: Object>)

    the adapter configuration hash



50
51
52
# File 'lib/ductr/adapter.rb', line 50

def config
  @config
end

#nameSymbol (readonly)

Returns the adapter instance name.

Returns:

  • (Symbol)

    the adapter instance name



47
48
49
# File 'lib/ductr/adapter.rb', line 47

def name
  @name
end

Class Method Details

.destination_registryRegistry

All the destinations declared for this adapter goes here.

Returns:



32
33
34
# File 'lib/ductr/adapter.rb', line 32

def destination_registry
  @destination_registry ||= Registry.new(:destination)
end

.lookup_registryRegistry

All the lookups declared for this adapter goes here.

Returns:



23
24
25
# File 'lib/ductr/adapter.rb', line 23

def lookup_registry
  @lookup_registry ||= Registry.new(:lookup)
end

.source_registryRegistry

All the sources declared for this adapter goes here.

Returns:



14
15
16
# File 'lib/ductr/adapter.rb', line 14

def source_registry
  @source_registry ||= Registry.new(:source)
end

.trigger_registryRegistry

All the triggers declared for this adapter goes here.

Returns:



41
42
43
# File 'lib/ductr/adapter.rb', line 41

def trigger_registry
  @trigger_registry ||= Registry.new(:trigger)
end

Instance Method Details

#close!void

This method returns an undefined value.

Closes the adapter when finished e.g. close connection, drop http session, close file…

Raises:

  • (NotImplementedError)


90
91
92
# File 'lib/ductr/adapter.rb', line 90

def close!
  raise NotImplementedError, "An adapter must implement the #close! method"
end

#open { ... } ⇒ void

This method returns an undefined value.

Allow use of adapter with block syntax, automatically closes on block exit.

Yields:

  • a block to execute when the adapter is opened



69
70
71
72
73
# File 'lib/ductr/adapter.rb', line 69

def open(&)
  yield(open!)
ensure
  close!
end

#open!void

This method returns an undefined value.

Opens the adapter before using it e.g. open connection, authenticate to http endpoint, open file… This method may return something, as a connection object.

Raises:

  • (NotImplementedError)


81
82
83
# File 'lib/ductr/adapter.rb', line 81

def open!
  raise NotImplementedError, "An adapter must implement the #open! method"
end