Skip to content

Commit

Permalink
Update devtools
Browse files Browse the repository at this point in the history
* Fix rubocop warnings
* Fix rspec warnings
* Update flay score
  • Loading branch information
snusnu committed Jan 19, 2015
1 parent b151ce5 commit d2717f5
Show file tree
Hide file tree
Showing 12 changed files with 154 additions and 100 deletions.
6 changes: 6 additions & 0 deletions .rubocop.yml
@@ -0,0 +1,6 @@
AllCops:
Include:
- 'Gemfile'
Exclude:
- 'vendor/**/*'
- 'benchmarks/**/*'
3 changes: 1 addition & 2 deletions Gemfile
Expand Up @@ -2,5 +2,4 @@ source 'https://rubygems.org'

gemspec

gem 'devtools', :git => 'https://github.com/rom-rb/devtools.git'
eval File.read('Gemfile.devtools')
gem 'devtools', git: 'https://github.com/mbj/devtools.git', branch: 'master'
71 changes: 0 additions & 71 deletions Gemfile.devtools

This file was deleted.

2 changes: 1 addition & 1 deletion config/flay.yml
@@ -1,3 +1,3 @@
---
threshold: 12
total_score: 74
total_score: 72
113 changes: 113 additions & 0 deletions config/rubocop.yml
@@ -0,0 +1,113 @@
inherit_from: ../.rubocop.yml

# Avoid parameter lists longer than five parameters.
ParameterLists:
Max: 3
CountKeywordArgs: true

# Avoid more than `Max` levels of nesting.
BlockNesting:
Max: 3

# Align with the style guide.
CollectionMethods:
PreferredMethods:
collect: 'map'
inject: 'reduce'
find: 'detect'
find_all: 'select'

# Do not force public/protected/private keyword to be indented at the same
# level as the def keyword. My personal preference is to outdent these keywords
# because I think when scanning code it makes it easier to identify the
# sections of code and visually separate them. When the keyword is at the same
# level I think it sort of blends in with the def keywords and makes it harder
# to scan the code and see where the sections are.
AccessModifierIndentation:
Enabled: false

# Limit line length
LineLength:
Max: 106

# Disable documentation checking until a class needs to be documented once
Documentation:
Enabled: false

# Do not always use &&/|| instead of and/or.
AndOr:
Enabled: false

# Do not favor modifier if/unless usage when you have a single-line body
IfUnlessModifier:
Enabled: false

# Allow case equality operator (in limited use within the specs)
CaseEquality:
Enabled: false

# Constants do not always have to use SCREAMING_SNAKE_CASE
ConstantName:
Enabled: false

# Not all trivial readers/writers can be defined with attr_* methods
TrivialAccessors:
Enabled: false

# Allow empty lines around class body
EmptyLinesAroundClassBody:
Enabled: false

# Allow empty lines around module body
EmptyLinesAroundModuleBody:
Enabled: false

# Allow empty lines around block body
EmptyLinesAroundBlockBody:
Enabled: false

# Allow multiple line operations to not require indentation
MultilineOperationIndentation:
Enabled: false

# Prefer String#% over Kernel#sprintf
FormatString:
Enabled: false

# Use square brackets for literal Array objects
PercentLiteralDelimiters:
PreferredDelimiters:
'%': '{}'
'%i': '[]'
'%q': ()
'%Q': ()
'%r': '{}'
'%s': ()
'%w': '[]'
'%W': '[]'
'%x': ()

# Align if/else blocks with the variable assignment
EndAlignment:
AlignWith: variable

# Do not always align parameters when it is easier to read
AlignParameters:
Exclude:
- spec/**/*_spec.rb

# Prefer #kind_of? over #is_a?
ClassCheck:
EnforcedStyle: kind_of?

# Do not prefer double quotes to be used when %q or %Q is more appropriate
UnneededPercentQ:
Enabled: false

# Allow a maximum ABC score
Metrics/AbcSize:
Max: 21.02

# Do not prefer lambda.call(...) over lambda.(...)
LambdaCall:
Enabled: false
27 changes: 18 additions & 9 deletions lib/request.rb
Expand Up @@ -9,13 +9,22 @@
# Library namespace and abstract base class
class Request

KEYS = %W(
path_info protocol port request_method
host if_modified_since query_params query_params_hash
query_string content_length content_type body
).map(&:to_sym).freeze

METHODS = (KEYS + %W(rack_env get? post?)).map(&:to_sym).freeze
KEYS = %w[
path_info
protocol
port
request_method
host
if_modified_since
query_params
query_params_hash
query_string
content_length
content_type
body
].map(&:to_sym).freeze

METHODS = (KEYS + %w[rack_env get? post?]).map(&:to_sym).freeze

include Adamantium::Flat, AbstractType, Equalizer.new(*KEYS)

Expand Down Expand Up @@ -98,7 +107,7 @@ def uid
#
def query_params_hash
query_params.each_with_object({}) do |(key, value), hash|
hash[key]=value
hash[key] = value
end
end
memoize :query_params_hash
Expand Down Expand Up @@ -153,7 +162,7 @@ def root_uri
# @api private
#
def host_with_port
uhost, uport = self.host, self.port
uhost, uport = host, port
if port != protocol.default_port
"#{uhost}:#{uport}"
else
Expand Down
2 changes: 1 addition & 1 deletion lib/request/method.rb
Expand Up @@ -22,7 +22,7 @@ class Method
attr_reader :verb

INDEX = ALL.each_with_object({}) do |method, index|
index[method.verb]=method
index[method.verb] = method
end.freeze

# Return request method
Expand Down
14 changes: 7 additions & 7 deletions lib/request/rack.rb
Expand Up @@ -94,7 +94,7 @@ def content_length
end

unless value =~ CONTENT_LENGTH_REGEXP
raise InvalidKeyError, 'invalid content length'
fail InvalidKeyError, 'invalid content length'
end

value.to_i
Expand Down Expand Up @@ -125,18 +125,18 @@ def query_params
def if_modified_since
value = @rack_env.fetch(IF_MODIFIED_SINCE) { return }
begin
Time.httpdate(value)
rescue ArgumentError
Time.httpdate(value)
rescue ArgumentError
nil
end
end
memoize :if_modified_since

accessor(:path_info, Key.new('PATH_INFO') )
accessor(:host, Key.new('SERVER_NAME') )
accessor(:query_string, Key.new('QUERY_STRING') )
accessor(:path_info, Key.new('PATH_INFO'))
accessor(:host, Key.new('SERVER_NAME'))
accessor(:query_string, Key.new('QUERY_STRING'))
accessor(:content_type, Key.new('CONTENT_TYPE'), nil)
accessor(:body, Key.new('rack.input') )
accessor(:body, Key.new('rack.input'))

private

Expand Down
2 changes: 1 addition & 1 deletion spec/shared/rack_env_accessor_behavior.rb
Expand Up @@ -23,7 +23,7 @@

it 'should not freeze the input env' do
subject
env.frozen?.should be(false)
expect(env.frozen?).to be(false)
end
end

Expand Down
6 changes: 2 additions & 4 deletions spec/spec_helper.rb
@@ -1,8 +1,6 @@
# encoding: utf-8

require 'request'
require 'devtools'
Devtools.init_spec_helper
require 'request'

RSpec.configure do |config|
end
Devtools.init_spec_helper
4 changes: 2 additions & 2 deletions spec/unit/request/key/hash_spec.rb
Expand Up @@ -3,7 +3,7 @@
describe Request::Key, '#hash' do
subject { described_class.new(string).hash }

let(:string) { "teststring" }
let(:string) { 'teststring' }

it { should == string.hash }
end
end
4 changes: 2 additions & 2 deletions spec/unit/request/rack/content_length_spec.rb
Expand Up @@ -3,7 +3,7 @@
describe Request::Rack, '#content_length' do
subject { object.content_length }

let(:rack_key) { 'CONTENT_LENGTH'}
let(:rack_key) { 'CONTENT_LENGTH' }

context 'with decimal positive integer' do
it_should_behave_like 'a rack env accessor' do
Expand Down Expand Up @@ -40,7 +40,7 @@

it_should_behave_like 'a rack env accessor' do

let(:expected_value) { 0 }
let(:expected_value) { 0 }

end
end
Expand Down

0 comments on commit d2717f5

Please sign in to comment.