Class: ROM::Memory::Gateway

Inherits:
Gateway
  • Object
show all
Defined in:
lib/rom/memory/gateway.rb

Overview

In-memory gateway interface

Examples:

gateway = ROM::Memory::Gateway.new
gateway.dataset(:users)
gateway[:users].insert(name: 'Jane')

Instance Attribute Summary collapse

Attributes inherited from Gateway

#connection

Instance Method Summary collapse

Methods inherited from Gateway

adapter, #adapter, class_from_symbol, #disconnect, mapper_compiler, #mapper_compiler, setup, #transaction

Methods included from Notifications::Listener

#subscribe

Constructor Details

#initializeGateway

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Gateway.



24
25
26
# File 'lib/rom/memory/gateway.rb', line 24

def initialize
  @connection = Storage.new
end

Instance Attribute Details

#loggerObject (readonly)

Returns default logger.

Returns:

  • (Object)

    default logger



21
22
23
# File 'lib/rom/memory/gateway.rb', line 21

def logger
  @logger
end

Instance Method Details

#[](name) ⇒ Memory::Dataset

Return dataset with the given name

Returns:



59
60
61
# File 'lib/rom/memory/gateway.rb', line 59

def [](name)
  connection[name]
end

#dataset(name) ⇒ Dataset

Register a dataset in the gateway

If dataset already exists it will be returned

Returns:



44
45
46
# File 'lib/rom/memory/gateway.rb', line 44

def dataset(name)
  self[name] || connection.create_dataset(name)
end

#dataset?(name) ⇒ Boolean

Returns:

  • (Boolean)

See Also:

  • Gateway#dataset?


49
50
51
# File 'lib/rom/memory/gateway.rb', line 49

def dataset?(name)
  connection.key?(name)
end

#use_logger(logger) ⇒ Object

Set default logger for the gateway

Parameters:

  • logger (Object)

    object



33
34
35
# File 'lib/rom/memory/gateway.rb', line 33

def use_logger(logger)
  @logger = logger
end