diff --git a/.pryrc b/.pryrc index d158c4a..f79751e 100644 --- a/.pryrc +++ b/.pryrc @@ -1,3 +1,5 @@ +# frozen_string_literal: true + Pry.config.editor = 'vim' require './config/environment' puts "Loading #{App.env}" diff --git a/Rakefile b/Rakefile index 99d54cd..358da59 100644 --- a/Rakefile +++ b/Rakefile @@ -1,2 +1,3 @@ # frozen_string_literal: true + Dir.glob('lib/tasks/*.rake').each { |r| import r } diff --git a/config/app.rb b/config/app.rb index 121d530..9b87fba 100644 --- a/config/app.rb +++ b/config/app.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require 'pathname' # Encapsulates app configuration diff --git a/config/environment.rb b/config/environment.rb index 352574a..578fb8c 100644 --- a/config/environment.rb +++ b/config/environment.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require_relative 'app' $LOAD_PATH << App.root.join('lib') Dir[App.root.join('config/initializers/*.rb')].each { |f| require f } diff --git a/config/initializers/sequel.rb b/config/initializers/sequel.rb index f1d8af8..26a2d58 100644 --- a/config/initializers/sequel.rb +++ b/config/initializers/sequel.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require 'pg' require 'sequel' diff --git a/config/schedule.rb b/config/schedule.rb index e51ba9e..67731cf 100644 --- a/config/schedule.rb +++ b/config/schedule.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + job_type :rake, 'cd :path && foreman run bundle exec rake :task --silent :output' every '*/15 13,14,15,16,17 * * 1-5' do diff --git a/config/unicorn.rb b/config/unicorn.rb index 9df511e..bb3101f 100644 --- a/config/unicorn.rb +++ b/config/unicorn.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + worker_process_count = (ENV['WORKER_PROCESSES'] || 4).to_i preload_app true diff --git a/db/migrate/001_create_currencies.rb b/db/migrate/001_create_currencies.rb index 3d1e311..bdbcc59 100644 --- a/db/migrate/001_create_currencies.rb +++ b/db/migrate/001_create_currencies.rb @@ -7,7 +7,7 @@ Sequel.migration do String :iso_code Float :rate - index [:date, :iso_code], unique: true + index %i[date iso_code], unique: true end end end diff --git a/lib/api.rb b/lib/api.rb index 9c3d4c1..aec3cbd 100644 --- a/lib/api.rb +++ b/lib/api.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require 'oj' require 'sinatra' require 'rack/cors' diff --git a/lib/currency.rb b/lib/currency.rb index f6aae41..dcd5632 100644 --- a/lib/currency.rb +++ b/lib/currency.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + class Currency < Sequel::Model dataset_module do def recent diff --git a/lib/quote.rb b/lib/quote.rb index d4a8d4d..a0aad94 100644 --- a/lib/quote.rb +++ b/lib/quote.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require 'currency' class Quote diff --git a/lib/tasks/db.rake b/lib/tasks/db.rake index 776bc8b..20be55c 100644 --- a/lib/tasks/db.rake +++ b/lib/tasks/db.rake @@ -1,4 +1,5 @@ # frozen_string_literal: true + namespace :db do desc 'Create db' task :create do diff --git a/lib/tasks/environment.rake b/lib/tasks/environment.rake index 8729c19..95c6e48 100644 --- a/lib/tasks/environment.rake +++ b/lib/tasks/environment.rake @@ -1,4 +1,5 @@ # frozen_string_literal: true + task :environment do require './config/environment' end diff --git a/lib/tasks/rates.rake b/lib/tasks/rates.rake index 0cbce1f..554c8d7 100644 --- a/lib/tasks/rates.rake +++ b/lib/tasks/rates.rake @@ -1,4 +1,5 @@ # frozen_string_literal: true + namespace :rates do task setup: :environment do require 'currency' diff --git a/lib/tasks/test.rake b/lib/tasks/test.rake index 2e96839..1e65fae 100644 --- a/lib/tasks/test.rake +++ b/lib/tasks/test.rake @@ -1,4 +1,5 @@ # frozen_string_literal: true + return unless ENV['RACK_ENV'] == 'test' require 'rake/testtask' @@ -12,4 +13,4 @@ end RuboCop::RakeTask.new -task default: %w(db:migrate rates:load test rubocop) +task default: %w[db:migrate rates:load test rubocop] diff --git a/spec/api_spec.rb b/spec/api_spec.rb index 5ed2c59..5c45fde 100644 --- a/spec/api_spec.rb +++ b/spec/api_spec.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require_relative 'helper' require 'rack/test' require 'api' @@ -32,7 +33,7 @@ describe 'the API' do it 'filters symbols' do get '/latest?symbols=USD' - json['rates'].keys.must_equal %w(USD) + json['rates'].keys.must_equal %w[USD] end it 'aliases base as from' do @@ -42,7 +43,7 @@ describe 'the API' do it 'aliases symbols as to' do get '/latest?to=USD' - json['rates'].keys.must_equal %w(USD) + json['rates'].keys.must_equal %w[USD] end it 'returns historical quotes' do @@ -57,14 +58,14 @@ describe 'the API' do end it 'returns a cache control header' do - %w(/ /latest /2012-11-20).each do |path| + %w[/ /latest /2012-11-20].each do |path| get path headers['Cache-Control'].wont_be_nil end end it 'returns a last modified header' do - %w(/latest /2012-11-20).each do |path| + %w[/latest /2012-11-20].each do |path| get path headers['Last-Modified'].wont_be_nil end @@ -76,7 +77,7 @@ describe 'the API' do end it 'allows cross-origin requests' do - %w(/ /latest /2012-11-20).each do |path| + %w[/ /latest /2012-11-20].each do |path| header 'Origin', '*' get path assert headers.key?('Access-Control-Allow-Methods') @@ -84,7 +85,7 @@ describe 'the API' do end it 'responds to preflight requests' do - %w(/ /latest /2012-11-20).each do |path| + %w[/ /latest /2012-11-20].each do |path| header 'Origin', '*' header 'Access-Control-Request-Method', 'GET' header 'Access-Control-Request-Headers', 'Content-Type' diff --git a/spec/currency_spec.rb b/spec/currency_spec.rb index f6a84f4..88d771c 100644 --- a/spec/currency_spec.rb +++ b/spec/currency_spec.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require_relative 'helper' require 'currency' diff --git a/spec/edge_cases_spec.rb b/spec/edge_cases_spec.rb index 57f0513..288ff79 100644 --- a/spec/edge_cases_spec.rb +++ b/spec/edge_cases_spec.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require_relative 'helper' require 'rack/test' require 'api' diff --git a/spec/helper.rb b/spec/helper.rb index 40f4cd5..41bb245 100644 --- a/spec/helper.rb +++ b/spec/helper.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require './config/environment' require 'minitest/autorun' require 'minitest/pride' diff --git a/spec/quote_spec.rb b/spec/quote_spec.rb index 21b7bf5..110badb 100644 --- a/spec/quote_spec.rb +++ b/spec/quote_spec.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require_relative 'helper' require 'quote' @@ -27,7 +28,7 @@ describe Quote do it 'casts to hash' do stub_rates do |quote| - %i(base date rates).each do |key| + %i[base date rates].each do |key| quote.to_h.keys.must_include key end end