Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
N
Noah
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
Noah
Commits
d849eb55
Commit
d849eb55
authored
Apr 07, 2011
by
John E. Vincent
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
more link work
parent
743c7801
Changes
9
Show whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
46 additions
and
20 deletions
+46
-20
noah.rb
lib/noah.rb
+1
-0
app.rb
lib/noah/app.rb
+1
-0
exceptions.rb
lib/noah/exceptions.rb
+0
-0
link_routes.rb
lib/noah/link_routes.rb
+8
-0
models.rb
lib/noah/models.rb
+2
-2
applications.rb
lib/noah/models/applications.rb
+4
-5
configurations.rb
lib/noah/models/configurations.rb
+5
-5
ephemerals.rb
lib/noah/models/ephemerals.rb
+5
-5
link.rb
lib/noah/models/link.rb
+20
-3
No files found.
lib/noah.rb
View file @
d849eb55
...
...
@@ -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'
)
...
...
lib/noah/app.rb
View file @
d849eb55
...
...
@@ -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
lib/noah/exceptions.rb
0 → 100644
View file @
d849eb55
lib/noah/link_routes.rb
0 → 100644
View file @
d849eb55
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
lib/noah/models.rb
View file @
d849eb55
...
...
@@ -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
...
...
lib/noah/models/applications.rb
View file @
d849eb55
...
...
@@ -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
...
...
lib/noah/models/configurations.rb
View file @
d849eb55
...
...
@@ -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
...
...
lib/noah/models/ephemerals.rb
View file @
d849eb55
...
...
@@ -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
...
...
lib/noah/models/link.rb
View file @
d849eb55
...
...
@@ -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
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment