Commit 1bccdcdc authored by John E. Vincent's avatar John E. Vincent

preliminary untag work

parent b4d89299
......@@ -6,6 +6,15 @@ module Noah
index :members
index :name
def delete
self.members.each_value do |member_array|
member_array.each do |member|
member.tags.key.srem "#{self.id}"
end
end
super
end
def validate
super
assert_present :name
......@@ -29,6 +38,15 @@ module Noah
hsh
end
def delete_member(node)
nc = class_to_lower(node.class.to_s)+"s"
if self.members[nc.to_sym].member?(node)
Ohm.redis.srem("#{self.key}:members", "#{node.key}")
node.untag!(self.name) unless node.tags.member?(self) == false
end
self.save
end
def to_hash
h = {:name => name, :created_at => created_at, :updated_at => updated_at}
h.merge!(members_to_hash)
......
......@@ -17,9 +17,27 @@ module Noah::Taggable
tags << my_tag
my_tag.members = self
end
self.save
end
def untag!(tag_name)
case tag_name.class.to_s
when "Array"
tag_name.each do |t|
my_tag = ::Noah::Tag.find(:name => t).first
if self.tags.member?(my_tag)
self.tags.key.srem "#{my_tag.id}"
my_tag.delete_member(self)
end
end
else
my_tag = ::Noah::Tag.find(:name => tag_name).first
if self.tags.member?(my_tag)
self.tags.key.srem "#{my_tag.id}"
my_tag.delete_member(self)
end
end
self.save
end
def to_hash
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment