Browse files

Compatible with Ruby 1.9.1

  • Loading branch information...
1 parent f39c738 commit 4ab94372f47ba63093c229f746e9b36883fba62f Winton Welsh committed Nov 28, 2009
Showing with 58 additions and 63 deletions.
  1. +5 −0 README.markdown
  2. +26 −25 Rakefile
  3. +0 −36 captcha.gemspec
  4. +21 −0 gemspec.rb
  5. +6 −2 lib/captcha/cipher.rb
View
5 README.markdown
@@ -14,6 +14,11 @@ Goals
* Colors, wave, implode
* Handle lots of users
+Compatibility
+-------------
+
+Tested with Ruby 1.8.6, 1.8.7, and 1.9.1.
+
Install
-------
View
51 Rakefile
@@ -1,31 +1,32 @@
+require 'rubygems'
require 'rake'
+require 'rake/gempackagetask'
+require 'spec/rake/spectask'
+require 'gemspec'
-task :default => 'captcha.gemspec'
-
-file 'captcha.gemspec' => FileList['{lib,spec}/**','Rakefile'] do |f|
- # read spec file and split out manifest section
- spec = File.read(f.name)
- parts = spec.split(" # = MANIFEST =\n")
- fail 'bad spec' if parts.length != 3
- # determine file list from git ls-files
- files = `git ls-files`.
- split("\n").
- sort.
- reject{ |file| file =~ /^\./ }.
- reject { |file| file =~ /^doc/ }.
- map{ |file| " #{file}" }.
- join("\n")
- # piece file back together and write...
- parts[1] = " s.files = %w[\n#{files}\n ]\n"
- spec = parts.join(" # = MANIFEST =\n")
- File.open(f.name, 'w') { |io| io.write(spec) }
- puts "Updated #{f.name}"
+desc "Generate gemspec"
+task :gemspec do
+ File.open("#{Dir.pwd}/#{GEM_NAME}.gemspec", 'w') do |f|
+ f.write(GEM_SPEC.to_ruby)
+ end
end
-# sudo rake install
+desc "Install gem"
task :install do
- `sudo gem uninstall captcha -x`
- `gem build captcha.gemspec`
- `sudo gem install captcha*.gem`
- `rm captcha*.gem`
+ Rake::Task['gem'].invoke
+ `sudo gem uninstall #{GEM_NAME} -x`
+ `sudo gem install pkg/#{GEM_NAME}*.gem`
+ `rm -Rf pkg`
+end
+
+desc "Package gem"
+Rake::GemPackageTask.new(GEM_SPEC) do |pkg|
+ pkg.gem_spec = GEM_SPEC
+end
+
+desc "Run specs"
+Spec::Rake::SpecTask.new do |t|
+ t.rcov = true
+ t.spec_opts = ["--format", "specdoc", "--colour"]
+ t.spec_files = FileList["spec/**/*_spec.rb"]
end
View
36 captcha.gemspec
@@ -1,36 +0,0 @@
-Gem::Specification.new do |s|
- s.name = 'captcha'
- s.version = '1.2.1'
- s.date = '2009-03-27'
-
- s.summary = "A Google-style captcha for enterprise Rails apps"
- s.description = "A Google-style captcha for enterprise Rails apps"
-
- s.author = 'Winton Welsh'
- s.email = 'mail@wintoni.us'
- s.homepage = 'http://github.com/winton/captcha'
-
- s.has_rdoc = false
-
- # = MANIFEST =
- s.files = %w[
- MIT-LICENSE
- README.markdown
- Rakefile
- captcha.gemspec
- init.rb
- lib/captcha.rb
- lib/captcha/action.rb
- lib/captcha/cipher.rb
- lib/captcha/config.rb
- lib/captcha/generator.rb
- lib/captcha/image.rb
- lib/captcha/model.rb
- resources/captcha.ttf
- spec/lib/captcha_spec.rb
- spec/spec.opts
- spec/spec_helper.rb
- tasks/captcha.rake
- ]
- # = MANIFEST =
-end
View
21 gemspec.rb
@@ -0,0 +1,21 @@
+GEM_NAME = 'captcha'
+GEM_FILES = FileList['**/*'] - FileList[
+ 'coverage', 'coverage/**/*',
+ 'pkg', 'pkg/**/*'
+]
+GEM_SPEC = Gem::Specification.new do |s|
+ # == CONFIGURE ==
+ s.author = "Winton Welsh"
+ s.email = "mail@wintoni.us"
+ s.homepage = "http://github.com/winton/#{GEM_NAME}"
+ s.summary = "A Google-style captcha for enterprise Rails apps"
+ # == CONFIGURE ==
+ s.add_dependency('rmagick', '>=2.9.2')
+ s.extra_rdoc_files = [ "README.markdown" ]
+ s.files = GEM_FILES.to_a
+ s.has_rdoc = false
+ s.name = GEM_NAME
+ s.platform = Gem::Platform::RUBY
+ s.require_path = "lib"
+ s.version = "1.2.2"
+end
View
8 lib/captcha/cipher.rb
@@ -16,8 +16,12 @@ def self.encrypt(text)
encrypted << cipher.final
# Turn into chr codes separated by underscores
# 135_14_163_53_43_135_172_31_1_23_169_81_49_110_49_230
- encrypted = (0..encrypted.length-1).collect do |x|
- encrypted[x]
+ if encrypted.respond_to?(:codepoints)
+ encrypted = encrypted.codepoints.to_a
+ else
+ encrypted = (0..encrypted.length-1).collect do |x|
+ encrypted[x]
+ end
end
encrypted.join('_')
end

0 comments on commit 4ab9437

Please sign in to comment.