Sha256: f7fa0a585bf211e89e5d47d08af454f6efafb84dba1e621c250955f4d2beaf5c

Contents?: true

Size: 898 Bytes

Versions: 1

Compression:

Stored size: 898 Bytes

Contents

# frozen_string_literal: true

require "dry/core/constants"
require "hanami/utils/string"
require "hanami/utils/class"

module Hanami
  class Config
    class Actions
      # Config for HTTP sessions in Hanami actions
      #
      # @since 2.0.0
      class Sessions
        attr_reader :storage, :options

        def initialize(storage = nil, *options)
          @storage = storage
          @options = options
        end

        def enabled?
          !storage.nil?
        end

        def middleware
          return [] if !enabled?

          [[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
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
hanami-2.0.0.beta4 lib/hanami/config/actions/sessions.rb