Sha256: f10da3fcb8d992763ff4e5659797b6281bdf18612f74652e001bdaaa5e86eab2

Contents?: true

Size: 683 Bytes

Versions: 12

Compression:

Stored size: 683 Bytes

Contents

module SimpleCaptcha
  class SimpleCaptchaData
    include Mongoid::Document
    include Mongoid::Timestamps
    
    store_in collection: "simple_captcha_data"
    
    field :key, :type => String
    field :value, :type => String
    
    class << self
      def get_data(key)
        SimpleCaptchaData.where(:key => key).first || new(:key => key)
      end
      
      def remove_data(key)
        SimpleCaptchaData.where(:key => key).first.delete
        clear_old_data(1.hour.ago)
      end
      
      def clear_old_data(time = 1.hour.ago)
        return unless Time === time
        SimpleCaptchaData.where(:updated_at.lt => time.utc).delete_all
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
glebtv-simple_captcha-0.7.0 lib/simple_captcha/storage/mongoid.rb
glebtv-simple_captcha-0.6.7 lib/simple_captcha/storage/mongoid.rb
glebtv-simple_captcha-0.6.5 lib/simple_captcha/storage/mongoid.rb
glebtv-simple_captcha-0.6.4 lib/simple_captcha/storage/mongoid.rb
glebtv-simple_captcha-0.6.3 lib/simple_captcha/storage/mongoid.rb
glebtv-simple_captcha-0.6.2 lib/simple_captcha/storage/mongoid.rb
glebtv-simple_captcha-0.6.1 lib/simple_captcha/storage/mongoid.rb
glebtv-simple_captcha-0.6.0 lib/simple_captcha/storage/mongoid.rb
glebtv-simple_captcha-0.5.2 lib/simple_captcha/storage/mongoid.rb
glebtv-simple_captcha-0.5.1 lib/simple_captcha/storage/mongoid.rb
glebtv-simple_captcha-0.4.6 lib/simple_captcha/storage/mongoid.rb
glebtv-simple_captcha-0.4.5 lib/simple_captcha/storage/mongoid.rb