File: simple_captcha_data_sequel.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 (22 lines) | stat: -rw-r--r-- 476 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
module SimpleCaptcha
  class SimpleCaptchaData < Sequel::Model
    plugin :update_or_create
    plugin :timestamps, update_on_create: true

    class << self
      def get_data(key)
        find_or_new(key: key)
      end

      def remove_data(key)
        where(key: key).delete
        clear_old_data(1.hour.ago)
      end

      def clear_old_data(time = 1.hour.ago)
        return unless Time === time
        where {updated_at < time}.delete
      end
    end
  end
end