Sha256: f300bc3f85cdf238c095f2db47c2d60d35fd58182166c21e03f4d47ea4551807

Contents?: true

Size: 1.53 KB

Versions: 7

Compression:

Stored size: 1.53 KB

Contents

# frozen_string_literal: true

module ROM
  module Mongo
    # Wrapping the mongo collections to dataset abstractions
    # and passing them to the relations
    #
    # @abstract
    class Gateway < ROM::Gateway
      adapter :mongo

      # Builded datasets
      #
      # @return [Hash] The hash with datasets
      #
      # @api public
      attr_reader :datasets

      # Initializes the Gateway object
      #
      # @example Create a Gateway object
      #   ROM::Mongo::Gateway.new(client)
      #
      # @param [Mongo::Client] client The mongo client instance
      #
      # @api public
      def initialize(client)
        @client = client
        @datasets = {}
      end

      # Buildes dataset with the given name
      #
      # @param [Symbol] name dataset name
      #
      # @param [Class] dataset_class dataset class
      #
      # @return [ROM::Mongo::Dataset]
      #
      # @api public
      def dataset(name, dataset_class = ROM::Mongo::Dataset)
        datasets[name] = dataset_class.new(client[name])
      end

      # Checkes if dataset exists
      #
      # @param [Symbol] name dataset name
      #
      # @return [true, false]
      #
      # @api public
      def dataset?(name)
        datasets.key?(name)
      end

      # Retrieves dataset with the given name
      #
      # @param [Symbol] name dataset name
      #
      # @return [ROM::Mongo::Dataset, nil]
      #
      # @api public
      def [](name)
        datasets[name]
      end

      private

      # @api private
      attr_reader :client
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
rom-mongodb-0.1.6 lib/rom/mongo/gateway.rb
rom-mongodb-0.1.5 lib/rom/mongo/gateway.rb
rom-mongodb-0.1.4 lib/rom/mongo/gateway.rb
rom-mongodb-0.1.3 lib/rom/mongo/gateway.rb
rom-mongodb-0.1.2 lib/rom/mongo/gateway.rb
rom-mongodb-0.1.1 lib/rom/mongo/gateway.rb
rom-mongodb-0.1.0 lib/rom/mongo/gateway.rb