Sha256: 9a246d1427d5de5d4148001ab7af2eb57f0bfbfae0eba850fb48822909952bd2

Contents?: true

Size: 1.02 KB

Versions: 9

Compression:

Stored size: 1.02 KB

Contents

# coding: utf-8
module RailsCaptcha
  class Generator
    def initialize
      generate
    end

    def generate
      require 'etc'
      uid = File.stat("#{Rails.root}/Gemfile").uid
      owner = Etc.getpwuid(uid).name
      return unless Config.options
      return if Config.last_modified && Config.last_modified > Time.now - Config.options[:generate_every]
      path = Rails.root.join(Config.options[:destination])
      Config.captchas.each do |captcha|
        FileUtils.rm_f captcha
      end
      FileUtils.rm_rf path
      FileUtils.mkdir path
      FileUtils.chown_R owner, owner, path if Rails.env.production?
      (1..Config.options[:count]).each do |x|
        image = Image.new Config.options
        path = "#{Config.options[:destination]}/#{Cipher.encrypt(image.code)}.jpg"
        next if File.exists?(path)
        File.open(path, 'w') do |f|
          FileUtils.chown owner, owner, path if Rails.env.production?
          f << image.data.force_encoding("UTF-8")
        end
      end
      GC.start
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
rails_captcha-0.0.10 lib/rails_captcha/captcha/generator.rb
rails_captcha-0.0.8 lib/rails_captcha/captcha/generator.rb
rails_captcha-0.0.7 lib/rails_captcha/captcha/generator.rb
rails_captcha-0.0.6 lib/rails_captcha/captcha/generator.rb
rails_captcha-0.0.5 lib/rails_captcha/captcha/generator.rb
rails_captcha-0.0.4 lib/rails_captcha/captcha/generator.rb
rails_captcha-0.0.3 lib/rails_captcha/captcha/generator.rb
rails_captcha-0.0.2 lib/rails_captcha/captcha/generator.rb
rails_captcha-0.0.1 lib/rails_captcha/captcha/generator.rb