From e968c2c6b4e1363749de10a9e57f74325ef43eb9 Mon Sep 17 00:00:00 2001 From: hakanensari Date: Fri, 14 Mar 2014 12:12:21 +0000 Subject: [PATCH] Refactor rake tasks --- Rakefile | 38 +------------------------------------- lib/tasks/db.rake | 12 ++++++++++++ lib/tasks/rates.rake | 18 ++++++++++++++++++ lib/tasks/test.rake | 7 +++++++ 4 files changed, 38 insertions(+), 37 deletions(-) create mode 100644 lib/tasks/db.rake create mode 100644 lib/tasks/rates.rake create mode 100644 lib/tasks/test.rake diff --git a/Rakefile b/Rakefile index 2bea3d5..547f8b0 100644 --- a/Rakefile +++ b/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] diff --git a/lib/tasks/db.rake b/lib/tasks/db.rake new file mode 100644 index 0000000..aeff11f --- /dev/null +++ b/lib/tasks/db.rake @@ -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 diff --git a/lib/tasks/rates.rake b/lib/tasks/rates.rake new file mode 100644 index 0000000..dd46738 --- /dev/null +++ b/lib/tasks/rates.rake @@ -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 diff --git a/lib/tasks/test.rake b/lib/tasks/test.rake new file mode 100644 index 0000000..ad75211 --- /dev/null +++ b/lib/tasks/test.rake @@ -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