Sha256: 83a0369dd299f96d37a023ebc60ea747c4bf2e909ca3e19c978f2a88e2a7dda8

Contents?: true

Size: 973 Bytes

Versions: 5

Compression:

Stored size: 973 Bytes

Contents

# frozen_string_literal: true
module Split
  module Persistence
    class DualAdapter
      extend Forwardable
      def_delegators :@adapter, :keys, :[], :[]=, :delete

      def initialize(context)
        if logged_in = self.class.config[:logged_in]
        else
          raise "Please configure :logged_in"
        end
        if logged_in_adapter = self.class.config[:logged_in_adapter]
        else
          raise "Please configure :logged_in_adapter"
        end
        if logged_out_adapter = self.class.config[:logged_out_adapter]
        else
          raise "Please configure :logged_out_adapter"
        end

        if logged_in.call(context)
          @adapter = logged_in_adapter.new(context)
        else
          @adapter = logged_out_adapter.new(context)
        end
      end

      def self.with_config(options={})
        self.config.merge!(options)
        self
      end

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

    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
split-2.2.0 lib/split/persistence/dual_adapter.rb
split-2.1.0 lib/split/persistence/dual_adapter.rb
split-2.0.0 lib/split/persistence/dual_adapter.rb
split-1.7.0 lib/split/persistence/dual_adapter.rb
split-1.6.0 lib/split/persistence/dual_adapter.rb