Sha256: bd85276e9eaaf58d9cf7aaa6a85f3e058e750f4d091b16187a7b149bbaac72b7

Contents?: true

Size: 631 Bytes

Versions: 3

Compression:

Stored size: 631 Bytes

Contents

module SimpleCaptcha
  class SimpleCaptchaData
    include Mongoid::Document
    include Mongoid::Timestamps
    
    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

3 entries across 3 versions & 1 rubygems

Version Path
glebtv-simple_captcha-0.4.3 lib/simple_captcha/storage/mongoid.rb
glebtv-simple_captcha-0.4.1 lib/simple_captcha/storage/mongoid.rb
glebtv-simple_captcha-0.3.1 lib/simple_captcha/storage/mongoid.rb