2010-05-08 16:27:49 -04:00
|
|
|
class Topic
|
|
|
|
include ActiveModel::Validations
|
2010-08-20 10:17:29 -04:00
|
|
|
include ActiveModel::Validations::Callbacks
|
2010-05-08 16:27:49 -04:00
|
|
|
|
2011-02-05 19:00:57 -05:00
|
|
|
def self._validates_default_keys
|
|
|
|
super | [ :message ]
|
|
|
|
end
|
|
|
|
|
2013-10-23 09:01:14 -04:00
|
|
|
attr_accessor :title, :author_name, :content, :approved, :created_at
|
2010-08-20 10:17:29 -04:00
|
|
|
attr_accessor :after_validation_performed
|
|
|
|
|
|
|
|
after_validation :perform_after_validation
|
2010-05-08 16:27:49 -04:00
|
|
|
|
|
|
|
def initialize(attributes = {})
|
|
|
|
attributes.each do |key, value|
|
|
|
|
send "#{key}=", value
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2009-03-20 11:07:49 -04:00
|
|
|
def condition_is_true
|
|
|
|
true
|
|
|
|
end
|
|
|
|
|
|
|
|
def condition_is_true_but_its_not
|
|
|
|
false
|
|
|
|
end
|
2010-08-20 10:17:29 -04:00
|
|
|
|
|
|
|
def perform_after_validation
|
|
|
|
self.after_validation_performed = true
|
|
|
|
end
|
|
|
|
|
2011-02-05 19:33:00 -05:00
|
|
|
def my_validation
|
|
|
|
errors.add :title, "is missing" unless title
|
|
|
|
end
|
|
|
|
|
2011-02-05 19:44:35 -05:00
|
|
|
def my_validation_with_arg(attr)
|
|
|
|
errors.add attr, "is missing" unless send(attr)
|
|
|
|
end
|
|
|
|
|
2014-08-03 01:50:09 -04:00
|
|
|
def my_word_tokenizer(str)
|
|
|
|
str.scan(/\w+/)
|
|
|
|
end
|
|
|
|
|
2009-03-20 11:07:49 -04:00
|
|
|
end
|