Sha256: 0dc18196ffe3fd22df1b2908726056b17dba4b60a262e4932f554480f4f8c217

Contents?: true

Size: 981 Bytes

Versions: 26

Compression:

Stored size: 981 Bytes

Contents

require 'digest/sha1'

module SimpleCaptcha #:nodoc
  module Utils #:nodoc
    # Execute command with params and return output if exit status equal expected_outcodes
    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

    def self.simple_captcha_value(key) #:nodoc
      SimpleCaptchaData.get_data(key).value rescue nil
    end

    def self.simple_captcha_passed!(key) #:nodoc
      SimpleCaptchaData.remove_data(key)
    end

    def self.generate_key(*args)
      args << Time.now.to_s
      Digest::SHA1.hexdigest(args.join)
    end
  end
end

Version data entries

26 entries across 26 versions & 9 rubygems

Version Path
simple_captcha2-0.3.3 lib/simple_captcha/utils.rb
simple_captcha2-0.3.2 lib/simple_captcha/utils.rb
simple_captcha2-0.3.1 lib/simple_captcha/utils.rb
simple_captcha2-0.2.2 lib/simple_captcha/utils.rb
simple_captcha2-0.3.0 lib/simple_captcha/utils.rb
simple_captcha2-0.2.1 lib/simple_captcha/utils.rb
simple_captcha2-0.2.0 lib/simple_captcha/utils.rb
wxianfeng_simple_captcha-0.5.0 lib/simple_captcha/utils.rb
pludoni-simple_captcha-0.1.6 lib/simple_captcha/utils.rb
wxianfeng_simple_captcha-0.4.0 lib/simple_captcha/utils.rb
wxianfeng_simple_captcha-0.3.0 lib/simple_captcha/utils.rb
galetahub-simple_captcha-0.1.5 lib/simple_captcha/utils.rb
galetahub-simple_captcha-0.1.4 lib/simple_captcha/utils.rb
loyal_simple_captcha-0.0.1 lib/simple_captcha/utils.rb
glebtv-simple_captcha-0.1.6 lib/simple_captcha/utils.rb
foco-simple_captcha-0.1.3 lib/simple_captcha/utils.rb
nahaylo-simple_captcha-0.2.0 lib/simple_captcha/utils.rb
wxianfeng_simple_captcha-0.2.0 lib/simple_captcha/utils.rb
wxianfeng_simple_captcha-0.1.0 lib/simple_captcha/utils.rb
wolcanus-simple_captcha-0.1.6 lib/simple_captcha/utils.rb