Sha256: a53cf79e7f86607a12a5d3d09a87087b2d611f26a8cf60adba7e2dc11e2d0f53

Contents?: true

Size: 712 Bytes

Versions: 11

Compression:

Stored size: 712 Bytes

Contents

module Restspec
  module Values
    # A value object that transforms a http status code (201) or
    # a symbol with the status code message (:created) to a simple
    # number (201).
    class StatusCode
      def initialize(number_or_symbol)
        self.number_or_symbol = number_or_symbol
      end

      # @example
      #   StatusCode.new(201).value # 201
      #   StatusCode.new(:created).value # 201
      # @return [Fixnum] the status code
      def value
        if number_or_symbol.is_a?(Symbol)
          Rack::Utils::SYMBOL_TO_STATUS_CODE.fetch(number_or_symbol)
        else
          number_or_symbol
        end
      end

      private

      attr_accessor :number_or_symbol
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
restspec-0.3.2 lib/restspec/values/status_code.rb
restspec-0.3.1 lib/restspec/values/status_code.rb
restspec-0.3.0 lib/restspec/values/status_code.rb
restspec-0.2.6 lib/restspec/values/status_code.rb
restspec-0.2.5 lib/restspec/values/status_code.rb
restspec-0.2.4 lib/restspec/values/status_code.rb
restspec-0.2.3 lib/restspec/values/status_code.rb
restspec-0.2.2 lib/restspec/values/status_code.rb
restspec-0.2.1 lib/restspec/values/status_code.rb
restspec-0.2 lib/restspec/values/status_code.rb
restspec-0.1 lib/restspec/values/status_code.rb