Skip to content

Commit

Permalink
Merge pull request #170 from tarcieri/improvement/expose-readpartial-…
Browse files Browse the repository at this point in the history
…on-response

Delegate `Response#readpartial` to `#body`
  • Loading branch information
tarcieri committed Jan 1, 2015
2 parents b144b32 + ce3c5b0 commit 020969a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 11 deletions.
2 changes: 1 addition & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ end
require 'yardstick/rake/verify'
Yardstick::Rake::Verify.new do |verify|
verify.require_exact_threshold = false
verify.threshold = 59.2
verify.threshold = 58.8
end

task :default => [:spec, :rubocop, :verify_measurements]
28 changes: 18 additions & 10 deletions lib/http/response.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,13 @@ class Response
# @deprecated Will be removed in 1.0.0
SYMBOL_TO_STATUS_CODE = Hash[STATUS_CODES.map { |k, v| [v.downcase.gsub(/\s|-/, '_').to_sym, k] }].freeze

# @return [Status]
attr_reader :status

# @return [Body]
attr_reader :body

# @return [URI, nil]
attr_reader :uri

def initialize(status, version, headers, body, uri = nil) # rubocop:disable ParameterLists
Expand All @@ -29,30 +34,33 @@ def initialize(status, version, headers, body, uri = nil) # rubocop:disable Para
@headers = HTTP::Headers.coerce(headers || {})
end

# (see Status#reason)
# @!attribute reason
# (see Status#reason)
def_delegator :status, :reason

# (see Status#code)
# @!attribute code
# (see Status#code)
def_delegator :status, :code

# @deprecated Will be removed in 1.0.0
alias_method :status_code, :code

# @!method to_s
# (see Body#to_s)
def_delegator :body, :to_s
alias_method :to_str, :to_s

# @!method readpartial
# (see Body#readpartial)
def_delegator :body, :readpartial

# Returns an Array ala Rack: `[status, headers, body]`
#
# @return [Array(Fixnum, Hash, String)]
def to_a
[status.to_i, headers.to_h, body.to_s]
end

# Return the response body as a string
#
# @return [String]
def to_s
body.to_s
end
alias_method :to_str, :to_s

# Flushes body and returns self-reference
#
# @return [Response]
Expand Down

0 comments on commit 020969a

Please sign in to comment.