mirror of
https://github.com/hakanensari/frankfurter.git
synced 2024-11-25 04:22:28 +01:00
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:
parent
d74fefa9c9
commit
3319c49dca
@ -1,11 +0,0 @@
|
||||
.dockerignore
|
||||
.git*
|
||||
.pryrc
|
||||
.ruby*
|
||||
Dockerfile
|
||||
LICENSE
|
||||
Procfile
|
||||
docker-compose*.yml
|
||||
spec
|
||||
*.md
|
||||
*.yml
|
4
.gitignore
vendored
4
.gitignore
vendored
@ -1,6 +1,2 @@
|
||||
.bundle
|
||||
.env
|
||||
bin
|
||||
log
|
||||
tmp
|
||||
vendor
|
||||
|
@ -1 +0,0 @@
|
||||
fixer-io
|
@ -1 +0,0 @@
|
||||
ruby-2.4.1
|
@ -1,8 +1,10 @@
|
||||
before_install:
|
||||
- gem update --system
|
||||
- gem install bundler
|
||||
before_script:
|
||||
- psql -c 'create database fixer_test;' -U postgres
|
||||
- cd app
|
||||
env:
|
||||
- RACK_ENV=test
|
||||
rvm:
|
||||
- 2.4.1
|
||||
- 2.4.2
|
||||
sudo: false
|
||||
|
6
app/.dockerignore
Normal file
6
app/.dockerignore
Normal file
@ -0,0 +1,6 @@
|
||||
.*
|
||||
Dockerfile
|
||||
LICENSE
|
||||
spec
|
||||
*.md
|
||||
*.yml
|
@ -1,5 +1,5 @@
|
||||
AllCops:
|
||||
TargetRubyVersion: 2.3
|
||||
TargetRubyVersion: 2.4
|
||||
Documentation:
|
||||
Enabled: false
|
||||
Metrics/BlockLength:
|
1
app/.tool-versions
Normal file
1
app/.tool-versions
Normal file
@ -0,0 +1 @@
|
||||
ruby 2.4.2
|
@ -1,4 +1,4 @@
|
||||
FROM ruby:2.4.1
|
||||
FROM ruby:2.4.2
|
||||
|
||||
RUN mkdir /app
|
||||
WORKDIR /app
|
@ -2,7 +2,7 @@
|
||||
|
||||
source 'http://rubygems.org'
|
||||
|
||||
ruby '2.4.1'
|
||||
ruby '2.4.2'
|
||||
|
||||
gem 'fixer'
|
||||
gem 'kgio'
|
@ -2,46 +2,45 @@ GEM
|
||||
remote: http://rubygems.org/
|
||||
specs:
|
||||
ast (2.3.0)
|
||||
coderay (1.1.1)
|
||||
coderay (1.1.2)
|
||||
fixer (0.7.0)
|
||||
kgio (2.11.0)
|
||||
method_source (0.8.2)
|
||||
minitest (5.10.2)
|
||||
method_source (0.9.0)
|
||||
minitest (5.10.3)
|
||||
minitest-around (0.4.0)
|
||||
minitest (~> 5.0)
|
||||
mustermann (1.0.0)
|
||||
oj (3.1.3)
|
||||
parallel (1.11.2)
|
||||
mustermann (1.0.1)
|
||||
oj (3.3.9)
|
||||
parallel (1.12.0)
|
||||
parser (2.4.0.0)
|
||||
ast (~> 2.2)
|
||||
pg (0.21.0)
|
||||
powerpack (0.1.1)
|
||||
pry (0.10.4)
|
||||
pry (0.11.2)
|
||||
coderay (~> 1.1.0)
|
||||
method_source (~> 0.8.1)
|
||||
slop (~> 3.4)
|
||||
method_source (~> 0.9.0)
|
||||
rack (2.0.3)
|
||||
rack-cors (0.4.1)
|
||||
rack-cors (1.0.2)
|
||||
rack-protection (2.0.0)
|
||||
rack
|
||||
rack-test (0.6.3)
|
||||
rack (>= 1.0)
|
||||
rack-test (0.7.0)
|
||||
rack (>= 1.0, < 3)
|
||||
rainbow (2.2.2)
|
||||
rake
|
||||
raindrops (0.18.0)
|
||||
rake (12.0.0)
|
||||
rubocop (0.49.1)
|
||||
raindrops (0.19.0)
|
||||
rake (12.2.1)
|
||||
rubocop (0.51.0)
|
||||
parallel (~> 1.10)
|
||||
parser (>= 2.3.3.1, < 3.0)
|
||||
powerpack (~> 0.1)
|
||||
rainbow (>= 1.99.1, < 3.0)
|
||||
rainbow (>= 2.2.2, < 3.0)
|
||||
ruby-progressbar (~> 1.7)
|
||||
unicode-display_width (~> 1.0, >= 1.0.1)
|
||||
ruby-progressbar (1.8.1)
|
||||
sequel (4.47.0)
|
||||
sequel_pg (1.6.19)
|
||||
pg (>= 0.8.0)
|
||||
sequel (>= 4.0.0)
|
||||
ruby-progressbar (1.9.0)
|
||||
sequel (5.2.0)
|
||||
sequel_pg (1.8.0)
|
||||
pg (>= 0.18.0)
|
||||
sequel (>= 4.34.0)
|
||||
shotgun (0.9.2)
|
||||
rack (>= 1.0)
|
||||
sinatra (2.0.0)
|
||||
@ -49,10 +48,9 @@ GEM
|
||||
rack (~> 2.0)
|
||||
rack-protection (= 2.0.0)
|
||||
tilt (~> 2.0)
|
||||
slop (3.6.0)
|
||||
tilt (2.0.7)
|
||||
unicode-display_width (1.2.1)
|
||||
unicorn (5.3.0)
|
||||
tilt (2.0.8)
|
||||
unicode-display_width (1.3.0)
|
||||
unicorn (5.3.1)
|
||||
kgio (~> 2.6)
|
||||
raindrops (~> 0.7)
|
||||
|
||||
@ -76,7 +74,7 @@ DEPENDENCIES
|
||||
unicorn
|
||||
|
||||
RUBY VERSION
|
||||
ruby 2.4.1p111
|
||||
ruby 2.4.2p198
|
||||
|
||||
BUNDLED WITH
|
||||
1.14.6
|
||||
1.16.0
|
@ -2,5 +2,4 @@
|
||||
|
||||
require './config/environment'
|
||||
require 'minitest/autorun'
|
||||
require 'minitest/pride'
|
||||
require 'minitest/around/spec'
|
@ -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
|
@ -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(' ')}"
|
@ -1,2 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
sudo restart api.fixer.io 2>/dev/null || sudo start api.fixer.io
|
@ -1,13 +1,19 @@
|
||||
version: '3'
|
||||
services:
|
||||
db:
|
||||
restart: always
|
||||
web:
|
||||
env_file: .env
|
||||
restart: always
|
||||
scheduler:
|
||||
restart: always
|
||||
nginx-proxy:
|
||||
labels:
|
||||
- "com.github.jrcs.letsencrypt_nginx_proxy_companion.nginx_proxy=true"
|
||||
ports:
|
||||
- "80:80"
|
||||
- "443:443"
|
||||
restart: always
|
||||
volumes:
|
||||
- /etc/nginx/conf.d
|
||||
- ./limit_req.conf:/etc/nginx/conf.d/limit_req.conf:ro
|
||||
@ -18,6 +24,7 @@ services:
|
||||
image: jrcs/letsencrypt-nginx-proxy-companion
|
||||
depends_on:
|
||||
- nginx-proxy
|
||||
restart: always
|
||||
volumes:
|
||||
- /var/run/docker.sock:/var/run/docker.sock:ro
|
||||
- certs:/etc/nginx/certs:rw
|
||||
|
@ -5,8 +5,9 @@ services:
|
||||
volumes:
|
||||
- data:/var/lib/postgresql/data
|
||||
web:
|
||||
build: .
|
||||
command: unicorn -c ./config/unicorn.rb
|
||||
build:
|
||||
context: ./app
|
||||
command: unicorn -c config/unicorn.rb
|
||||
environment:
|
||||
DATABASE_URL: postgres://postgres@db/postgres
|
||||
entrypoint: ./wait-for-it.sh db:5432 -s --
|
||||
|
5
gem/.rubocop.yml
Normal file
5
gem/.rubocop.yml
Normal file
@ -0,0 +1,5 @@
|
||||
AllCops:
|
||||
TargetRubyVersion: 2.4
|
||||
Metrics/BlockLength:
|
||||
Exclude:
|
||||
- 'spec/**/*'
|
4
gem/Gemfile
Normal file
4
gem/Gemfile
Normal file
@ -0,0 +1,4 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
source 'https://rubygems.org'
|
||||
gemspec
|
53
gem/Gemfile.lock
Normal file
53
gem/Gemfile.lock
Normal 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
3
gem/README.md
Normal 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
14
gem/Rakefile
Normal 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
26
gem/fixer.gemspec
Normal 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
3
gem/lib/fixer.rb
Normal file
@ -0,0 +1,3 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'fixer/feed'
|
48
gem/lib/fixer/feed.rb
Normal file
48
gem/lib/fixer/feed.rb
Normal 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
5
gem/lib/fixer/version.rb
Normal file
@ -0,0 +1,5 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module Fixer
|
||||
VERSION = '0.7.0'
|
||||
end
|
47
gem/spec/feed_spec.rb
Normal file
47
gem/spec/feed_spec.rb
Normal 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
14
gem/spec/helper.rb
Normal 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
|
95157
gem/spec/vcr_cassettes/fixer.yml
Normal file
95157
gem/spec/vcr_cassettes/fixer.yml
Normal file
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user