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

Instance Method Summary collapse

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.


26
27
28
# File 'lib/rom/memory/gateway.rb', line 26

def initialize
  @connection = Storage.new
end

Instance Attribute Details

#loggerObject (readonly)

Returns default logger.

Returns:

  • (Object)

    default logger


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

def logger
  @logger
end

Instance Method Details

#[](name) ⇒ Memory::Dataset

Return dataset with the given name

Returns:


61
62
63
# File 'lib/rom/memory/gateway.rb', line 61

def [](name)
  connection[name]
end

#dataset(name) ⇒ Dataset

Register a dataset in the gateway

If dataset already exists it will be returned

Returns:


46
47
48
# File 'lib/rom/memory/gateway.rb', line 46

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

#dataset?(name) ⇒ Boolean

Returns:

  • (Boolean)

See Also:

  • Gateway#dataset?

51
52
53
# File 'lib/rom/memory/gateway.rb', line 51

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

#use_logger(logger) ⇒ Object

Set default logger for the gateway

Parameters:

  • logger (Object)

    object


35
36
37
# File 'lib/rom/memory/gateway.rb', line 35

def use_logger(logger)
  @logger = logger
end