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

more link work

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