Sha256: 1fba0ba386baab415d022ca25d928d5cfea5188eb9e5f0d5dd59334b18f50575

Contents?: true

Size: 1.28 KB

Versions: 38

Compression:

Stored size: 1.28 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
      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

38 entries across 38 versions & 2 rubygems

Version Path
rom-core-4.2.1 lib/rom/memory/gateway.rb
rom-core-4.2.0 lib/rom/memory/gateway.rb
rom-core-4.1.2 lib/rom/memory/gateway.rb
rom-core-4.1.1 lib/rom/memory/gateway.rb
rom-core-4.1.0 lib/rom/memory/gateway.rb
rom-core-4.0.2 lib/rom/memory/gateway.rb
rom-core-4.0.1 lib/rom/memory/gateway.rb
rom-3.3.3 lib/rom/memory/gateway.rb
rom-core-4.0.0 lib/rom/memory/gateway.rb
rom-3.3.2 lib/rom/memory/gateway.rb
rom-core-4.0.0.rc2 lib/rom/memory/gateway.rb
rom-core-4.0.0.rc1 lib/rom/memory/gateway.rb
rom-core-4.0.0.beta3 lib/rom/memory/gateway.rb
rom-3.3.1 lib/rom/memory/gateway.rb
rom-core-4.0.0.beta2 lib/rom/memory/gateway.rb
rom-3.3.0 lib/rom/memory/gateway.rb
rom-core-4.0.0.beta1 lib/rom/memory/gateway.rb
rom-3.2.3 lib/rom/memory/gateway.rb
rom-3.2.2 lib/rom/memory/gateway.rb
rom-3.2.1 lib/rom/memory/gateway.rb