Commit e7f7ef43 authored by John E. Vincent's avatar John E. Vincent

preliminary tagging and linking support

parent 140f5211
......@@ -9,6 +9,9 @@ module Noah
model.send :include, Ohm::Callbacks
model.send :include, Ohm::ExtraValidations
model.send :attribute, :tags
model.send :index, :tag
# removing this as it's simply redundant
# model.after :save, :notify_via_redis_save
model.after :create, :notify_via_redis_create
......@@ -25,6 +28,9 @@ module Noah
self.created_at == self.updated_at
end
def tag(tags = self.tags)
tags.to_s.split(/\s*,\s*/).uniq
end
def watch!(opts={:endpoint => nil, :pattern => nil})
base_pattern = "#{self.patternize_me}"
......@@ -53,6 +59,7 @@ module Noah
def class_to_lower
self.class.to_s.gsub(/(.*)::(\w)/,'\2').downcase
end
def dbnum
o = Ohm.options.first
return "0" if o.nil?
......@@ -60,6 +67,15 @@ module Noah
o[:db].nil? ? "#{o[:url].split('/').last}" : "#{o[:db]}"
end
def before_update
return if new?
tag(read_remote(:tags)).map(&Tag).each {|t| t.decr :total}
end
def after_save
tag.map(&Tag).each {|t| t.incr :total }
end
["create", "update", "delete"].each do |meth|
class_eval do
define_method("notify_via_redis_#{meth}".to_sym) do
......@@ -79,6 +95,7 @@ module Noah
end
end
require File.join(File.dirname(__FILE__), 'models','tags')
require File.join(File.dirname(__FILE__), 'models','hosts')
require File.join(File.dirname(__FILE__), 'models','services')
require File.join(File.dirname(__FILE__), 'models','applications')
......
module Noah
class Link < Model
attribute :path
attribute :nodes
index :path
# Nothing to see yet.
# This will be for creating "overlays" or "link" relationships
# between arbitrary objects or modeling your data the way you want.
#
# Example:
# path = "/myservers"
# path.nodes = ["/applications/myapp","/some/ephemeral/path", "sometag"]
#
# would result in a structure like:
# path/
# applications/
# myapp
# some/ephemeral/path/
# child1
# child2
# child3
# sometag/
# tagged_item1
# tagged_item2
# tagged_item4
# tagged_item5
#
# The idea is to create a blended view across opinionated, tagged and
# ephemeral nodes.
#
# Almost a "choose your own model" thing.
end
end
module Noah
class Tag < Model
counter :total
def name
@name = id
end
def self.[](id)
super(encode(id)) || create(:id => encode(id))
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