Sha256: e462c528587d6d2c8665c0ae469b6ccac4caafa107e0ec0ad09ee3c65bd799b9

Contents?: true

Size: 859 Bytes

Versions: 32

Compression:

Stored size: 859 Bytes

Contents

# frozen-string-literal: true

require 'rack/utils'

class Roda
  module RodaPlugins
    # The symbol_status plugin patches the +status=+ response method to
    # accept the status name as a symbol.  If given an integer value,
    # the default behaviour is used.
    #
    # Examples:
    #   r.is "needs_authorization" do
    #     response.status = :unauthorized
    #   end
    #   r.is "nothing" do
    #     response.status = :no_content
    #   end
    #
    # The conversion is done through <tt>Rack::Utils.status_code</tt>.
    module SymbolStatus
      module ResponseMethods
        # Sets the response status code by fixnum or symbol name
        def status=(code)
          code = Rack::Utils.status_code(code) if code.is_a?(Symbol)
          super(code)
        end
      end
    end

    register_plugin(:symbol_status, SymbolStatus)
  end
end

Version data entries

32 entries across 32 versions & 1 rubygems

Version Path
roda-3.67.0 lib/roda/plugins/symbol_status.rb
roda-3.66.0 lib/roda/plugins/symbol_status.rb
roda-3.65.0 lib/roda/plugins/symbol_status.rb
roda-3.64.0 lib/roda/plugins/symbol_status.rb
roda-3.63.0 lib/roda/plugins/symbol_status.rb
roda-3.62.0 lib/roda/plugins/symbol_status.rb
roda-3.61.0 lib/roda/plugins/symbol_status.rb
roda-3.60.0 lib/roda/plugins/symbol_status.rb
roda-3.59.0 lib/roda/plugins/symbol_status.rb
roda-3.58.0 lib/roda/plugins/symbol_status.rb
roda-3.57.0 lib/roda/plugins/symbol_status.rb
roda-3.56.0 lib/roda/plugins/symbol_status.rb