Sha256: b00a7fa512983c968cb4cbf9d2f1ea18d2e1e16a82b497023acbbb543c85dacb

Contents?: true

Size: 1.29 KB

Versions: 13

Compression:

Stored size: 1.29 KB

Contents

module Asynchronic
  module DataStore
    class ScopedStore

      include Helper

      attr_reader :data_store
      attr_reader :scope
      
      def initialize(data_store, scope)
        @data_store = data_store
        @scope = Key[scope]
      end

      def [](key)
        @data_store[@scope[key]]
      end

      def []=(key, value)
        @data_store[@scope[key]] = value
      end

      def delete(key)
        @data_store.delete @scope[key]
      end

      def delete_cascade
        @data_store.delete_cascade @scope
      end

      def keys
        @data_store.keys.
          select { |k| k.start_with? @scope[''] }.
          map { |k| Key[k].remove_first @scope.sections.count }
      end

      def synchronize(key, &block)
        data_store.synchronize(key, &block)
      end

      def connection_args
        [
          {
            data_store_class: @data_store.class,
            data_store_connection_args: @data_store.connection_args,
            scope: @scope
          }
        ]
      end

      def self.connect(*args)
        data_store = args[0][:data_store_class].connect *args[0][:data_store_connection_args]
        new data_store, args[0][:scope]
      end

      def to_s
        "#<#{self.class} @data_store=#{@data_store} @scope=#{@scope}>"
      end

    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
asynchronic-3.0.3 lib/asynchronic/data_store/scoped_store.rb
asynchronic-3.0.2 lib/asynchronic/data_store/scoped_store.rb
asynchronic-3.0.1 lib/asynchronic/data_store/scoped_store.rb
asynchronic-3.0.0 lib/asynchronic/data_store/scoped_store.rb
asynchronic-2.0.1 lib/asynchronic/data_store/scoped_store.rb
asynchronic-2.0.0 lib/asynchronic/data_store/scoped_store.rb
asynchronic-1.6.3 lib/asynchronic/data_store/scoped_store.rb
asynchronic-1.6.2 lib/asynchronic/data_store/scoped_store.rb
asynchronic-1.6.1 lib/asynchronic/data_store/scoped_store.rb
asynchronic-1.6.0 lib/asynchronic/data_store/scoped_store.rb
asynchronic-1.5.2 lib/asynchronic/data_store/scoped_store.rb
asynchronic-1.5.1 lib/asynchronic/data_store/scoped_store.rb
asynchronic-1.5.0 lib/asynchronic/data_store/scoped_store.rb