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
e7f7ef43
Commit
e7f7ef43
authored
Mar 19, 2011
by
John E. Vincent
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
preliminary tagging and linking support
parent
140f5211
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
67 additions
and
0 deletions
+67
-0
models.rb
lib/noah/models.rb
+17
-0
link.rb
lib/noah/models/link.rb
+37
-0
tags.rb
lib/noah/models/tags.rb
+13
-0
No files found.
lib/noah/models.rb
View file @
e7f7ef43
...
...
@@ -9,6 +9,9 @@ module Noah
model
.
send
:include
,
Ohm
::
Callbacks
model
.
send
:include
,
Ohm
::
ExtraValidations
model
.
send
:attribute
,
:tags
model
.
send
:index
,
:tag
# removing this as it's simply redundant
# model.after :save, :notify_via_redis_save
model
.
after
:create
,
:notify_via_redis_create
...
...
@@ -25,6 +28,9 @@ module Noah
self
.
created_at
==
self
.
updated_at
end
def
tag
(
tags
=
self
.
tags
)
tags
.
to_s
.
split
(
/\s*,\s*/
).
uniq
end
def
watch!
(
opts
=
{
:endpoint
=>
nil
,
:pattern
=>
nil
})
base_pattern
=
"
#{
self
.
patternize_me
}
"
...
...
@@ -53,6 +59,7 @@ module Noah
def
class_to_lower
self
.
class
.
to_s
.
gsub
(
/(.*)::(\w)/
,
'\2'
).
downcase
end
def
dbnum
o
=
Ohm
.
options
.
first
return
"0"
if
o
.
nil?
...
...
@@ -60,6 +67,15 @@ 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
...
...
@@ -79,6 +95,7 @@ module Noah
end
end
require
File
.
join
(
File
.
dirname
(
__FILE__
),
'models'
,
'tags'
)
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/link.rb
0 → 100644
View file @
e7f7ef43
module
Noah
class
Link
<
Model
attribute
:path
attribute
:nodes
index
:path
# Nothing to see yet.
# This will be for creating "overlays" or "link" relationships
# between arbitrary objects or modeling your data the way you want.
#
# Example:
# path = "/myservers"
# path.nodes = ["/applications/myapp","/some/ephemeral/path", "sometag"]
#
# would result in a structure like:
# path/
# applications/
# myapp
# some/ephemeral/path/
# child1
# child2
# child3
# sometag/
# tagged_item1
# tagged_item2
# tagged_item4
# tagged_item5
#
# The idea is to create a blended view across opinionated, tagged and
# ephemeral nodes.
#
# Almost a "choose your own model" thing.
end
end
lib/noah/models/tags.rb
0 → 100644
View file @
e7f7ef43
module
Noah
class
Tag
<
Model
counter
:total
def
name
@name
=
id
end
def
self
.
[]
(
id
)
super
(
encode
(
id
))
||
create
(
:id
=>
encode
(
id
))
end
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