Module: Semantic::Antispam::ClassMethods

Defined in:
lib/semantic_antispam/antispam.rb

Instance Method Summary collapse

Instance Method Details

#semantic_antispamObject



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/semantic_antispam/antispam.rb', line 33

def semantic_antispam
  class_eval do
    attr_accessor :antispam_answer
    attr_writer :antispam_hash

    private
    def semantic_antispam_question
      @semantic_antispam_question ||= Semantic::Antispam.questions.sample
      @antispam_hash ||= @semantic_antispam_question[:hash]
      @semantic_antispam_question
    end

    public
    def antispam_question
      semantic_antispam_question[:question]
    end

    def antispam_hash
      semantic_antispam_question[:hash]
    end

    validate :check_semantic_antispam, :on => :create
    private
    def check_semantic_antispam
      errors.add :antispam_answer, I18n.t("semantic_antispam.error_msg", :default=>"SPAM") unless antispam_answer and Semantic::Antispam.find(antispam_hash)[:answer].downcase == antispam_answer.downcase
    end
  end
end