Sha256: f6fd66416063806173ac5882913d54cfa0f8b059a4d6540a7a8c2556f45b3f4f

Contents?: true

Size: 972 Bytes

Versions: 7

Compression:

Stored size: 972 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

7 entries across 7 versions & 1 rubygems

Version Path
hanami-2.0.0.alpha8 lib/hanami/configuration/sessions.rb
hanami-2.0.0.alpha7.1 lib/hanami/configuration/sessions.rb
hanami-2.0.0.alpha7 lib/hanami/configuration/sessions.rb
hanami-2.0.0.alpha6 lib/hanami/configuration/sessions.rb
hanami-2.0.0.alpha5 lib/hanami/configuration/sessions.rb
hanami-2.0.0.alpha4 lib/hanami/configuration/sessions.rb
hanami-2.0.0.alpha3 lib/hanami/configuration/sessions.rb