Sha256: baa5652e799abcf6501357065d1356ad6f652d4dd644714c4563b1113f72fc79

Contents?: true

Size: 984 Bytes

Versions: 1

Compression:

Stored size: 984 Bytes

Contents

module SoaringSimpleCaptcha
  class SimpleCaptchaData < ::ActiveRecord::Base
    
    if ::ActiveRecord::VERSION::MAJOR >= 3
      # Fixes deprecation warning in Rails 3.2:
      # DEPRECATION WARNING: Calling set_table_name is deprecated. Please use `self.table_name = 'the_name'` instead.
      self.table_name = "simple_captcha_data"
    else
      set_table_name "simple_captcha_data"
    end
    
    #attr_accessible :key, :value
    
    class << self
      def get_data(key)
        data = find_by_key(key) || new(:key => key)
      end
      
      def remove_data(key)
#         delete_all(["#{connection.quote_column_name(:key)} = ?", key])
        find_by(key: key).destroy
        clear_old_data(1.hour.ago)
      end
      
      def clear_old_data(time = 1.hour.ago)
        return unless Time === time
#         delete_all(["#{connection.quote_column_name(:updated_at)} < ?", time])
        where("updated_at < ?", time).each{|r|r.destroy}
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
soaring_simple_captcha-0.1.6 lib/soaring_simple_captcha/simple_captcha_data.rb