Skip to content

Commit

Permalink
Use the begin/end blocks implicit in a method definition.
Browse files Browse the repository at this point in the history
  • Loading branch information
emmanuel committed Jan 4, 2012
1 parent 34ecddc commit b76610d
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 42 deletions.
12 changes: 5 additions & 7 deletions lib/webmachine/decision/conneg.rb
Expand Up @@ -226,13 +226,11 @@ class MediaTypeList < PriorityList
# {MediaType} items instead of Strings.
# @see PriorityList#add_header_val
def add_header_val(c)
begin
mt = MediaType.parse(c)
q = mt.params.delete('q') || 1.0
add(q.to_f, mt)
rescue ArgumentError
raise MalformedRequest, t('invalid_media_type', :type => c)
end
mt = MediaType.parse(c)
q = mt.params.delete('q') || 1.0
add(q.to_f, mt)
rescue ArgumentError
raise MalformedRequest, t('invalid_media_type', :type => c)
end
end
end
Expand Down
28 changes: 12 additions & 16 deletions lib/webmachine/decision/flow.rb
Expand Up @@ -254,14 +254,12 @@ def h10

# If-Unmodified-Since is valid date?
def h11
begin
date = Time.httpdate(request.if_unmodified_since)
metadata['If-Unmodified-Since'] = date
rescue ArgumentError
:i12
else
:h12
end
date = Time.httpdate(request.if_unmodified_since)
metadata['If-Unmodified-Since'] = date
rescue ArgumentError
:i12
else
:h12
end

# Last-Modified > I-UM-S?
Expand Down Expand Up @@ -351,14 +349,12 @@ def l13

# IMS is valid date?
def l14
begin
date = Time.httpdate(request.if_modified_since)
metadata['If-Modified-Since'] = date
rescue ArgumentError
:m16
else
:l15
end
date = Time.httpdate(request.if_modified_since)
metadata['If-Modified-Since'] = date
rescue ArgumentError
:m16
else
:l15
end

# IMS > Now?
Expand Down
36 changes: 17 additions & 19 deletions lib/webmachine/decision/fsm.rb
Expand Up @@ -20,27 +20,25 @@ def initialize(resource, request, response)

# Processes the request, iteratively invoking the decision methods in {Flow}.
def run
begin
state = Flow::START
loop do
response.trace << state
result = send(state)
case result
when Fixnum # Response code
respond(result)
break
when Symbol # Next state
state = result
else # You bwoke it
raise InvalidResource, t('fsm_broke', :state => state, :result => result.inspect)
end
state = Flow::START
loop do
response.trace << state
result = send(state)
case result
when Fixnum # Response code
respond(result)
break
when Symbol # Next state
state = result
else # You bwoke it
raise InvalidResource, t('fsm_broke', :state => state, :result => result.inspect)
end
rescue MalformedRequest => malformed
Webmachine.render_error(400, request, response, :message => malformed.message)
respond(400)
rescue => e # Handle all exceptions without crashing the server
error_response(e, state)
end
rescue MalformedRequest => malformed
Webmachine.render_error(400, request, response, :message => malformed.message)
respond(400)
rescue => e # Handle all exceptions without crashing the server
error_response(e, state)
end

private
Expand Down

0 comments on commit b76610d

Please sign in to comment.