Sha256: fcf528f105dd1c65e2c53e22906c8547771521d12ba5b3f33aafb2fe484edf54

Contents?: true

Size: 970 Bytes

Versions: 4

Compression:

Stored size: 970 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
      NULL_SESSION_OPTION = :null
      private_constant :NULL_SESSION_OPTION

      def self.null
        self.class.new(NULL_SESSION_OPTION)
      end

      attr_reader :storage, :options

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

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

      def enabled?
        storage != NULL_SESSION_OPTION
      end

      def middleware
        [storage_middleware, options]
      end

      private

      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

4 entries across 4 versions & 1 rubygems

Version Path
hanami-2.0.0.beta3 lib/hanami/configuration/sessions.rb
hanami-2.0.0.beta2 lib/hanami/configuration/sessions.rb
hanami-2.0.0.beta1.1 lib/hanami/configuration/sessions.rb
hanami-2.0.0.beta1 lib/hanami/configuration/sessions.rb