Sha256: 19f60d5caeb244139b47bcdeef511f4873989fdafd129d92d84d4051de423d38

Contents?: true

Size: 659 Bytes

Versions: 2

Compression:

Stored size: 659 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

2 entries across 2 versions & 1 rubygems

Version Path
glebtv-simple_captcha-0.8.1 lib/simple_captcha/storage/mongoid.rb
glebtv-simple_captcha-0.8.0 lib/simple_captcha/storage/mongoid.rb