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

more link work

parent 743c7801
......@@ -17,6 +17,7 @@ require 'yaml'
require 'sinatra/base'
require File.join(File.dirname(__FILE__), 'noah', 'log')
require File.join(File.dirname(__FILE__), 'noah', 'exceptions')
require File.join(File.dirname(__FILE__), 'noah', 'custom_watcher')
require File.join(File.dirname(__FILE__), 'noah','validations')
require File.join(File.dirname(__FILE__), 'noah','models')
......
......@@ -64,6 +64,7 @@ module Noah
load File.join(File.dirname(__FILE__), 'configuration_routes.rb')
load File.join(File.dirname(__FILE__), 'watcher_routes.rb')
load File.join(File.dirname(__FILE__), 'ephemeral_routes.rb')
load File.join(File.dirname(__FILE__), 'link_routes.rb')
end
end
class Noah::App
get '/*/?' do
path = params[:splat][0]
link_name = Noah::Link.find(:path => "/"+path).first
(halt 404) if link_name.nil?
link_name.to_json
end
end
......@@ -75,8 +75,8 @@ module Noah
@deleted_name = self.name
end
def class_to_lower
self.class.to_s.gsub(/(.*)::(\w)/,'\2').downcase
def class_to_lower(class_name = self.class.to_s)
class_name.gsub(/(.*)::(\w)/,'\2').downcase
end
def dbnum
......
......@@ -16,17 +16,16 @@ module Noah
arr = []
self.configurations.sort.each {|c| arr << c.to_hash} if self.configurations.size != 0
super.merge(:name => name, :configurations => arr, :created_at => created_at, :updated_at => updated_at)
#super.merge(:name => name, :created_at => created_at, :updated_at => updated_at)
end
class << self
def find_or_create(opts = {})
begin
find(opts).first.nil? ? (app = create(opts)) : (app = find(opts).first)
if app.valid?
app.save
find(opts).first.nil? ? (obj = new(opts)) : (obj = find(opts).first)
if obj.valid?
obj.save
end
app
obj
rescue Exception => e
e.message
end
......
......@@ -25,11 +25,11 @@ module Noah
class << self
def find_or_create(opts={})
begin
if find(opts).first.nil?
conf = create(opts)
else
conf = find(opts).first
find(opts).first.nil? ? (obj = new(opts)) : (obj = find(opts).first)
if obj.valid?
obj.save
end
obj
rescue Exception => e
e.message
end
......
......@@ -28,12 +28,12 @@ module Noah
def find_or_create(opts = {})
begin
path, data = opts[:path], opts[:data]
find(:path => path).first.nil? ? (eph = new(:path => path)) : (eph = find(:path => path).first)
eph.data = data
if eph.valid?
eph.save
find(:path => path).first.nil? ? (obj = new(:path => path)) : (obj = find(:path => path).first)
obj.data = data
if obj.valid?
obj.save
end
eph
obj
rescue Exception => e
e.message
end
......
......@@ -31,9 +31,26 @@ module Noah
end
def to_hash
n = Array.new
nodes.each {|node| n << node_to_class(node).to_hash} if nodes.size > 0
h = {:name => name, :nodes => n, :created_at => created_at, :updated_at => updated_at}
# TODO Holy shit, is this messy or what?
# Prepopulate instance variables of each object type instead?
%w[applications configurations hosts services ephemerals].each {|x| instance_variable_set("@#{x}", Hash.new)}
if nodes.size > 0
nodes.each do |node|
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})
else
hsh[n.name].merge!(n.to_hash)
end
end
end
h = {:name => name, :hosts => @hosts, :services => @services, :applications => @applications, :configurations => @configurations, :ephemerals => @ephemerals, :created_at => created_at, :updated_at => updated_at}
super.merge(h)
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