Sha256: ca5384e281c3cae4f944c32c7445580e71b66f240bc4cee2d0b092728276ab86

Contents?: true

Size: 740 Bytes

Versions: 9

Compression:

Stored size: 740 Bytes

Contents

# coding: utf-8
module RailsCaptcha
  module Action

    def self.included(base)
      base.extend ClassMethods
    end

    module ClassMethods
      def acts_as_captcha
        unless included_modules.include? InstanceMethods
          include InstanceMethods
        end
        before_filter :assign_captcha
      end
    end

    module InstanceMethods
      private

      def assign_captcha
        unless session[:captcha] && RailsCaptcha::Config.exists?(session[:captcha])
          files = RailsCaptcha::Config.captchas
          session[:captcha] = File.basename(files[rand(files.length)], '.jpg')
        end
      end

      def reset_captcha
        session[:captcha] = nil
        assign_captcha
      end
    end

  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
rails_captcha-0.0.10 lib/rails_captcha/captcha/action.rb
rails_captcha-0.0.8 lib/rails_captcha/captcha/action.rb
rails_captcha-0.0.7 lib/rails_captcha/captcha/action.rb
rails_captcha-0.0.6 lib/rails_captcha/captcha/action.rb
rails_captcha-0.0.5 lib/rails_captcha/captcha/action.rb
rails_captcha-0.0.4 lib/rails_captcha/captcha/action.rb
rails_captcha-0.0.3 lib/rails_captcha/captcha/action.rb
rails_captcha-0.0.2 lib/rails_captcha/captcha/action.rb
rails_captcha-0.0.1 lib/rails_captcha/captcha/action.rb