lib/tasks/okei_tasks.rake in okei-0.0.2 vs lib/tasks/okei_tasks.rake in okei-1.0.0.pre.rc

- old
+ new

@@ -1,7 +1,45 @@ namespace :okei do + def app + @app ||= ( + Rake::Task.task_defined?("railties:install:migrations") ? "" : "app:" + ) + end + + desc "Installs the units gem into rails application" + task install: %w(dependencies:install db:migrate) do + system "rake routes:mount" if app.blank? + end + + namespace :db do + + desc "Copies and runs db migrations from okei gem" + task migrate: %w(install:migrations environment) do + system "rake db:migrate SCOPE=okei RAILS_ENV=#{ Rails.env }" + end + end + + namespace :install do + + desc "Copies migrations from okei gem to application" + task :migrations do + Rake::Task["#{ app }railties:install:migrations"].reenable + Rake::Task["#{ app }okei:install:migrations"].invoke + end + end + + namespace :dependencies do + + desc "Installs gem dependencies" + task :install do + system "rake #{ app }corrector:install" + Rake::Task["#{ app }railties:install:migrations"].reenable + system "rake #{ app }uuids:install" + end + end + namespace :routes do desc "Mounts units API routes" task :mount do insert_into_file( @@ -10,47 +48,28 @@ line: "\n\n mount Okei::Engine => \"/okei\"", engine: "Okei::Engine" ) end - desc "Dismounts units API routes" - task :dismount do - remove_from_file "config/routes.rb", "Okei::Engine" - end - def insert_into_file(name, before:, line:, engine:) text = File.read(name) return if text[engine] File.write name, text.gsub(before, line << before) end - - def remove_from_file(name, text) - temp = File.read(name).split("\n").reject { |line| line[text] }.join("\n") - File.write(name, temp) - end end - namespace :db do + namespace :test do - desc "Creates and runs units API migrations" - task :add do - sh "rake okei:install:migrations" - sh "rake db:migrate SCOPE=okei" + desc "Prepares spec environment" + task prepare: %w(cache:prepare) do + system "rake db:migrate RAILS_ENV=test" end + end - desc "Rolls back units API migrations" - task :rollback do - sh "rake db:rollback SCOPE=okei STEP=4" - end + namespace :cache do - desc "Removes units API db tables and migrations" - task drop: :rollback do - sh "rm db/migrate/*.okei.rb" + desc "Creates spec/dummy/temp/cache folder" + task :prepare do + system "mkdir spec/dummy/tmp/cache -p -v" end end - - desc "Mounts the units gem into rails application" - task install: %w(db:migrate routes:mount) - - desc "Uninstalls the units gem from rails application" - task uninstall: %w(routes:dismount db:drop) end