File: simple_captcha_data_mongoid.rb

package info (click to toggle)
ruby-simple-captcha2 0.5.0-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 168 kB
  • sloc: ruby: 589; makefile: 2
file content (25 lines) | stat: -rw-r--r-- 565 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
module SimpleCaptcha
  class SimpleCaptchaData
    include Mongoid::Document
    include Mongoid::Timestamps

    field :key, type: String
    field :value, type: String

    class << self
      def get_data(key)
        data = where(:key => key).first || new(:key => key)
      end
      
      def remove_data(key)
        where(:key => key).delete_all
        clear_old_data(1.hour.ago)
      end
      
      def clear_old_data(time = 1.hour.ago)
        return unless Time === time
        where(:updated_at.lte => time).delete_all
      end
    end
  end
end