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
349e759b
Commit
349e759b
authored
May 25, 2011
by
John E. Vincent
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
untag fully working via Ruby API
parent
b3fc82de
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
49 additions
and
15 deletions
+49
-15
helpers.rb
lib/noah/helpers.rb
+1
-0
tags.rb
lib/noah/models/tags.rb
+12
-5
taggable.rb
lib/noah/taggable.rb
+11
-10
tag_spec.rb
spec/tag_spec.rb
+25
-0
No files found.
lib/noah/helpers.rb
View file @
349e759b
...
...
@@ -91,6 +91,7 @@ module Noah
end
return
link
end
def
add_config_to_app
(
appname
,
config_hash
)
begin
config
=
Noah
::
Configuration
.
find_or_create
(
config_hash
)
...
...
lib/noah/models/tags.rb
View file @
349e759b
...
...
@@ -8,8 +8,8 @@ module Noah
def
delete
self
.
members
.
each_value
do
|
member_array
|
member_array
.
each
do
|
mem
ber
|
member
.
tags
.
key
.
srem
"
#{
self
.
id
}
"
member_array
.
each
do
|
mem
|
delete_member
(
mem
)
end
end
super
...
...
@@ -40,11 +40,18 @@ module Noah
def
delete_member
(
node
)
nc
=
class_to_lower
(
node
.
class
.
to_s
)
+
"s"
if
self
.
members
[
nc
.
to_sym
].
member?
(
node
)
# Need to refactor. Essentially there are conditions we need to check for before trying to delete a member
# Are there any members at all?
# Are there any members of a given class?
# Not pretty but it works for now
if
self
.
members
.
size
==
0
||
self
.
members
.
has_key?
(
nc
.
to_sym
)
==
false
# no match so save and be done with it
self
.
save
elsif
self
.
members
[
nc
.
to_sym
].
include?
(
node
)
Ohm
.
redis
.
srem
(
"
#{
self
.
key
}
:members"
,
"
#{
node
.
key
}
"
)
node
.
untag!
(
self
.
name
)
unless
node
.
tags
.
member?
(
self
)
==
false
node
.
untag!
(
self
.
name
)
if
node
.
tags
.
include?
(
self
)
self
.
save
end
self
.
save
end
def
to_hash
...
...
lib/noah/taggable.rb
View file @
349e759b
...
...
@@ -24,18 +24,10 @@ module Noah::Taggable
case
tag_name
.
class
.
to_s
when
"Array"
tag_name
.
each
do
|
t
|
my_tag
=
::
Noah
::
Tag
.
find
(
:name
=>
t
).
first
if
self
.
tags
.
member?
(
my_tag
)
self
.
tags
.
key
.
srem
"
#{
my_tag
.
id
}
"
my_tag
.
delete_member
(
self
)
end
remove_tag
(
t
)
end
else
my_tag
=
::
Noah
::
Tag
.
find
(
:name
=>
tag_name
).
first
if
self
.
tags
.
member?
(
my_tag
)
self
.
tags
.
key
.
srem
"
#{
my_tag
.
id
}
"
my_tag
.
delete_member
(
self
)
end
remove_tag
(
tag_name
)
end
self
.
save
end
...
...
@@ -45,4 +37,13 @@ module Noah::Taggable
self
.
tags
.
sort
.
each
{
|
t
|
tag_arr
<<
t
.
name
}
if
self
.
tags
.
size
!=
0
super
.
merge
(
:tags
=>
tag_arr
)
end
protected
def
remove_tag
(
tag_name
)
my_tag
=
::
Noah
::
Tag
.
find
(
:name
=>
tag_name
).
first
if
self
.
tags
.
member?
(
my_tag
)
self
.
tags
.
key
.
srem
"
#{
my_tag
.
id
}
"
my_tag
.
delete_member
(
self
)
end
end
end
spec/tag_spec.rb
View file @
349e759b
...
...
@@ -60,6 +60,31 @@ describe "Using the Tag Model", :reset_redis => true do
end
end
end
it
"should untag! a single tag from an object"
do
@application
.
tag!
"foobarspec"
t
=
Noah
::
Tag
.
find
(
:name
=>
'foobarspec'
).
first
t
.
nil?
.
should
==
false
@application
.
tags
.
size
.
should
==
1
@application
.
tags
.
include?
(
t
).
should
==
true
t
.
members
.
size
.
should
==
1
t
.
members
[
:applications
].
include?
(
@application
).
should
==
true
@application
.
untag!
"foobarspec"
@application
.
tags
.
size
.
should
==
0
t
.
members
.
size
.
should
==
0
end
it
"should untag! an array of tags from an object"
do
tagz
=
%w{foo bar baz bang}
@application
.
tag!
tagz
@application
.
tags
.
size
.
should
==
tagz
.
size
@application
.
untag!
tagz
@application
.
tags
.
size
.
should
==
0
tagz
.
each
do
|
tag
|
t
=
Noah
::
Tag
.
find
(
:name
=>
tag
).
first
t
.
nil?
.
should
==
false
Noah
::
Tag
.
all
.
size
.
should
==
tagz
.
size
t
.
members
.
has_key?
(
:applications
).
should
==
false
end
end
end
describe
"should not"
do
...
...
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