Permalink
Browse files

Use Rubocop and fix existing offences

  • Loading branch information...
1 parent 597792c commit 4a1f4ca3c1e0cffda983d3b5e76312bb66afb79f @hakanensari committed Oct 11, 2016
Showing with 40 additions and 13 deletions.
  1. +1 −0 Gemfile
  2. +14 −1 Gemfile.lock
  3. +3 −1 Rakefile
  4. +2 −0 config.ru
  5. +3 −1 config/unicorn.rb
  6. +3 −1 deploy/before_restart
  7. +1 −2 lib/currency.rb
  8. +3 −6 lib/quote.rb
  9. +5 −0 lib/tasks/rubocop.rake
  10. +3 −1 spec/converter_spec.rb
  11. +2 −0 spec/edge_cases_spec.rb
View
@@ -18,5 +18,6 @@ group :development do
gem 'minitest-around'
gem 'pry'
gem 'rack-test'
+ gem 'rubocop'
gem 'shotgun'
end
View
@@ -16,7 +16,10 @@ GEM
ast
ruby-ll (~> 2.1)
oj (2.15.1)
+ parser (2.3.1.4)
+ ast (~> 2.2)
pg (0.18.4)
+ powerpack (0.1.1)
pry (0.10.3)
coderay (~> 1.1.0)
method_source (~> 0.8.1)
@@ -27,11 +30,19 @@ GEM
rack
rack-test (0.6.3)
rack (>= 1.0)
+ rainbow (2.1.0)
raindrops (0.16.0)
rake (11.1.2)
+ rubocop (0.43.0)
+ parser (>= 2.3.1.1, < 3.0)
+ powerpack (~> 0.1)
+ rainbow (>= 1.99.1, < 3.0)
+ ruby-progressbar (~> 1.7)
+ unicode-display_width (~> 1.0, >= 1.0.1)
ruby-ll (2.1.2)
ansi
ast
+ ruby-progressbar (1.8.1)
sequel (4.35.0)
sequel_pg (1.6.17)
pg (>= 0.8.0)
@@ -44,6 +55,7 @@ GEM
tilt (>= 1.3, < 3)
slop (3.6.0)
tilt (2.0.5)
+ unicode-display_width (1.1.1)
unicorn (5.1.0)
kgio (~> 2.6)
raindrops (~> 0.7)
@@ -61,6 +73,7 @@ DEPENDENCIES
rack-cors
rack-test
rake
+ rubocop
sequel_pg
shotgun
sinatra
@@ -70,4 +83,4 @@ RUBY VERSION
ruby 2.3.1p112
BUNDLED WITH
- 1.12.3
+ 1.13.6
View
@@ -1,2 +1,4 @@
+# frozen_string_literal: true
+
Dir.glob('lib/tasks/*.rake').each { |r| import r }
-task default: %w(db:migrate rates:load test)
+task default: %w(db:migrate rates:load test rubocop)
View
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
require './config/environment'
require 'api'
View
@@ -1,7 +1,9 @@
# frozen_string_literal: true
+worker_process_count = (ENV['WORKER_PROCESSES'] || 4).to_i
+
preload_app true
-worker_processes((ENV['WORKER_PROCESSES'] || 4).to_i)
+worker_processes worker_process_count
timeout 10
before_fork do |_, _|
@@ -1,4 +1,6 @@
#!/usr/bin/env ruby
+# frozen_string_literal: true
+
oldrev, newrev = ARGV
def run(cmd)
@@ -10,7 +12,7 @@ run 'whenever --update-crontab'
tasks = []
num_migrations = `git diff #{oldrev} #{newrev} --diff-filter=A --name-only -z db/migrate`.split("\0").size
-tasks << 'db:migrate' if num_migrations > 0
+tasks << 'db:migrate' if num_migrations.positive?
tasks << 'rates:load'
run "foreman run bundle exec rake #{tasks.join(' ')}"
View
@@ -11,8 +11,7 @@ def before(value)
end
def current_date
- currency = recent.first
- currency.date if currency
+ recent.first&.date
end
def current_date_before(value)
View
@@ -27,19 +27,16 @@ def attributes
private
def base=(base)
- @base = base ? base.upcase : DEFAULT_BASE
+ @base = base&.upcase || DEFAULT_BASE
end
def date=(date)
current_date = date ? Currency.current_date_before(date) : Currency.current_date
raise Invalid, 'Date too old' unless current_date
@date = current_date
rescue Sequel::DatabaseError => ex
- if ex.wrapped_exception.is_a?(PG::DataException)
- raise Invalid, 'Invalid date'
- else
- raise
- end
+ raise Invalid, 'Invalid date' if ex.wrapped_exception.is_a?(PG::DataException)
+ raise
end
def find_rates
@@ -0,0 +1,5 @@
+# frozen_string_literal: true
+
+require 'rubocop/rake_task'
+
+RuboCop::RakeTask.new
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
require_relative 'helper'
require 'converter'
@@ -29,7 +31,7 @@
end
it 'should raise with invalid currency' do
- quote.stub :rates, Hash.new do
+ quote.stub :rates, {} do
-> { converter.convert(quote) }.must_raise Quote::Invalid, 'Invalid to'
end
end
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
require_relative 'helper'
require 'rack/test'
require 'api'

0 comments on commit 4a1f4ca

Please sign in to comment.