Sha256: bc58790b31ab0c3a8bd47a509c62c28980a12a3c48b491a5f93945715b9b3313

Contents?: true

Size: 835 Bytes

Versions: 6

Compression:

Stored size: 835 Bytes

Contents

module SpiffyStoresApp
  class SessionRepository
    class ConfigurationError < StandardError; end

    class << self
      def storage=(storage)
        @storage = storage

        unless storage.nil? || self.storage.respond_to?(:store) && self.storage.respond_to?(:retrieve)
          raise ArgumentError, "storage must respond to :store and :retrieve"
        end
      end

      def retrieve(id)
        storage.retrieve(id)
      end

      def store(session)
        storage.store(session)
      end

      def storage
        load_storage || raise(ConfigurationError.new("SpiffyStoresSessionRepository.storage is not configured!"))
      end

      private

      def load_storage
        return unless @storage
        @storage.respond_to?(:safe_constantize) ? @storage.safe_constantize : @storage
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
spiffy_stores_app-8.2.11 lib/spiffy_stores_app/session/session_repository.rb
spiffy_stores_app-8.2.10 lib/spiffy_stores_app/session/session_repository.rb
spiffy_stores_app-8.2.9 lib/spiffy_stores_app/session/session_repository.rb
spiffy_stores_app-8.2.8 lib/spiffy_stores_app/session/session_repository.rb
spiffy_stores_app-8.2.7 lib/spiffy_stores_app/session/session_repository.rb
spiffy_stores_app-8.2.6 lib/spiffy_stores_app/session/session_repository.rb