Sha256: 48cfdef77628806e30ce12d97444ac20626764eecb055d9f28ab6e041bddd4a0

Contents?: true

Size: 823 Bytes

Versions: 1

Compression:

Stored size: 823 Bytes

Contents

# frozen_string_literal: true

module Cistern::Data
  def self.extended(klass)
    klass.send(:extend, ClassMethods)
    klass.send(:include, InstanceMethods)
  end

  def self.backends
    @backends ||= {}
  end

  def self.backend(*args, &block)
    engine, options = args

    Cistern::Data.backends[engine].new(options || {}, &block)
  end

  module ClassMethods
    def data
      @data ||= Cistern::Data.backend(*storage) { |d, k| d[k] = [] }
    end

    def reset!
      clear!
      @data = nil
    end

    def clear!
      data.clear
    end

    def store_in(*args, **kwargs)
      @storage = *args
      @data    = nil
    end

    def storage
      @storage ||= :hash
    end
  end

  module InstanceMethods
    def data
      self.class.data
    end

    def reset!
      self.class.reset!
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
cistern-2.10.0 lib/cistern/data.rb