Sha256: df75a150d972d1f7fc0a2bbb85649947cd94a651780e9324f30628cf756f39ab

Contents?: true

Size: 1.25 KB

Versions: 6

Compression:

Stored size: 1.25 KB

Contents

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
      # @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

6 entries across 6 versions & 1 rubygems

Version Path
rom-0.9.1 lib/rom/memory/gateway.rb
rom-0.9.0 lib/rom/memory/gateway.rb
rom-0.9.0.rc1 lib/rom/memory/gateway.rb
rom-0.9.0.beta1 lib/rom/memory/gateway.rb
rom-0.8.1 lib/rom/memory/gateway.rb
rom-0.8.0 lib/rom/memory/gateway.rb