Sha256: ee8a7170182f52a4648005d28eca91bac96a809e326b29c6fba84b60b62db1a5

Contents?: true

Size: 991 Bytes

Versions: 14

Compression:

Stored size: 991 Bytes

Contents

# Unoptimized, highly inefficient in-memory datastore designed for use with specs.

module Praxis::Mapper
  module Support
    class MemoryRepository

      attr_reader :collections

      def initialize
        clear!
      end

      def clear!
        @collections = Hash.new do |hash, collection_name|
          hash[collection_name] = Set.new
        end
      end

      def collection(collection)
        collection_name = if collection.respond_to?(:table_name)
          collection.table_name.to_sym
        else
          collection.to_sym
        end

        @collections[collection_name]
      end

      def insert(collection, *values)
        self.collection(collection).merge(*values)
      end

      # Retrieve all records for +collection+ matching all +conditions+.
      def all(collection, **conditions)
        self.collection(collection).select do |row|
          conditions.all? do |k,v|
            row[k] === v
          end
        end
      end

    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
praxis-mapper-4.5 lib/praxis-mapper/support/memory_repository.rb
praxis-mapper-4.4.1 lib/praxis-mapper/support/memory_repository.rb
praxis-mapper-4.4 lib/praxis-mapper/support/memory_repository.rb
praxis-mapper-4.3 lib/praxis-mapper/support/memory_repository.rb
praxis-mapper-4.2 lib/praxis-mapper/support/memory_repository.rb
praxis-mapper-4.1.2 lib/praxis-mapper/support/memory_repository.rb
praxis-mapper-4.1.1 lib/praxis-mapper/support/memory_repository.rb
praxis-mapper-4.1 lib/praxis-mapper/support/memory_repository.rb
praxis-mapper-4.0 lib/praxis-mapper/support/memory_repository.rb
praxis-mapper-3.4.0 lib/praxis-mapper/support/memory_repository.rb
praxis-mapper-3.3 lib/praxis-mapper/support/memory_repository.rb
praxis-mapper-3.2 lib/praxis-mapper/support/memory_repository.rb
praxis-mapper-3.1.2 lib/praxis-mapper/support/memory_repository.rb
praxis-mapper-3.1.1 lib/praxis-mapper/support/memory_repository.rb