Skip to content

Commit

Permalink
More docs for yard
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander Kern committed Apr 18, 2011
1 parent 3db5ee7 commit d989ad2
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 31 deletions.
3 changes: 3 additions & 0 deletions .yardopts
@@ -0,0 +1,3 @@
--readme README.md
--markup markdown
--markup-provider maruku
6 changes: 5 additions & 1 deletion Gemfile.lock
Expand Up @@ -8,17 +8,21 @@ GEM
remote: http://rubygems.org/
specs:
ZenTest (4.5.0)
addressable (2.2.4)
addressable (2.2.5)
autotest (4.4.6)
ZenTest (>= 4.4.1)
maruku (0.6.0)
syntax (>= 1.0.0)
minitest (2.0.2)
mocha (0.9.12)
syntax (1.0.0)

PLATFORMS
ruby

DEPENDENCIES
autotest (~> 4.4)
maruku (~> 0.6)
minitest (~> 2.0)
mocha (~> 0.9)
webbed!
19 changes: 18 additions & 1 deletion lib/webbed/generic_message.rb
@@ -1,6 +1,20 @@
module Webbed
# Generic methods used for both {Request}'s and {Response}'s.
# @abstract
module GenericMessage
attr_reader :headers, :http_version
# Returns the HTTP Version of the message.
#
# Automatically converts the HTTP Version to an instance of {HTTPVersion} if
# it is not already one.
attr_reader :http_version

# Returns the headers of the message.
#
# Automatically converts the headers to an instance of {Headers} if it
# is not already one.
attr_reader :headers

# Returns the entity body of the message.
attr_accessor :entity_body

def headers=(headers)
Expand All @@ -11,6 +25,9 @@ def http_version=(http_version)
@http_version = Webbed::HTTPVersion.new(http_version)
end

# Convert the message into an HTTP message as per RFC 2616.
#
# @return [String] the HTTP message
def to_s
"#{start_line}#{headers.to_s}\r\n#{entity_body}"
end
Expand Down
52 changes: 23 additions & 29 deletions lib/webbed/http_version.rb
@@ -1,30 +1,27 @@
module Webbed
# Webbed supports both primary versions of HTTP, HTTP/1.0 and HTTP/1.1.
# {Webbed} supports both primary versions of HTTP, HTTP/1.0 and HTTP/1.1.
# Although the use of HTTP/1.1 has been strongly encouraged since its creation
# in 1999, it remains relatively common for older command line tools (such as
# wget) and some search engines. Webbed can also be extended in the future to
# support new versions of HTTP, should one ever come into existence.
#
# {Webbed::HTTPVersion} is a small abstraction on top of the HTTP-Version as
# defined in RFC 2616. According to the RFC, its simple format is:
# {HTTPVersion} is a small abstraction on top of the HTTP-Version as defined
# in RFC 2616. According to the RFC, its simple format is:
#
# HTTP-Version = "HTTP" "/" 1*DIGIT "." 1*DIGIT
# HTTP-Version = "HTTP" "/" 1*DIGIT "." 1*DIGIT
#
# While this is perhaps the simplest of all the abstractions in Webbed, it
# While this is perhaps the simplest of all the abstractions in {Webbed}, it
# does offer some nice helper methods for treating the version string more
# Ruby-like.
#
# HTTP/1.0 and HTTP/1.1 HTTPVersions are cached. In every case I can think of,
# you will not have to create a new HTTPVersion, just use the constants
# {Webbed::HTTPVersion::ONE_POINT_OH} and {Webbed::HTTPVersion::ONE_POINT_ONE}
# when creating messages.
#
# @author Alexander Kern
# HTTP/1.0 and HTTP/1.1 {HTTPVersion}'s are cached. In every case I can think
# of, you will not have to create a new {HTTPVersion}, just use the constants
# {ONE_POINT_OH} and {ONE_POINT_ONE} when creating messages.
class HTTPVersion
include Comparable
REGEX = /^HTTP\/(\d+\.\d+)$/

# Creates a new HTTP-Version.
# Creates a new {HTTPVersion}.
#
# Only HTTP/1.0 and HTTP/1.1 versions are cached. All other versions will be
# created at runtime each time this method is called.
Expand All @@ -33,8 +30,8 @@ class HTTPVersion
# Webbed::HTTPVersion.new(1.1)
# Webbed::HTTPVersion.new('HTTP/1.1')
#
# @param [#match, #to_f] http_version The HTTP-Version to create
# @return [Webbed::HTTPVersion] The new HTTPVersion
# @param http_version [#match, #to_f] the {HTTPVersion} to create
# @return [HTTPVersion] the new {HTTPVersion}
def initialize(http_version)
if REGEX =~ http_version.to_s
@http_version = $1.to_f
Expand All @@ -43,58 +40,55 @@ def initialize(http_version)
end
end

# Converts to String according to RFC 2616.
# Converts to a string according to RFC 2616.
#
# @example
# version = Webbed::HTTPVersion.new(1.1)
# version.to_s # => 'HTTP/1.1'
#
# @return [String] The stringified HTTP-Version
# @return [String] the string {HTTPVersion}
def to_s
"HTTP/#{to_f}"
end

# Converts to float.
# Converts to a float.
#
# @example
# version = Webbed::HTTPVersion.new('HTTP/1.1')
# version.to_f # => 1.1
#
# @return [Float] The float-ified HTTP-Version
# @return [Float] the float {HTTPVersion}
def to_f
@http_version
end

# Compare to another HTTP-Version.
#
# You'll rarely directly use this method. It does, however, allow you to use
# all the fun little things that the Comparable has to offer. This includes
# checking for equality and sorting. Fun fun fun!
#
# @param [#to_f] other The other HTTP-Version to compare against
# Compares to another {HTTPVersion}.
#
# @example
# version_1_1 = Webbed::HTTPVersion.new(1.1)
# version_5_0 = Webbed::HTTPVersion.new('HTTP/5.0')
# version_1_1 == version_5_0 # => false
# version_5_0 < version_5_0 # => false
# version_5_0 > version_1_1 # => true
#
# @param other [#to_f] the other {HTTPVersion} to compare against
# @return [Integer] the sign of the comparison (either `1`, `0`, or `-1`)
def <=>(other)
to_f <=> other.to_f
end

# Major HTTP-Version number as an integer.
# Returns the major HTTP-Version number as an integer.
#
# @example
# version = Webbed::HTTPVersion.new('HTTP/6.9')
# version.major # => 6
#
# @return [Fixnum] Major HTTP-Version number
# @return [Fixnum] major HTTP-Version number
def major
to_f.floor
end

# Minor HTTP-Version number as an integer.
# Return the minor HTTP-Version number as an integer.
#
# Right now this is a pretty big hack since the HTTP-Version is internally
# stored as a float. Ruby does not natively offer a way to get the string of
Expand All @@ -107,7 +101,7 @@ def major
# version = Webbed::HTTPVersion.new('HTTP/4.2')
# version.minor # => 2
#
# @return [Fixnum] Minor HTTP-Version number
# @return [Fixnum] minor HTTP-Version number
def minor
to_f.to_s.split('.')[1].to_i
end
Expand Down
1 change: 1 addition & 0 deletions lib/webbed/version.rb
@@ -1,3 +1,4 @@
module Webbed
# Webbed version number
VERSION = '0.1.1'
end
1 change: 1 addition & 0 deletions webbed.gemspec
Expand Up @@ -19,6 +19,7 @@ Gem::Specification.new do |s|
s.add_development_dependency 'minitest', '~> 2.0'
s.add_development_dependency 'mocha', '~> 0.9'
s.add_development_dependency 'autotest', '~> 4.4'
s.add_development_dependency 'maruku', '~> 0.6'

s.files = `git ls-files`.split("\n")
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
Expand Down

0 comments on commit d989ad2

Please sign in to comment.