Sha256: 3b99fb663f40de567cc63285e0d86336e8675a24aa255f14525f680c4af2de71

Contents?: true

Size: 1.01 KB

Versions: 1

Compression:

Stored size: 1.01 KB

Contents

# frozen_string_literal: true

require "hanami/action/flash"

module Hanami
  class Action
    # Session support for actions.
    #
    # Not included by default; you should include this module manually to enable session support.
    # For actions within an Hanami app, this module will be included automatically if sessions are
    # configured in the app config.
    #
    # @api public
    # @since 0.1.0
    module Session
      # @api private
      # @since 0.1.0
      def self.included(base)
        base.class_eval do
          before { |req, _| req.id }
        end
      end

      private

      def sessions_enabled?
        true
      end

      # Finalize the response
      #
      # @return [void]
      #
      # @since 0.3.0
      # @api private
      #
      # @see Hanami::Action#finish
      def finish(req, res, *)
        if (next_flash = res.flash.next).any?
          res.session[Flash::KEY] = next_flash
        else
          res.session.delete(Flash::KEY)
        end

        super
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
hanami-controller-2.0.0.rc1 lib/hanami/action/session.rb