Module: Taro::StatusCode

Defined in:
lib/taro/status_code.rb

Class Method Summary collapse

Class Method Details

.coerce_to_int(arg) ⇒ Object



4
5
6
7
8
9
10
11
# File 'lib/taro/status_code.rb', line 4

def self.coerce_to_int(arg)
  # support using http status numbers directly
  return arg if ::Rack::Utils::SYMBOL_TO_STATUS_CODE.key(arg)

  # support using symbols, but coerce them to numbers
  ::Rack::Utils::SYMBOL_TO_STATUS_CODE[arg] ||
    raise(Taro::ArgumentError, "Invalid status: #{arg.inspect}")
end

.coerce_to_message(arg) ⇒ Object



13
14
15
# File 'lib/taro/status_code.rb', line 13

def self.coerce_to_message(arg)
  ::Rack::Utils::HTTP_STATUS_CODES.fetch(coerce_to_int(arg))
end