Class: KeyVortex::Adapter

Inherits:
Object
  • Object
show all
Defined in:
lib/key_vortex/adapter.rb,
lib/key_vortex/adapter/memory.rb

Overview

Adapters bridge the gap between the main logic of KeyVortex and individual backends. When using a backend, it can have various limitations on particular data types. KeyVortex will guarantee that these limitations are more permissive then the Records used to interact with it.

To keep dependencies down, the subclasses you’ll actually use will be implemented in other gems, but an in memory adapter does ship with this gem. Here are some that are available:

Building Adapters

For an adapter to work with KeyVortex, it needs to inherit from this class. In addition, it needs to override the following methods:

  • save(Record) => Anything

  • find(String) => Record

  • remove(String) => Anything

There is a separate gem, which provides a set of shared examples enforcing the correct behavior of those methods. PRs to include your gem in the list in the previous section will be accepted if they conform to that contract.

Direct Known Subclasses

Memory

Defined Under Namespace

Classes: Memory

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeAdapter

Returns a new instance of Adapter.



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

def initialize
  @limitations = {}
end

Class Method Details

.symbolSymbol

Provide the symbol used when using the factory method KeyVortex.vortex.

Returns:

  • (Symbol)

    A symbol representing this class



52
53
54
# File 'lib/key_vortex/adapter.rb', line 52

def self.symbol
  name.split(":").last.downcase.to_sym
end

Instance Method Details

#limitation_for(field) ⇒ KeyVortex::Limitation

Get the limitation for the type of a given field.

Parameters:

Returns:



39
40
41
# File 'lib/key_vortex/adapter.rb', line 39

def limitation_for(field)
  @limitations[field.limitation.type]
end

#register_limitation(limitation) ⇒ Object

Apply the provided limitation to the adapter.

Parameters:



45
46
47
# File 'lib/key_vortex/adapter.rb', line 45

def register_limitation(limitation)
  @limitations[limitation.type] = limitation
end