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
8ffe0176
Commit
8ffe0176
authored
Apr 10, 2011
by
John E. Vincent
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
convert links to 'linkable' module and change link json
parent
6773fbb6
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
36 additions
and
6 deletions
+36
-6
application_routes.rb
lib/noah/application_routes.rb
+5
-2
linkable.rb
lib/noah/linkable.rb
+20
-0
models.rb
lib/noah/models.rb
+2
-1
hosts.rb
lib/noah/models/hosts.rb
+1
-1
link.rb
lib/noah/models/link.rb
+8
-2
No files found.
lib/noah/application_routes.rb
View file @
8ffe0176
...
...
@@ -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
|
...
...
lib/noah/linkable.rb
0 → 100644
View file @
8ffe0176
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
lib/noah/models.rb
View file @
8ffe0176
...
...
@@ -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'
)
lib/noah/models/hosts.rb
View file @
8ffe0176
...
...
@@ -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
...
...
lib/noah/models/link.rb
View file @
8ffe0176
...
...
@@ -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+)$/
)
...
...
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