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
17cacf42
Commit
17cacf42
authored
Aug 04, 2011
by
John E. Vincent
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
tag DRYup
parent
6eda1500
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
58 additions
and
0 deletions
+58
-0
tag_helpers.rb
lib/noah/helpers/tag_helpers.rb
+46
-0
tags.rb
lib/noah/routes/tags.rb
+12
-0
No files found.
lib/noah/helpers/tag_helpers.rb
View file @
17cacf42
module
Noah
module
SinatraTagHelpers
#TODO DRY this sumbitch up
def
tag
(
primitive
,
name
,
tags
)
case
primitive
when
"services"
servicename
,
hostname
=
name
.
split
(
'/'
)
obj
=
host_service
(
hostname
,
servicename
)
when
"hosts"
obj
=
Noah
::
Host
.
find
(
:name
=>
name
).
first
when
"configurations"
obj
=
Noah
::
Configuration
.
find
(
:name
=>
name
).
first
when
"applications"
obj
=
Noah
::
Application
.
find
(
:name
=>
name
).
first
when
"ephemerals"
obj
=
Noah
::
Ephemeral
.
find
(
:path
=>
"/
#{
name
}
"
).
first
else
halt
404
end
obj
.
nil?
?
(
halt
404
)
:
(
obj
.
tag!
(
tags
))
obj
.
to_json
end
def
untag
(
primitive
,
name
,
tags
)
case
primitive
when
"services"
servicename
,
hostname
=
name
.
split
(
'/'
)
obj
=
host_service
(
hostname
,
servicename
)
when
"hosts"
obj
=
Noah
::
Host
.
find
(
:name
=>
name
).
first
when
"configurations"
obj
=
Noah
::
Configuration
.
find
(
:name
=>
name
).
first
when
"applications"
obj
=
Noah
::
Application
.
find
(
:name
=>
name
).
first
when
"ephemerals"
obj
=
Noah
::
Ephemeral
.
find
(
:path
=>
"/
#{
name
}
"
).
first
else
halt
404
end
obj
.
nil?
?
(
halt
404
)
:
(
obj
.
untag!
(
tags
))
obj
.
to_json
end
end
end
lib/noah/routes/tags.rb
View file @
17cacf42
class
Noah
::
App
class
Noah
::
App
put
'/:primitive/*/tag'
do
|
primitive
,
name
|
required_params
=
[
"tags"
]
data
=
JSON
.
parse
(
request
.
body
.
read
)
(
data
.
keys
.
sort
==
required_params
.
sort
)
?
(
tag
(
primitive
,
name
,
data
[
"tags"
]))
:
(
raise
"Missing Parameters"
)
end
delete
'/:primitive/*/tag'
do
|
primitive
,
name
|
required_params
=
[
"tags"
]
data
=
JSON
.
parse
(
request
.
body
.
read
)
(
data
.
keys
.
sort
==
required_params
.
sort
)
?
(
untag
(
primitive
,
name
,
data
[
"tags"
]))
:
(
raise
"Missing Parameters"
)
end
get
'/tags/:tagname/?'
do
|
tagname
|
get
'/tags/:tagname/?'
do
|
tagname
|
tags
=
Noah
::
Tags
.
all
(
:name
=>
tagname
).
to_hash
tags
=
Noah
::
Tags
.
all
(
:name
=>
tagname
).
to_hash
(
halt
404
)
if
tags
.
size
==
0
(
halt
404
)
if
tags
.
size
==
0
...
...
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