Module: Clustr::Adapter

Defined in:
lib/clustr/adapter.rb,
lib/clustr/adapter/base.rb,
lib/clustr/adapter/simpledb.rb

Overview

Contains different adapters for controlling the underlying logic for determining current members and adding new members to a cluster through the usage of different technologies, such as SimpleDB.

Defined Under Namespace

Classes: Base, SimpleDB

Class Method Summary collapse

Class Method Details

.[](adapter) ⇒ class

Return the constantized adapter class.

Parameters:

  • adapter (string)

    to return.

Returns:

  • (class)

    The uninitialized Adapter, nil if undefined.



38
39
40
# File 'lib/clustr/adapter.rb', line 38

def self.[](adapter)
  self.const_get adapter
end

.exists?(adapter) ⇒ boolean

Determines if the named adapter that has been passed in is a defined and implemented Adapter.

Parameters:

  • adapter (string)

    name

Returns:

  • (boolean)

    True if the Adapter is implemented, false otherwise.



48
49
50
# File 'lib/clustr/adapter.rb', line 48

def self.exists?(adapter)
  self.const_defined? adapter
end

.from_options(options) ⇒ object

Note:

The named adapter must equal the defined class name.

Instantiates and returns a new Adapter class which has been determined from the options hash that has been passed in.

Examples:

Initializing a new adapter

sdb = Clustr::Adapter.from_options({
  "adapter" => "SimpleDB",
  "key" => "foobar"
})

Parameters:

  • options (hash)

    to use, must contain an “adapter” key.

Returns:

  • (object)

    An instantiated adapter object.



28
29
30
31
# File 'lib/clustr/adapter.rb', line 28

def self.from_options(options)
  name = options["adapter"]
  self[name].new(options)
end