mirror of
https://github.com/hakanensari/frankfurter.git
synced 2024-11-21 18:42:29 +01:00
Refactor rake tasks
This commit is contained in:
parent
a2659e4a9c
commit
e968c2c6b4
38
Rakefile
38
Rakefile
@ -1,41 +1,5 @@
|
||||
require_relative 'config/environment'
|
||||
require 'rake/testtask'
|
||||
require 'currency'
|
||||
require 'fixer'
|
||||
|
||||
namespace :rates do
|
||||
desc 'Reload all rates'
|
||||
task :reload do
|
||||
Currency.delete
|
||||
data = Fixer::Feed.new(:historical)
|
||||
Currency.multi_insert(data.to_a)
|
||||
end
|
||||
|
||||
desc 'Update rates'
|
||||
task :update do
|
||||
Fixer::Feed.new.each do |hsh|
|
||||
Currency.find_or_create(hsh)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Rake::TestTask.new do |t|
|
||||
t.libs.push('lib')
|
||||
t.test_files = FileList['spec/*_spec.rb']
|
||||
t.verbose = true
|
||||
end
|
||||
|
||||
namespace :db do
|
||||
desc 'Run database migrations'
|
||||
task :migrate do
|
||||
Sequel.extension(:migration)
|
||||
db = Sequel::DATABASES.first
|
||||
dir = App.root.join('db/migrate')
|
||||
opts = {}
|
||||
opts.update(target: ENV['VERSION'].to_i) if ENV['VERSION']
|
||||
|
||||
Sequel::IntegerMigrator.new(db, dir, opts).run
|
||||
end
|
||||
end
|
||||
Dir.glob('lib/tasks/*.rake').each { |r| import r }
|
||||
|
||||
task :default => [:test]
|
||||
|
12
lib/tasks/db.rake
Normal file
12
lib/tasks/db.rake
Normal file
@ -0,0 +1,12 @@
|
||||
namespace :db do
|
||||
desc 'Run database migrations'
|
||||
task :migrate do
|
||||
Sequel.extension(:migration)
|
||||
db = Sequel::DATABASES.first
|
||||
dir = App.root.join('db/migrate')
|
||||
opts = {}
|
||||
opts.update(target: ENV['VERSION'].to_i) if ENV['VERSION']
|
||||
|
||||
Sequel::IntegerMigrator.new(db, dir, opts).run
|
||||
end
|
||||
end
|
18
lib/tasks/rates.rake
Normal file
18
lib/tasks/rates.rake
Normal file
@ -0,0 +1,18 @@
|
||||
require 'currency'
|
||||
require 'fixer'
|
||||
|
||||
namespace :rates do
|
||||
desc 'Reload all rates'
|
||||
task :reload do
|
||||
Currency.delete
|
||||
data = Fixer::Feed.new(:historical)
|
||||
Currency.multi_insert(data.to_a)
|
||||
end
|
||||
|
||||
desc 'Update rates'
|
||||
task :update do
|
||||
Fixer::Feed.new.each do |hsh|
|
||||
Currency.find_or_create(hsh)
|
||||
end
|
||||
end
|
||||
end
|
7
lib/tasks/test.rake
Normal file
7
lib/tasks/test.rake
Normal file
@ -0,0 +1,7 @@
|
||||
require 'rake/testtask'
|
||||
|
||||
Rake::TestTask.new do |t|
|
||||
t.libs.push('lib')
|
||||
t.test_files = FileList['spec/*_spec.rb']
|
||||
t.verbose = true
|
||||
end
|
Loading…
Reference in New Issue
Block a user