Commit 8ffe0176 authored by John E. Vincent's avatar John E. Vincent

convert links to 'linkable' module and change link json

parent 6773fbb6
......@@ -35,8 +35,11 @@ class Noah::App
w.to_json
end
put '/applications/:appname/link/:linkname' do |appname, linkname|
put '/applications/:appname/link' do |appname|
required_params = ["link_name"]
data = JSON.parse(request.body.read)
(data.keys.sort == required_params.sort) ? (a = Noah::Applicaiton.find(:name => appname).first) : (raise "Missing Parameters")
#a.nil? ? (halt 404) : (a.link!
end
put '/applications/:appname/?' do |appname|
......
module Noah::Linkable
def self.included(model)
model.send :set, :links, ::Noah::Link
model.send :index, :links
end
def link!(link_name)
link = Noah::Link.find_or_create(:path => link_name)
link.nodes = self
end
def unlink!(link_name)
end
def to_hash
link_arr = Array.new
self.links.sort.each {|l| link_arr << l.path} if self.links.size != 0
super.merge(:links => link_arr)
end
end
......@@ -112,11 +112,12 @@ module Noah
end
require File.join(File.dirname(__FILE__), 'models','tags')
require File.join(File.dirname(__FILE__), 'models','link')
require File.join(File.dirname(__FILE__), 'taggable')
require File.join(File.dirname(__FILE__), 'linkable')
require File.join(File.dirname(__FILE__), 'models','hosts')
require File.join(File.dirname(__FILE__), 'models','services')
require File.join(File.dirname(__FILE__), 'models','applications')
require File.join(File.dirname(__FILE__), 'models','configurations')
require File.join(File.dirname(__FILE__), 'models','watchers')
require File.join(File.dirname(__FILE__), 'models','ephemerals')
require File.join(File.dirname(__FILE__), 'models','link')
......@@ -22,7 +22,7 @@ module Noah
# @return [Hash] A hash representation of a {Host}
def to_hash
arr = []
services.sort.each {|s| arr << s.to_hash}
services.sort.each {|s| arr << {:id => s.id, :status => s.status, :name => s.name}}
h = {:name => name, :status => status, :created_at => created_at, :updated_at => updated_at, :services => arr}
super.merge(h)
end
......
......@@ -39,15 +39,19 @@ module Noah
n = node_to_class(node)
cls = class_to_lower(n.class.to_s)
hsh = instance_variable_get("@#{cls}s")
hsh["#{n.name}"] = Hash.new unless hsh.has_key?(n.name)
# all of this bs is because services are unique per [servicename, hostname]
# so if I add multiple services just by name to the hash, I'll wipe the previous one
# a better option would be for services to be named slug style
if cls == "service"
hsh[n.name].merge!({n.to_hash[:host] => n.to_hash})
hsh["#{n.name}-#{n.id}"] = Hash.new unless hsh.has_key?("#{n.name}-#{n.id}")
hsh["#{n.name}-#{n.id}"].merge!({n.to_hash[:host] => n.to_hash})
else
hsh["#{n.name}"] = Hash.new unless hsh.has_key?(n.name)
hsh[n.name].merge!(n.to_hash)
end
# all of this bs is because services are unique per [servicename, hostname]
# so if I add multiple services just by name to the hash, I'll wipe the previous one
# a better option would be for services to be named slug style
end
end
h = {:name => name, :hosts => @hosts, :services => @services, :applications => @applications, :configurations => @configurations, :ephemerals => @ephemerals, :created_at => created_at, :updated_at => updated_at}
......@@ -57,6 +61,7 @@ module Noah
def name
@name = path
end
class <<self
def find_or_create(opts={})
begin
......@@ -70,6 +75,7 @@ module Noah
end
end
end
private
def node_to_class(node)
node.match(/^Noah::(.*):(\d+)$/)
......
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