Sha256: 305f912f8c89da413b0b154a631907577fbc66787a5fde412046fea60b26e2ce

Contents?: true

Size: 940 Bytes

Versions: 1

Compression:

Stored size: 940 Bytes

Contents

require "is_bot/version"
require 'active_record'
require 'action_view'
require 'active_support'

module IsBot
  module CaptchaInReverse
    extend ::ActiveSupport::Concern

    included do 
      class_attribute :captcha_in_reverse
    end

    module ClassMethods
      def validate_captcha(options = {})
        validates_each :captcha_in_reverse do |record, attr, value|
          record.errors[attr] << (options[:message] || "You are a bot!") unless value.blank?
        end
      end
    end
  end

  module ViewHelper
    def captcha_reverse_field(object, options={})
      style = (options.delete(:style) || '') << ";"
      style << "position:absolute;left:-999em;"
      ActionView::Helpers::Tags::TextField.new(
        object, :captcha_in_reverse, self, options.merge(:style => style)
      ).render
    end
  end
end

ActiveRecord::Base.send(:include, IsBot::CaptchaInReverse)
ActionView::Base.send(:include, IsBot::ViewHelper)

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
is_bot-2.0.1 lib/is_bot.rb