Sha256: 37eb5c81a683b2fe7602ca88abcd44d69f36317a0647198cde77f0983d28f1ec

Contents?: true

Size: 928 Bytes

Versions: 2

Compression:

Stored size: 928 Bytes

Contents

# frozen_string_literal: true

require "hanami/utils/string"
require "hanami/utils/class"

module Hanami
  class Configuration
    # Hanami configuration for HTTP sessions
    #
    # @since 2.0.0
    class Sessions
      def self.null
        NULL_STORAGE
      end

      attr_reader :storage, :options

      def initialize(*args)
        storage, options, = Array(args.dup).flatten

        @storage = storage
        @options = options || {}
      end

      def enabled?
        storage != NULL_STORAGE
      end

      def middleware
        [[storage_middleware, options]]
      end

      private

      NULL_STORAGE = :null
      private_constant :NULL_STORAGE

      def storage_middleware
        require_storage

        name = Utils::String.classify(storage)
        Utils::Class.load!(name, Rack::Session)
      end

      def require_storage
        require "rack/session/#{storage}"
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
hanami-2.0.0.alpha2 lib/hanami/configuration/sessions.rb
hanami-2.0.0.alpha1 lib/hanami/configuration/sessions.rb