Sha256: 4adac2229a22bd6b7407e9c54f66b99a474d5df044d11e785a146875046f383f

Contents?: true

Size: 920 Bytes

Versions: 4

Compression:

Stored size: 920 Bytes

Contents

require 'aldous/respondable/base'
require 'aldous/respondable/shared/flash'

module Aldous
  module Respondable
    class Redirectable < Base
      def action(controller)
        RedirectAction.new(location, controller, view_data, status)
      end

      def location
        raise Errors::UserError.new("Redirectable objects must define a 'location' method")
      end

      def default_status
        :found
      end

      private

      class RedirectAction
        attr_reader :controller, :view_data, :location, :status

        def initialize(location, controller, view_data, status)
          @location = location
          @controller = controller
          @view_data = view_data
          @status = status
        end

        def execute
          Shared::Flash.new(view_data, controller.flash).set_error
          controller.redirect_to location, {status: status}
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
aldous-1.1.3 lib/aldous/respondable/redirectable.rb
aldous-1.1.2 lib/aldous/respondable/redirectable.rb
aldous-1.0.1 lib/aldous/respondable/redirectable.rb
aldous-1.0.0 lib/aldous/respondable/redirectable.rb