Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/simple_captcha/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ class Engine < ::Rails::Engine
end
when 'mongoid'
require 'simple_captcha/simple_captcha_data_mongoid.rb'
when 'mongomapper'
require 'simple_captcha/simple_captcha_data_mongomapper.rb'
when 'redis'
require 'simple_captcha/simple_captcha_data_redis.rb'
else
Expand Down
26 changes: 26 additions & 0 deletions lib/simple_captcha/simple_captcha_data_mongomapper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
module SimpleCaptcha
class SimpleCaptchaData
include MongoMapper::Document
plugin MongoMapper::Plugins::Timestamps
timestamps!

key :key, String, :required => true
key :value, String, :required => true

class << self
def get_data(key)
data = where(:key => key).first || new(:key => key)
end

def remove_data(key)
where(:key => key).remove
clear_old_data(1.hour.ago)
end

def clear_old_data(time = 1.hour.ago)
return unless Time === time
where(:updated_at.lte => time).remove
end
end
end
end