Skip to content
Browse files

Use the begin/end blocks implicit in a method definition.

  • Loading branch information...
1 parent 34ecddc commit b76610dbbfcff2e985843a0c73cd014d1ac05131 @emmanuel committed
Showing with 34 additions and 42 deletions.
  1. +5 −7 lib/webmachine/decision/conneg.rb
  2. +12 −16 lib/webmachine/decision/flow.rb
  3. +17 −19 lib/webmachine/decision/fsm.rb
View
12 lib/webmachine/decision/conneg.rb
@@ -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
View
28 lib/webmachine/decision/flow.rb
@@ -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?
@@ -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?
View
36 lib/webmachine/decision/fsm.rb
@@ -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

0 comments on commit b76610d

Please sign in to comment.
Something went wrong with that request. Please try again.