Sha256: 2664e1455e26d0a76eea7da911aeb86c25a3937f92ca20b16aa7a7c437082c48

Contents?: true

Size: 922 Bytes

Versions: 5

Compression:

Stored size: 922 Bytes

Contents

# frozen_string_literal: true

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

module Hanami
  class Action
    class ApplicationConfiguration
      # Configuration 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

5 entries across 5 versions & 1 rubygems

Version Path
hanami-controller-2.0.0.alpha6 lib/hanami/action/application_configuration/sessions.rb
hanami-controller-2.0.0.alpha5 lib/hanami/action/application_configuration/sessions.rb
hanami-controller-2.0.0.alpha4 lib/hanami/action/application_configuration/sessions.rb
hanami-controller-2.0.0.alpha3 lib/hanami/action/application_configuration/sessions.rb
hanami-controller-2.0.0.alpha2 lib/hanami/action/application_configuration/sessions.rb