Spring clean code base

- Bump ruby version
- Remove obsolete files, including deploy artefacts
- Don't use pride when testing
- Store gem and app in same repo
- Switch to asdf
This commit is contained in:
Hakan Ensari 2017-11-03 20:55:05 +00:00
parent d74fefa9c9
commit 3319c49dca
52 changed files with 95428 additions and 90 deletions

View File

@ -1,11 +0,0 @@
.dockerignore
.git*
.pryrc
.ruby*
Dockerfile
LICENSE
Procfile
docker-compose*.yml
spec
*.md
*.yml

4
.gitignore vendored
View File

@ -1,6 +1,2 @@
.bundle .bundle
.env .env
bin
log
tmp
vendor

View File

@ -1 +0,0 @@
fixer-io

View File

@ -1 +0,0 @@
ruby-2.4.1

View File

@ -1,8 +1,10 @@
before_install: before_install:
- gem update --system - gem update --system
- gem install bundler - gem install bundler
before_script:
- psql -c 'create database fixer_test;' -U postgres - psql -c 'create database fixer_test;' -U postgres
- cd app
env:
- RACK_ENV=test
rvm: rvm:
- 2.4.1 - 2.4.2
sudo: false sudo: false

View File

@ -1 +0,0 @@
web: bundle exec unicorn -p $PORT -c ./config/unicorn.rb

6
app/.dockerignore Normal file
View File

@ -0,0 +1,6 @@
.*
Dockerfile
LICENSE
spec
*.md
*.yml

View File

View File

@ -1,5 +1,5 @@
AllCops: AllCops:
TargetRubyVersion: 2.3 TargetRubyVersion: 2.4
Documentation: Documentation:
Enabled: false Enabled: false
Metrics/BlockLength: Metrics/BlockLength:

1
app/.tool-versions Normal file
View File

@ -0,0 +1 @@
ruby 2.4.2

View File

@ -1,4 +1,4 @@
FROM ruby:2.4.1 FROM ruby:2.4.2
RUN mkdir /app RUN mkdir /app
WORKDIR /app WORKDIR /app

View File

@ -2,7 +2,7 @@
source 'http://rubygems.org' source 'http://rubygems.org'
ruby '2.4.1' ruby '2.4.2'
gem 'fixer' gem 'fixer'
gem 'kgio' gem 'kgio'

View File

@ -2,46 +2,45 @@ GEM
remote: http://rubygems.org/ remote: http://rubygems.org/
specs: specs:
ast (2.3.0) ast (2.3.0)
coderay (1.1.1) coderay (1.1.2)
fixer (0.7.0) fixer (0.7.0)
kgio (2.11.0) kgio (2.11.0)
method_source (0.8.2) method_source (0.9.0)
minitest (5.10.2) minitest (5.10.3)
minitest-around (0.4.0) minitest-around (0.4.0)
minitest (~> 5.0) minitest (~> 5.0)
mustermann (1.0.0) mustermann (1.0.1)
oj (3.1.3) oj (3.3.9)
parallel (1.11.2) parallel (1.12.0)
parser (2.4.0.0) parser (2.4.0.0)
ast (~> 2.2) ast (~> 2.2)
pg (0.21.0) pg (0.21.0)
powerpack (0.1.1) powerpack (0.1.1)
pry (0.10.4) pry (0.11.2)
coderay (~> 1.1.0) coderay (~> 1.1.0)
method_source (~> 0.8.1) method_source (~> 0.9.0)
slop (~> 3.4)
rack (2.0.3) rack (2.0.3)
rack-cors (0.4.1) rack-cors (1.0.2)
rack-protection (2.0.0) rack-protection (2.0.0)
rack rack
rack-test (0.6.3) rack-test (0.7.0)
rack (>= 1.0) rack (>= 1.0, < 3)
rainbow (2.2.2) rainbow (2.2.2)
rake rake
raindrops (0.18.0) raindrops (0.19.0)
rake (12.0.0) rake (12.2.1)
rubocop (0.49.1) rubocop (0.51.0)
parallel (~> 1.10) parallel (~> 1.10)
parser (>= 2.3.3.1, < 3.0) parser (>= 2.3.3.1, < 3.0)
powerpack (~> 0.1) powerpack (~> 0.1)
rainbow (>= 1.99.1, < 3.0) rainbow (>= 2.2.2, < 3.0)
ruby-progressbar (~> 1.7) ruby-progressbar (~> 1.7)
unicode-display_width (~> 1.0, >= 1.0.1) unicode-display_width (~> 1.0, >= 1.0.1)
ruby-progressbar (1.8.1) ruby-progressbar (1.9.0)
sequel (4.47.0) sequel (5.2.0)
sequel_pg (1.6.19) sequel_pg (1.8.0)
pg (>= 0.8.0) pg (>= 0.18.0)
sequel (>= 4.0.0) sequel (>= 4.34.0)
shotgun (0.9.2) shotgun (0.9.2)
rack (>= 1.0) rack (>= 1.0)
sinatra (2.0.0) sinatra (2.0.0)
@ -49,10 +48,9 @@ GEM
rack (~> 2.0) rack (~> 2.0)
rack-protection (= 2.0.0) rack-protection (= 2.0.0)
tilt (~> 2.0) tilt (~> 2.0)
slop (3.6.0) tilt (2.0.8)
tilt (2.0.7) unicode-display_width (1.3.0)
unicode-display_width (1.2.1) unicorn (5.3.1)
unicorn (5.3.0)
kgio (~> 2.6) kgio (~> 2.6)
raindrops (~> 0.7) raindrops (~> 0.7)
@ -76,7 +74,7 @@ DEPENDENCIES
unicorn unicorn
RUBY VERSION RUBY VERSION
ruby 2.4.1p111 ruby 2.4.2p198
BUNDLED WITH BUNDLED WITH
1.14.6 1.16.0

View File

@ -2,5 +2,4 @@
require './config/environment' require './config/environment'
require 'minitest/autorun' require 'minitest/autorun'
require 'minitest/pride'
require 'minitest/around/spec' require 'minitest/around/spec'

View File

@ -1,17 +0,0 @@
#!/usr/bin/env bash
set -e
oldrev=$1
newrev=$2
run() {
[ -x $1 ] && $1 $oldrev $newrev
}
echo files changed: $(git diff $oldrev $newrev --diff-filter=ACDMR --name-only | wc -l)
umask 002
git submodule sync && git submodule update --init --recursive
run deploy/before_restart
run deploy/restart && run deploy/after_restart

View File

@ -1,18 +0,0 @@
#!/usr/bin/env ruby
# frozen_string_literal: true
oldrev, newrev = ARGV
def run(cmd)
exit($CHILD_STATUS.exitstatus) unless system "umask 002 && #{cmd}"
end
run 'foreman run bundle install --deployment --without development:test'
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.positive?
tasks << 'rates:load'
run "foreman run bundle exec rake #{tasks.join(' ')}"

View File

@ -1,2 +0,0 @@
#!/usr/bin/env bash
sudo restart api.fixer.io 2>/dev/null || sudo start api.fixer.io

View File

@ -1,13 +1,19 @@
version: '3' version: '3'
services: services:
db:
restart: always
web: web:
env_file: .env env_file: .env
restart: always
scheduler:
restart: always
nginx-proxy: nginx-proxy:
labels: labels:
- "com.github.jrcs.letsencrypt_nginx_proxy_companion.nginx_proxy=true" - "com.github.jrcs.letsencrypt_nginx_proxy_companion.nginx_proxy=true"
ports: ports:
- "80:80" - "80:80"
- "443:443" - "443:443"
restart: always
volumes: volumes:
- /etc/nginx/conf.d - /etc/nginx/conf.d
- ./limit_req.conf:/etc/nginx/conf.d/limit_req.conf:ro - ./limit_req.conf:/etc/nginx/conf.d/limit_req.conf:ro
@ -18,6 +24,7 @@ services:
image: jrcs/letsencrypt-nginx-proxy-companion image: jrcs/letsencrypt-nginx-proxy-companion
depends_on: depends_on:
- nginx-proxy - nginx-proxy
restart: always
volumes: volumes:
- /var/run/docker.sock:/var/run/docker.sock:ro - /var/run/docker.sock:/var/run/docker.sock:ro
- certs:/etc/nginx/certs:rw - certs:/etc/nginx/certs:rw

View File

@ -5,8 +5,9 @@ services:
volumes: volumes:
- data:/var/lib/postgresql/data - data:/var/lib/postgresql/data
web: web:
build: . build:
command: unicorn -c ./config/unicorn.rb context: ./app
command: unicorn -c config/unicorn.rb
environment: environment:
DATABASE_URL: postgres://postgres@db/postgres DATABASE_URL: postgres://postgres@db/postgres
entrypoint: ./wait-for-it.sh db:5432 -s -- entrypoint: ./wait-for-it.sh db:5432 -s --

5
gem/.rubocop.yml Normal file
View File

@ -0,0 +1,5 @@
AllCops:
TargetRubyVersion: 2.4
Metrics/BlockLength:
Exclude:
- 'spec/**/*'

4
gem/Gemfile Normal file
View File

@ -0,0 +1,4 @@
# frozen_string_literal: true
source 'https://rubygems.org'
gemspec

53
gem/Gemfile.lock Normal file
View File

@ -0,0 +1,53 @@
PATH
remote: .
specs:
fixer (0.7.0)
GEM
remote: https://rubygems.org/
specs:
addressable (2.5.2)
public_suffix (>= 2.0.2, < 4.0)
ast (2.3.0)
crack (0.4.3)
safe_yaml (~> 1.0.0)
hashdiff (0.3.7)
minitest (5.10.3)
parallel (1.12.0)
parser (2.4.0.0)
ast (~> 2.2)
powerpack (0.1.1)
public_suffix (3.0.0)
rainbow (2.2.2)
rake
rake (10.5.0)
rubocop (0.51.0)
parallel (~> 1.10)
parser (>= 2.3.3.1, < 3.0)
powerpack (~> 0.1)
rainbow (>= 2.2.2, < 3.0)
ruby-progressbar (~> 1.7)
unicode-display_width (~> 1.0, >= 1.0.1)
ruby-progressbar (1.9.0)
safe_yaml (1.0.4)
unicode-display_width (1.3.0)
vcr (3.0.3)
webmock (2.3.2)
addressable (>= 2.3.6)
crack (>= 0.3.2)
hashdiff
PLATFORMS
ruby
DEPENDENCIES
bundler (~> 1.0)
fixer!
minitest (~> 5.0)
rake (~> 10.0)
rubocop
vcr (~> 3.0)
webmock (~> 2.3)
BUNDLED WITH
1.16.0

3
gem/README.md Normal file
View File

@ -0,0 +1,3 @@
# Fixer
Fixer wraps the XML feeds of Euro foreign exchange reference provided by the European Central Bank.

14
gem/Rakefile Normal file
View File

@ -0,0 +1,14 @@
# frozen_string_literal: true
require 'bundler/gem_tasks'
require 'rake/testtask'
require 'rubocop/rake_task'
Rake::TestTask.new do |t|
t.ruby_opts += ['-W1']
t.pattern = 'spec/*_spec.rb'
end
RuboCop::RakeTask.new
task default: %i[test rubocop]

26
gem/fixer.gemspec Normal file
View File

@ -0,0 +1,26 @@
# frozen_string_literal: true
lib = File.expand_path('../lib', __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'fixer/version'
Gem::Specification.new do |spec|
spec.name = 'fixer'
spec.version = Fixer::VERSION
spec.author = ['Hakan Ensari']
spec.email = ['hakanensari@gmail.com']
spec.summary = <<-SUMMARY
A wrapper to the exchange rate feeds of the European Central Bank
SUMMARY
spec.homepage = 'https://github.com/hakanensari/fixer'
spec.license = 'MIT'
spec.files = Dir.glob('lib/**/*') + %w[LICENSE README.md]
spec.require_paths = ['lib']
spec.add_development_dependency 'bundler', '~> 1.0'
spec.add_development_dependency 'minitest', '~> 5.0'
spec.add_development_dependency 'rake', '~> 10.0'
spec.add_development_dependency 'rubocop'
spec.add_development_dependency 'vcr', '~> 3.0'
spec.add_development_dependency 'webmock', '~> 2.3'
end

3
gem/lib/fixer.rb Normal file
View File

@ -0,0 +1,3 @@
# frozen_string_literal: true
require 'fixer/feed'

48
gem/lib/fixer/feed.rb Normal file
View File

@ -0,0 +1,48 @@
# frozen_string_literal: true
require 'net/http'
require 'rexml/document'
module Fixer
# Wraps ECB's data feed
class Feed
include Enumerable
TYPES = {
current: 'daily',
ninety_days: 'hist-90d',
historical: 'hist'
}.freeze
def initialize(type = :current)
@type = TYPES.fetch(type) { raise ArgumentError }
end
def each
REXML::XPath.each(document, '/gesmes:Envelope/Cube/Cube[@time]') do |day|
date = Date.parse(day.attribute('time').value)
REXML::XPath.each(day, './Cube') do |currency|
yield(
date: date,
iso_code: currency.attribute('currency').value,
rate: Float(currency.attribute('rate').value)
)
end
end
end
private
def document
REXML::Document.new(xml)
end
def xml
Net::HTTP.get(url)
end
def url
URI("http://www.ecb.europa.eu/stats/eurofxref/eurofxref-#{@type}.xml")
end
end
end

5
gem/lib/fixer/version.rb Normal file
View File

@ -0,0 +1,5 @@
# frozen_string_literal: true
module Fixer
VERSION = '0.7.0'
end

47
gem/spec/feed_spec.rb Normal file
View File

@ -0,0 +1,47 @@
# frozen_string_literal: true
require_relative 'helper'
module Fixer
describe Feed do
before { VCR.insert_cassette 'fixer' }
after { VCR.eject_cassette }
it 'parses the date of a currency' do
feed = Feed.new
currency = feed.first
currency[:date].must_be_kind_of Date
end
it 'parse the ISO code of a currency' do
feed = Feed.new
currency = feed.first
currency[:iso_code].must_be_kind_of String
end
it 'parses the rate of a currency' do
feed = Feed.new
currency = feed.first
currency[:rate].must_be_kind_of Float
end
it 'fetches current rates' do
feed = Feed.new
feed.count.must_be :<, 40
end
it 'fetches rates for the past 90 days' do
feed = Feed.new(:ninety_days)
feed.count.must_be :>, 33 * 60
end
it 'fetches historical rates' do
feed = Feed.new(:historical)
feed.count.must_be :>, 33 * 3000
end
it 'raises error with invalid type' do
-> { Feed.new(:invalid) }.must_raise ArgumentError
end
end
end

14
gem/spec/helper.rb Normal file
View File

@ -0,0 +1,14 @@
# frozen_string_literal: true
$LOAD_PATH.unshift(File.expand_path('../../lib', __FILE__))
require 'minitest/autorun'
require 'vcr'
require 'webmock'
require 'fixer'
VCR.configure do |c|
c.cassette_library_dir = 'spec/vcr_cassettes'
c.hook_into :webmock
end

File diff suppressed because it is too large Load Diff