Sha256: 1710e9bbba3359d301312318382a5b0c30a5261a5bcd3310d38cf6d53df51fe8

Contents?: true

Size: 1.31 KB

Versions: 15

Compression:

Stored size: 1.31 KB

Contents

# frozen_string_literal: true

require 'rom/gateway'
require 'rom/memory/storage'
require 'rom/memory/commands'

module ROM
  module Memory
    # In-memory gateway interface
    #
    # @example
    #   gateway = ROM::Memory::Gateway.new
    #   gateway.dataset(:users)
    #   gateway[:users].insert(name: 'Jane')
    #
    # @api public
    class Gateway < ROM::Gateway
      adapter :memory

      # @return [Object] default logger
      #
      # @api public
      attr_reader :logger

      # @api private
      def initialize
        @connection = Storage.new
      end

      # Set default logger for the gateway
      #
      # @param [Object] logger object
      #
      # @api public
      def use_logger(logger)
        @logger = logger
      end

      # Register a dataset in the gateway
      #
      # If dataset already exists it will be returned
      #
      # @return [Dataset]
      #
      # @api public
      def dataset(name)
        self[name] || connection.create_dataset(name)
      end

      # @see ROM::Gateway#dataset?
      def dataset?(name)
        connection.key?(name)
      end

      # Return dataset with the given name
      #
      # @param (see ROM::Gateway#[])
      # @return [Memory::Dataset]
      #
      # @api public
      def [](name)
        connection[name]
      end
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
rom-core-5.3.2 lib/rom/memory/gateway.rb
rom-core-5.3.1 lib/rom/memory/gateway.rb
rom-core-5.3.0 lib/rom/memory/gateway.rb
rom-core-5.2.6 lib/rom/memory/gateway.rb
rom-core-5.2.5 lib/rom/memory/gateway.rb
rom-core-5.2.4 lib/rom/memory/gateway.rb
rom-core-5.2.3 lib/rom/memory/gateway.rb
rom-core-5.2.2 lib/rom/memory/gateway.rb
rom-core-5.2.1 lib/rom/memory/gateway.rb
rom-core-5.1.2 lib/rom/memory/gateway.rb
rom-core-5.1.1 lib/rom/memory/gateway.rb
rom-core-5.1.0 lib/rom/memory/gateway.rb
rom-core-5.0.2 lib/rom/memory/gateway.rb
rom-core-5.0.1 lib/rom/memory/gateway.rb
rom-core-5.0.0 lib/rom/memory/gateway.rb