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.88.0 lib/roda/plugins/symbol_status.rb
roda-3.87.0 lib/roda/plugins/symbol_status.rb
roda-3.86.0 lib/roda/plugins/symbol_status.rb
roda-3.85.0 lib/roda/plugins/symbol_status.rb
roda-3.84.0 lib/roda/plugins/symbol_status.rb
roda-3.83.0 lib/roda/plugins/symbol_status.rb
roda-3.82.0 lib/roda/plugins/symbol_status.rb
roda-3.81.0 lib/roda/plugins/symbol_status.rb
roda-3.79.0 lib/roda/plugins/symbol_status.rb
roda-3.78.0 lib/roda/plugins/symbol_status.rb
roda-3.77.0 lib/roda/plugins/symbol_status.rb
roda-3.76.0 lib/roda/plugins/symbol_status.rb
roda-3.75.0 lib/roda/plugins/symbol_status.rb
roda-3.74.0 lib/roda/plugins/symbol_status.rb
roda-3.73.0 lib/roda/plugins/symbol_status.rb
roda-3.72.0 lib/roda/plugins/symbol_status.rb
roda-3.71.0 lib/roda/plugins/symbol_status.rb
roda-3.70.0 lib/roda/plugins/symbol_status.rb
roda-3.69.0 lib/roda/plugins/symbol_status.rb
roda-3.68.0 lib/roda/plugins/symbol_status.rb