Permalink
Browse files

restructured the simple_captcha setup rake tasks [nap]

git-svn-id: svn://rubyforge.org/var/svn/expressica/plugins/simple_captcha@31 543a08ce-03e4-4efe-aa80-3b952f66419f
  • Loading branch information...
1 parent 57c7861 commit 9c1b10764d1b711bede540b91f1dfb3b56f8fba8 sur committed May 15, 2008
Showing with 64 additions and 56 deletions.
  1. +1 −0 init.rb
  2. +59 −0 lib/simple_captcha_setup.rb
  3. +4 −56 tasks/simple_captcha_tasks.rake
View
@@ -1,5 +1,6 @@
# Copyright (c) 2008 [Sur http://expressica.com]
+require 'simple_captcha_setup'
require 'simple_captcha_config'
require 'simple_captcha_image'
require 'simple_captcha_action_view'
@@ -0,0 +1,59 @@
+require 'fileutils'
+
+module SimpleCaptcha #:nodoc
+ module SetupTasks #:nodoc
+
+ def self.do_setup(version = :new)
+ @version = version
+
+ begin
+ puts "STEP 1"
+ generate_migration
+ write_migration_content
+ copy_view_file
+ puts "Followup Steps"
+ puts "STEP 2 -- run the task 'rake db:migrate'"
+ puts "STEP 3 -- edit the file config/routes.rb to add the route \"map.simple_captcha '/simple_captcha/:action', :controller => 'simple_captcha'\""
+ rescue StandardError => e
+ p e
+ end
+ end
+
+ private
+
+ def self.generate_migration
+ puts "==============================================================================="
+ puts "ruby script/generate migration create_simple_captcha_data"
+ puts %x{ruby script/generate migration create_simple_captcha_data}
+ puts "================================DONE==========================================="
+ end
+
+ def self.migration_source_file
+ @version == :old ?
+ File.join(File.dirname(__FILE__), "../assets", "migrate", "create_simple_captcha_data_less_than_2.0.rb") :
+ File.join(File.dirname(__FILE__), "../assets", "migrate", "create_simple_captcha_data.rb")
+ end
+
+ def self.write_migration_content
+ copy_to_path = File.join(RAILS_ROOT, "db", "migrate")
+ migration_filename =
+ Dir.entries(copy_to_path).collect do |file|
+ number, *name = file.split("_")
+ file if name.join("_") == "create_simple_captcha_data.rb"
+ end.compact.first
+ migration_file = File.join(copy_to_path, migration_filename)
+ File.open(migration_file, "wb"){|f| f.write(File.read(migration_source_file))}
+ end
+
+ def self.copy_view_file
+ puts "Copying SimpleCaptcha view file."
+ mkdir(File.join(RAILS_ROOT, "app/views/simple_captcha")) unless File.exist?(File.join(RAILS_ROOT, "app/views/simple_captcha"))
+ view_file = @version == :old ? '_simple_captcha.rhtml' : '_simple_captcha.erb'
+ FileUtils.cp_r(
+ File.join(File.dirname(__FILE__), "../assets/views/simple_captcha/_simple_captcha.erb"),
+ File.join(RAILS_ROOT, "app/views/simple_captcha/", view_file)
+ )
+ puts "================================DONE==========================================="
+ end
+ end
+end
@@ -3,65 +3,13 @@
require 'fileutils'
namespace :simple_captcha do
-
- def generate_migration
- puts "==============================================================================="
- puts "ruby script/generate migration create_simple_captcha_data"
- puts %x{ruby script/generate migration create_simple_captcha_data}
- puts "================================DONE==========================================="
- end
-
- def migration_source_file
- @rails == 'old' ?
- File.join(File.dirname(__FILE__), "../assets", "migrate", "create_simple_captcha_data_less_than_2.0.rb") :
- File.join(File.dirname(__FILE__), "../assets", "migrate", "create_simple_captcha_data.rb")
- end
-
- def write_migration_content
- copy_to_path = File.join(RAILS_ROOT, "db", "migrate")
- migration_filename =
- Dir.entries(copy_to_path).collect do |file|
- number, *name = file.split("_")
- file if name.join("_") == "create_simple_captcha_data.rb"
- end.compact.first
- migration_file = File.join(copy_to_path, migration_filename)
- File.open(migration_file, "wb"){|f| f.write(File.read(migration_source_file))}
- end
-
- def copy_view_file
- puts "Copying SimpleCaptcha view file."
- mkdir(File.join(RAILS_ROOT, "app/views/simple_captcha")) unless File.exist?(File.join(RAILS_ROOT, "app/views/simple_captcha"))
- view_file = @rails == 'old' ? '_simple_captcha.rhtml' : '_simple_captcha.erb'
- FileUtils.cp_r(
- File.join(File.dirname(__FILE__), "../assets/views/simple_captcha/_simple_captcha.erb"),
- File.join(RAILS_ROOT, "app/views/simple_captcha/", view_file)
- )
- puts "================================DONE==========================================="
- end
-
- def do_setup
- begin
- puts "STEP 1"
- generate_migration
- write_migration_content
- copy_view_file
- puts "Followup Steps"
- puts "STEP 2 -- run the task 'rake db:migrate'"
- puts "STEP 3 -- edit the file config/routes.rb to add the route \"map.simple_captcha '/simple_captcha/:action', :controller => 'simple_captcha'\""
- rescue StandardError => e
- p e
- end
- end
-
desc "Set up the plugin SimpleCaptcha for rails < 2.0"
- task :setup_old do
- @rails = 'old'
- do_setup
+ task :setup_old => :environment do
+ SimpleCaptcha::SetupTasks.do_setup(:old)
end
desc "Set up the plugin SimpleCaptcha for rails >= 2.0"
- task :setup do
- do_setup
+ task :setup => :environment do
+ SimpleCaptcha::SetupTasks.do_setup
end
-
end

0 comments on commit 9c1b107

Please sign in to comment.