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
5ea50e75
Commit
5ea50e75
authored
Apr 09, 2011
by
John E. Vincent
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
changing tagging support
parent
d849eb55
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
46 additions
and
28 deletions
+46
-28
models.rb
lib/noah/models.rb
+1
-15
applications.rb
lib/noah/models/applications.rb
+1
-0
configurations.rb
lib/noah/models/configurations.rb
+1
-1
ephemerals.rb
lib/noah/models/ephemerals.rb
+1
-1
hosts.rb
lib/noah/models/hosts.rb
+1
-1
services.rb
lib/noah/models/services.rb
+1
-1
tags.rb
lib/noah/models/tags.rb
+21
-9
taggable.rb
lib/noah/taggable.rb
+19
-0
No files found.
lib/noah/models.rb
View file @
5ea50e75
...
...
@@ -10,8 +10,6 @@ module Noah
model
.
send
:include
,
Ohm
::
Callbacks
model
.
send
:include
,
Ohm
::
ExtraValidations
model
.
send
:attribute
,
:tags
model
.
send
:index
,
:tag
model
.
send
:attribute
,
:metadata
# removing this as it's simply redundant
...
...
@@ -34,10 +32,6 @@ module Noah
self
.
created_at
==
self
.
updated_at
end
def
tag
(
tags
=
self
.
tags
)
tags
.
to_s
.
split
(
/\s*,\s*/
).
uniq
end
def
link!
(
path
)
base_pattern
=
"
#{
self
.
patternize_me
}
"
path
.
nil?
?
(
raise
ArgumentError
,
"Must provide a path"
)
:
p
=
path
...
...
@@ -86,15 +80,6 @@ module Noah
o
[
:db
].
nil?
?
"
#{
o
[
:url
].
split
(
'/'
).
last
}
"
:
"
#{
o
[
:db
]
}
"
end
def
before_update
return
if
new?
tag
(
read_remote
(
:tags
)).
map
(
&
Tag
).
each
{
|
t
|
t
.
decr
:total
}
end
def
after_save
tag
.
map
(
&
Tag
).
each
{
|
t
|
t
.
incr
:total
}
end
[
"create"
,
"update"
,
"delete"
].
each
do
|
meth
|
class_eval
do
define_method
(
"notify_via_redis_
#{
meth
}
"
.
to_sym
)
do
...
...
@@ -128,6 +113,7 @@ module Noah
end
require
File
.
join
(
File
.
dirname
(
__FILE__
),
'models'
,
'tags'
)
require
File
.
join
(
File
.
dirname
(
__FILE__
),
'taggable'
)
require
File
.
join
(
File
.
dirname
(
__FILE__
),
'models'
,
'hosts'
)
require
File
.
join
(
File
.
dirname
(
__FILE__
),
'models'
,
'services'
)
require
File
.
join
(
File
.
dirname
(
__FILE__
),
'models'
,
'applications'
)
...
...
lib/noah/models/applications.rb
View file @
5ea50e75
require
File
.
join
(
File
.
dirname
(
__FILE__
),
'configurations'
)
module
Noah
class
Application
<
Model
include
Taggable
attribute
:name
set
:configurations
,
Configuration
...
...
lib/noah/models/configurations.rb
View file @
5ea50e75
require
File
.
join
(
File
.
dirname
(
__FILE__
),
'applications'
)
module
Noah
class
Configuration
<
Model
include
Taggable
attribute
:name
attribute
:format
attribute
:body
...
...
lib/noah/models/ephemerals.rb
View file @
5ea50e75
module
Noah
class
Ephemeral
<
Model
include
EphemeralValidations
include
Taggable
attribute
:path
attribute
:data
attribute
:lifetime
...
...
lib/noah/models/hosts.rb
View file @
5ea50e75
...
...
@@ -3,7 +3,7 @@ module Noah
class
Host
<
Model
# Host model
# @return {Host} a {Host} object
include
Taggable
attribute
:name
attribute
:status
collection
:services
,
Service
...
...
lib/noah/models/services.rb
View file @
5ea50e75
module
Noah
class
Service
<
Model
include
Taggable
attribute
:name
attribute
:status
reference
:host
,
Host
...
...
lib/noah/models/tags.rb
View file @
5ea50e75
module
Noah
class
Tag
<
Model
counter
:total
attribute
:name
index
:name
def
name
@name
=
id
def
validate
super
assert_present
:name
assert_unique
:name
end
def
self
.
[]
(
id
)
super
(
encode
(
id
))
||
create
(
:id
=>
encode
(
id
))
def
tagged
(
tag
)
# TODO:
#logic to find all models with a given tag
#will need hooks added to taggable module
end
def
tagged
class
<<
self
def
find_or_create
(
opts
=
{})
begin
find
(
opts
).
first
.
nil?
?
obj
=
new
(
opts
)
:
obj
=
find
(
opts
).
first
if
obj
.
valid?
obj
.
save
end
obj
rescue
Exception
=>
e
e
.
message
end
end
def
all
end
end
...
...
lib/noah/taggable.rb
0 → 100644
View file @
5ea50e75
module
Noah::Taggable
def
self
.
included
(
model
)
model
.
send
:set
,
:tags
,
::
Noah
::
Tag
model
.
send
:index
,
:tags
end
def
tag!
(
tag_name
)
tags
<<
::
Noah
::
Tag
.
find_or_create
(
:name
=>
tag_name
)
end
def
untag!
(
tag_name
)
end
def
to_hash
tag_arr
=
[]
self
.
tags
.
sort
.
each
{
|
t
|
tag_arr
<<
t
.
name
}
if
self
.
tags
.
size
!=
0
super
.
merge
(
:tags
=>
tag_arr
)
end
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