added new tag batch change model

This commit is contained in:
albert
2011-08-03 18:32:57 -04:00
parent 04103c3352
commit 3e2b2e7418
6 changed files with 94 additions and 17 deletions

View File

@@ -0,0 +1,24 @@
module Moderator
class TagBatchChange
class Error < Exception ; end
attr_reader :predicate, :consequent
def initialize(predicate, consequent)
@predicate = predicate
@consequent = consequent
end
def execute
raise Error.new("Predicate is missing") if predicate.blank?
normalized_predicate = TagAlias.to_aliased(::Tag.scan_tags(predicate))
normalized_consequent = TagAlias.to_aliased(::Tag.scan_tags(consequent))
::Post.tag_match(predicate).each do |post|
tags = (post.tag_array - normalized_predicate + normalized_consequent).join(" ")
post.update_attributes(:tag_string => tags)
end
end
end
end