Skip to content

Commit 86d0f0c

Browse files
committed
Apply rubocop rules (auto and manual fixes)
1 parent 083e757 commit 86d0f0c

File tree

21 files changed

+73
-62
lines changed

21 files changed

+73
-62
lines changed

lib/webmachine/adapter.rb

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
module Webmachine
2-
32
# The abstract class for definining a Webmachine adapter.
43
#
54
# @abstract Subclass and override {#run} to implement a custom adapter.
65
class Adapter
7-
86
# @return [Webmachine::Application] returns the application
97
attr_reader :application
108

@@ -25,6 +23,5 @@ def self.run(application)
2523
def run
2624
raise NotImplementedError
2725
end
28-
2926
end
3027
end

lib/webmachine/adapters/lazy_request_body.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def empty?
2424
# @yield [chunk]
2525
# @yieldparam [String] chunk a chunk of the request body
2626
def each
27-
@request.body {|chunk| yield chunk }
27+
@request.body { |chunk| yield chunk }
2828
end
2929
end # class RequestBody
3030
end # module Adapters

lib/webmachine/adapters/rack_mapped.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ module Adapters
2121
# end
2222
# end
2323
class RackMapped < Rack
24-
2524
protected
2625

2726
def routing_tokens(rack_req)

lib/webmachine/application.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class Application
4343
# the Application instance being initialized
4444
def initialize(configuration = Configuration.default, dispatcher = Dispatcher.new)
4545
@configuration = configuration
46-
@dispatcher = dispatcher
46+
@dispatcher = dispatcher
4747

4848
yield self if block_given?
4949
end
@@ -73,7 +73,7 @@ def adapter_class
7373
#
7474
# @see Webmachine::Dispatcher#add_route
7575
def routes(&block)
76-
if block_given?
76+
if block
7777
dispatcher.instance_eval(&block)
7878
self
7979
else

lib/webmachine/chunked_body.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def initialize(body)
2929
# parameter.
3030
# Returns an {Enumerator} if no block is given.
3131
def each
32-
return self.to_enum unless block_given?
32+
return to_enum unless block_given?
3333

3434
@body.each do |chunk|
3535
size = chunk.bytesize

lib/webmachine/decision/falsey.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,3 @@ def Falsey.===(other)
77
end
88
end
99
end
10-

lib/webmachine/dispatcher.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def add_route(*args, &block)
3333
@routes << route
3434
route
3535
end
36-
alias :add :add_route
36+
alias_method :add, :add_route
3737

3838
# Dispatches a request to the appropriate {Resource} in the
3939
# dispatch list. If a matching resource is not found, a "404 Not
@@ -72,10 +72,11 @@ def find_resource(request, response)
7272
# Find the first route that matches an incoming request
7373
# @param [Request] request the request to match
7474
def find_route(request)
75-
@routes.find {|r| r.match?(request) }
75+
@routes.find { |r| r.match?(request) }
7676
end
7777

7878
private
79+
7980
def prepare_resource(route, request, response)
8081
route.apply(request)
8182
@resource_creator.call(route, request, response)

lib/webmachine/dispatcher/route.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,21 @@ def self.rfc3986_percent_decode(value)
4343
result
4444
end
4545

46+
# Decode a string using the scheme described in RFC 3986 2.1. Percent-Encoding (https://www.ietf.org/rfc/rfc3986.txt)
47+
def self.rfc3986_percent_decode(value)
48+
s = StringScanner.new(value)
49+
result = ""
50+
until s.eos?
51+
encoded_val = s.scan(/%([0-9a-fA-F]){2}/)
52+
result << if encoded_val.nil?
53+
s.getch
54+
else
55+
[encoded_val[1..-1]].pack("H*")
56+
end
57+
end
58+
result
59+
end
60+
4661
# Creates a new Route that will associate a pattern to a
4762
# {Resource}.
4863
#

lib/webmachine/etags.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class ETag
1010

1111
def self.new(etag)
1212
return etag if ETag === etag
13-
klass = etag =~ WEAK_ETAG ? WeakETag : self
13+
klass = WEAK_ETAG.match?(etag) ? WeakETag : self
1414
klass.send(:allocate).tap do |obj|
1515
obj.send(:initialize, etag)
1616
end
@@ -53,6 +53,7 @@ def to_s
5353
end
5454

5555
private
56+
5657
def unquote(str)
5758
if str =~ WEAK_ETAG
5859
unescape_quotes $1

lib/webmachine/header_negotiation.rb

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,18 @@
33
module Webmachine
44
module HeaderNegotiation
55
def ensure_date_header(res)
6-
if (200..499).include?(res.code)
6+
if (200..499).cover?(res.code)
77
res.headers[DATE] ||= Time.now.httpdate
88
end
99
end
1010

1111
def ensure_content_length(res)
1212
body = res.body
13-
case
14-
when res.headers[TRANSFER_ENCODING]
15-
return
16-
when [204, 205, 304].include?(res.code)
13+
if res.headers[TRANSFER_ENCODING]
14+
nil
15+
elsif [204, 205, 304].include?(res.code)
1716
res.headers.delete CONTENT_LENGTH
18-
when body != nil
17+
elsif !body.nil?
1918
res.headers[CONTENT_LENGTH] = body.respond_to?(:bytesize) ? body.bytesize.to_s : body.length.to_s
2019
else
2120
res.headers[CONTENT_LENGTH] = '0'

0 commit comments

Comments
 (0)