Sha256: 09ceb0328b56a572fb1965ae3ca62e732bfaa4fda34d27568d18b6ec69cbb92e
Contents?: true
Size: 1.41 KB
Versions: 1
Compression:
Stored size: 1.41 KB
Contents
module RmagickCaptcha module ModelAdditions module ClassMethods def has_rmagick_captcha(*symbols) symbols.each do |sym| define_method("#{sym}_key") do @attributes["#{sym}_key"] end define_method("#{sym}_key=") do |val| @attributes["#{sym}_key"]=val end define_method("#{sym}_text") do @attributes["#{sym}_text"] end define_method("#{sym}_text=") do |val| @attributes["#{sym}_text"]=val end define_method("validate_rmagick_#{sym}") do text = @attributes["#{sym}_text"] key = @attributes["#{sym}_key"] if ::Rails.env != 'test' && text != key self.errors.add(:"#{sym}_text") false end end # First parameter should be options hash define_method("reset_#{sym}_key") do |*argv| result = "" parameter1 = argv.first || Hash.new options = ::RmagickCaptcha.options.merge(parameter1) options[:captcha_key_len].times do size = ::RmagickCaptcha.options[:random_chars].size; result << ::RmagickCaptcha.options[:random_chars][rand(size)] end @attributes["#{sym}_key"] = result @attributes["#{sym}_text"] = nil result end end end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
rmagick_captcha-0.6.4 | lib/rmagick_captcha/model_additions.rb |