Skip to content
Browse files

adding rake task to generate config (Rails 3.* only)

  • Loading branch information...
1 parent 4acef74 commit 2d456986484237974e6c1c570d2cb9da04fafdcf @matthutchinson committed Sep 20, 2010
View
2 Rakefile
@@ -40,7 +40,7 @@ begin
gemspec.email = "matt@hiddenloop.com"
gemspec.homepage = "http://github.com/matthutchinson/acts_as_textcaptcha"
gemspec.authors = ["Matthew Hutchinson"]
- gemspec.files = Dir.glob("{lib}/**/*")
+ gemspec.files = [Dir.glob("{lib}/**/*"), Dir.glob("{config}/*")]
gemspec.add_dependency('bcrypt-ruby', '~> 2.1.2')
end
Jeweler::GemcutterTasks.new
View
10 acts_as_textcaptcha.gemspec
@@ -5,11 +5,11 @@
Gem::Specification.new do |s|
s.name = %q{acts_as_textcaptcha}
- s.version = "2.1.4"
+ s.version = "2.1.5"
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["Matthew Hutchinson"]
- s.date = %q{2010-09-17}
+ s.date = %q{2010-09-20}
s.description = %q{Spam protection for your ActiveRecord models using logic questions and the excellent textcaptcha api. See textcaptcha.com for more details and to get your api key.
The logic questions are aimed at a child's age of 7, so can be solved easily by all but the most cognitively impaired users. As they involve human logic, such questions cannot be solved by a robot.
For more reasons on why logic questions are useful, see here; http://textcaptcha.com/why}
@@ -19,11 +19,13 @@ Gem::Specification.new do |s|
"README.rdoc"
]
s.files = [
- "lib/acts_as_textcaptcha.rb",
+ "config/textcaptcha.yml",
+ "lib/acts_as_textcaptcha.rb",
"lib/acts_as_textcaptcha/framework/rails2.rb",
"lib/acts_as_textcaptcha/framework/rails3.rb",
"lib/acts_as_textcaptcha/textcaptcha.rb",
- "lib/acts_as_textcaptcha/textcaptcha_helper.rb"
+ "lib/acts_as_textcaptcha/textcaptcha_helper.rb",
+ "lib/tasks/textcaptcha.rake"
]
s.homepage = %q{http://github.com/matthutchinson/acts_as_textcaptcha}
s.rdoc_options = ["--charset=UTF-8"]
View
2 lib/acts_as_textcaptcha/framework/rails3.rb
@@ -4,4 +4,4 @@
ActiveSupport.on_load(:action_controller) do
include ActsAsTextcaptcha::TextcaptchaHelper
-end
+end
View
11 lib/acts_as_textcaptcha/textcaptcha.rb
@@ -15,6 +15,13 @@
end
module ActsAsTextcaptcha
+
+ class Railtie < ::Rails::Railtie
+ rake_tasks do
+ load "tasks/textcaptcha.rake"
+ end
+ end
+
module Textcaptcha #:nodoc:
def acts_as_textcaptcha(options = nil)
@@ -45,9 +52,9 @@ def perform_spam_check?; true end
# if returning false model.validate will always be false with errors on base
def allowed?; true end
- def validate_textcaptcha
+ def validate_textcaptcha
# if not new_record? we dont spam check on existing records (ie. no spam check on updates/edits)
- if !respond_to?('new_record?') || new_record?
+ if !respond_to?('new_record?') || new_record?
if allowed?
if possible_answers && perform_spam_check? && !validate_spam_answer
errors.add(:spam_answer, 'is incorrect, try another question instead')
View
23 lib/tasks/textcaptcha.rake
@@ -0,0 +1,23 @@
+namespace :textcaptcha do
+ desc "Adds a textcaptcha.yml template config file to ./config "
+ task :generate_config do
+
+ src = File.join(File.dirname(__FILE__), '../..', 'config', 'textcaptcha.yml')
+ dest = File.join(Rails.root, 'config', 'textcaptcha.yml')
+ if File.exist?(dest)
+ puts "\ntextcaptcha config file: #{dest}\n ... already exists. Aborting.\n\n"
+ else
+ config_file = ''
+ f = File.open(src, 'r')
+ f.each_line { |line| config_file += line }
+ config_file.gsub!(/api\_key\:(.+)$/, 'api_key: # get one at http://textcaptcha.com' )
+ config_file.gsub!(/bcrypt\_salt\:(.+)$/, "bcrypt_salt: #{BCrypt::Engine.generate_salt}" ) if defined?(BCrypt)
+
+ f = File.new(dest, 'w')
+ f.write(config_file)
+ f.close
+ puts "\ntextcaptcha.yml generated at #{dest} (with a new BCrypt salt).\nNOTE: edit this file and add your textcaptcha api key (from http://textcaptcha.com)"
+ end
+
+ end
+end

0 comments on commit 2d45698

Please sign in to comment.
Something went wrong with that request. Please try again.