Commit 3110020f authored by John E. Vincent's avatar John E. Vincent

quick tagging fix

parent 293c86ff
......@@ -7,7 +7,7 @@ module Noah::Linkable
def link!(link_name)
link = Noah::Link.find_or_create(:path => link_name)
link.nodes = self
self.links << link
links << link
end
def unlink!(link_name)
......
......@@ -19,9 +19,11 @@ module Noah
when "Array"
node.each do |n|
self.key[:nodes].sadd(n.key)
n.links << self
end
else
self.key[:nodes].sadd(node.key)
n.links << self
end
end
......
module Noah
class Tag < Model
attribute :name
attribute :members
index :name
def validate
......@@ -9,10 +10,25 @@ module Noah
assert_unique :name
end
def tagged(tag)
# TODO:
#logic to find all models with a given tag
#will need hooks added to taggable module
def members=(member)
self.key[:members].sadd(member.key)
end
def members
hsh = Hash.new
self.key[:members].smembers.each do |member|
n = node_to_class(member)
cls = class_to_lower(n.class.to_s)
hash_key = "#{cls}s".to_sym
hsh[hash_key] = Array.new unless hsh.has_key?(hash_key)
hsh[hash_key] << n.name
end
hsh
end
def self.tagged(tag)
t = find(:name => tag).first
t.members
end
class <<self
......@@ -28,6 +44,12 @@ module Noah
end
end
end
private
def node_to_class(node)
node.match(/^Noah::(.*):(\d+)$/)
Noah.const_get($1).send(:[], $2)
end
end
end
......@@ -8,10 +8,14 @@ module Noah::Taggable
case tag_name.class.to_s
when "Array"
tag_name.each do |t|
tags << ::Noah::Tag.find_or_create(:name => t)
my_tag = ::Noah::Tag.find_or_create(:name => t)
tags << my_tag
my_tag.members = self
end
else
tags << Noah::Tag.find_or_create(:name => tag_name)
my_tag = ::Noah::Tag.find_or_create(:name => tag_name)
tags << my_tag
my_tag.members = self
end
end
......
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