Sha256: 49c972f1681bb04723b33330c7d9ba5e0f7a5e444bf4c6ccd39f1fc287341ad5

Contents?: true

Size: 920 Bytes

Versions: 10

Compression:

Stored size: 920 Bytes

Contents

module SimpleCaptcha
  class SimpleCaptchaData < ::ActiveRecord::Base
    def self.rails3?
      ::ActiveRecord::VERSION::MAJOR == 3
    end

    if rails3?
      # 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])
        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])
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 6 rubygems

Version Path
galetahub-simple_captcha-0.1.5 lib/simple_captcha/simple_captcha_data.rb
galetahub-simple_captcha-0.1.4 lib/simple_captcha/simple_captcha_data.rb
loyal_simple_captcha-0.0.1 lib/simple_captcha/simple_captcha_data.rb
glebtv-simple_captcha-0.2.1 lib/simple_captcha/simple_captcha_data_ar.rb
glebtv-simple_captcha-0.2.0 lib/simple_captcha/simple_captcha_data_ar.rb
foco-simple_captcha-0.1.3 lib/simple_captcha/simple_captcha_data.rb
nahaylo-simple_captcha-0.2.0 lib/simple_captcha/simple_captcha_data.rb
the_captcha-0.1.3 lib/simple_captcha/simple_captcha_data.rb
the_captcha-0.1.1 lib/simple_captcha/simple_captcha_data.rb
the_captcha-0.1.0 lib/simple_captcha/simple_captcha_data.rb