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

link work. unproductive

parent e7f7ef43
module Noah
PROTECTED_PATHS = %w[applications configurations hosts services watches ark noah]
PATH_MAPPING = {"Noah::Application" => "//noah/application",
"Noah::Service" => "//noah/service",
"Noah::Configuration" => "//noah/configuration",
"Noah::Host" => "//noah/host",
"Noah::Tag" => "//noah/tag",
"Noah::Ephemeral" => "//noah/ephemeral"}
end
begin
require 'yajl'
......
require 'logger'
require 'logger'
module Noah::Agents
module Base
......
......@@ -2,6 +2,7 @@ require 'ohm'
require 'ohm/contrib'
module Noah
class Model < Ohm::Model
def self.inherited(model)
model.send :include, Ohm::Timestamping
......@@ -24,6 +25,10 @@ module Noah
module ModelClassMethods
def self.included(base)
Noah::RegisteredModels.register_model(base)
end
def is_new?
self.created_at == self.updated_at
end
......@@ -32,6 +37,19 @@ module Noah
tags.to_s.split(/\s*,\s*/).uniq
end
def link!(path)
base_pattern = "#{self.patternize_me}"
path.nil? ? (raise ArgumentError, "Must provide a path") : p=path
begin
l = Link.new :path => p, :source => base_pattern
l.valid? ? l.save : (raise "#{l.errors}")
l.name
rescue Exception => e
e.message
end
end
def watch!(opts={:endpoint => nil, :pattern => nil})
base_pattern = "#{self.patternize_me}"
opts[:endpoint].nil? ? (raise ArgumentError, "Need an endpoint") : endpoint=opts[:endpoint]
......@@ -94,7 +112,20 @@ module Noah
end
end
class RegisteredModels
@@models = []
def self.register_model(model)
@@models << model
end
def self.models
@@models
end
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')
......
module Noah
class Link < Model
attribute :path
attribute :nodes
attribute :source
index :path
index :source
def validate
super
assert_present :path
assert_present :source
assert_unique [:path, :source]
end
# Nothing to see yet.
# This will be for creating "overlays" or "link" relationships
# between arbitrary objects or modeling your data the way you want.
......@@ -33,5 +39,9 @@ module Noah
#
# Almost a "choose your own model" thing.
def name
@name = path
end
end
end
......@@ -10,4 +10,5 @@ module Noah
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