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

quick tagging fix

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