Module: SimpleCaptcha::Utils
- Defined in:
- lib/simple_captcha/utils.rb
Overview
:nodoc
Class Method Summary collapse
- .generate_key(*args) ⇒ Object
- .random_str ⇒ Object
-
.run(cmd, params = "", expected_outcodes = 0) ⇒ Object
Execute command with params and return output if exit status equal expected_outcodes.
-
.simple_captcha_new_value(key) ⇒ Object
:nodoc.
-
.simple_captcha_passed!(key) ⇒ Object
:nodoc.
-
.simple_captcha_value(key) ⇒ Object
:nodoc.
Class Method Details
.generate_key(*args) ⇒ Object
49 50 51 52 |
# File 'lib/simple_captcha/utils.rb', line 49 def self.generate_key(*args) args << Time.now.to_s Digest::SHA1.hexdigest(args.join) end |
.random_str ⇒ Object
27 28 29 30 31 32 |
# File 'lib/simple_captcha/utils.rb', line 27 def self.random_str() charset = SimpleCaptcha.charset.split(//) size = SimpleCaptcha.length (0...size).map{ charset.to_a[rand(charset.size)] }.join end |
.run(cmd, params = "", expected_outcodes = 0) ⇒ Object
Execute command with params and return output if exit status equal expected_outcodes
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/simple_captcha/utils.rb', line 6 def self.run(cmd, params = "", expected_outcodes = 0) command = %Q[#{cmd} #{params}].gsub(/\s+/, " ") command = "#{command} 2>&1" unless (image_magick_path = SimpleCaptcha.image_magick_path).blank? command = File.join(image_magick_path, command) end output = `#{command}` unless [expected_outcodes].flatten.include?($?.exitstatus) raise ::StandardError, "Error while running #{cmd}: #{output}" end output end |
.simple_captcha_new_value(key) ⇒ Object
:nodoc
34 35 36 37 38 39 40 41 42 43 |
# File 'lib/simple_captcha/utils.rb', line 34 def self.simple_captcha_new_value(key) #:nodoc begin d = SimpleCaptchaData.get_data(key) d.value = self.random_str d.save! d.value rescue nil end end |
.simple_captcha_passed!(key) ⇒ Object
:nodoc
45 46 47 |
# File 'lib/simple_captcha/utils.rb', line 45 def self.simple_captcha_passed!(key) #:nodoc SimpleCaptchaData.remove_data(key) end |
.simple_captcha_value(key) ⇒ Object
:nodoc
23 24 25 |
# File 'lib/simple_captcha/utils.rb', line 23 def self.simple_captcha_value(key) #:nodoc SimpleCaptchaData.get_data(key).value rescue nil end |