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
3110020f
Commit
3110020f
authored
Apr 11, 2011
by
John E. Vincent
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
quick tagging fix
parent
293c86ff
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
35 additions
and
7 deletions
+35
-7
linkable.rb
lib/noah/linkable.rb
+1
-1
link.rb
lib/noah/models/link.rb
+2
-0
tags.rb
lib/noah/models/tags.rb
+26
-4
taggable.rb
lib/noah/taggable.rb
+6
-2
No files found.
lib/noah/linkable.rb
View file @
3110020f
...
...
@@ -7,7 +7,7 @@ module Noah::Linkable
def
link!
(
link_name
)
link
=
Noah
::
Link
.
find_or_create
(
:path
=>
link_name
)
link
.
nodes
=
self
self
.
links
<<
link
links
<<
link
end
def
unlink!
(
link_name
)
...
...
lib/noah/models/link.rb
View file @
3110020f
...
...
@@ -19,9 +19,11 @@ module Noah
when
"Array"
node
.
each
do
|
n
|
self
.
key
[
:nodes
].
sadd
(
n
.
key
)
n
.
links
<<
self
end
else
self
.
key
[
:nodes
].
sadd
(
node
.
key
)
n
.
links
<<
self
end
end
...
...
lib/noah/models/tags.rb
View file @
3110020f
module
Noah
class
Tag
<
Model
attribute
:name
attribute
:members
index
:name
def
validate
...
...
@@ -9,10 +10,25 @@ module Noah
assert_unique
:name
end
def
tagged
(
tag
)
# TODO:
#logic to find all models with a given tag
#will need hooks added to taggable module
def
members
=
(
member
)
self
.
key
[
:members
].
sadd
(
member
.
key
)
end
def
members
hsh
=
Hash
.
new
self
.
key
[
:members
].
smembers
.
each
do
|
member
|
n
=
node_to_class
(
member
)
cls
=
class_to_lower
(
n
.
class
.
to_s
)
hash_key
=
"
#{
cls
}
s"
.
to_sym
hsh
[
hash_key
]
=
Array
.
new
unless
hsh
.
has_key?
(
hash_key
)
hsh
[
hash_key
]
<<
n
.
name
end
hsh
end
def
self
.
tagged
(
tag
)
t
=
find
(
:name
=>
tag
).
first
t
.
members
end
class
<<
self
...
...
@@ -28,6 +44,12 @@ module Noah
end
end
end
private
def
node_to_class
(
node
)
node
.
match
(
/^Noah::(.*):(\d+)$/
)
Noah
.
const_get
(
$1
).
send
(
:[]
,
$2
)
end
end
end
lib/noah/taggable.rb
View file @
3110020f
...
...
@@ -8,10 +8,14 @@ module Noah::Taggable
case
tag_name
.
class
.
to_s
when
"Array"
tag_name
.
each
do
|
t
|
tags
<<
::
Noah
::
Tag
.
find_or_create
(
:name
=>
t
)
my_tag
=
::
Noah
::
Tag
.
find_or_create
(
:name
=>
t
)
tags
<<
my_tag
my_tag
.
members
=
self
end
else
tags
<<
Noah
::
Tag
.
find_or_create
(
:name
=>
tag_name
)
my_tag
=
::
Noah
::
Tag
.
find_or_create
(
:name
=>
tag_name
)
tags
<<
my_tag
my_tag
.
members
=
self
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