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
...
@@ -91,6 +91,7 @@ module Noah
end
end
return
link
return
link
end
end
def
add_config_to_app
(
appname
,
config_hash
)
def
add_config_to_app
(
appname
,
config_hash
)
begin
begin
config
=
Noah
::
Configuration
.
find_or_create
(
config_hash
)
config
=
Noah
::
Configuration
.
find_or_create
(
config_hash
)
...
...
lib/noah/models/tags.rb
View file @
349e759b
...
@@ -8,8 +8,8 @@ module Noah
...
@@ -8,8 +8,8 @@ module Noah
def
delete
def
delete
self
.
members
.
each_value
do
|
member_array
|
self
.
members
.
each_value
do
|
member_array
|
member_array
.
each
do
|
mem
ber
|
member_array
.
each
do
|
mem
|
member
.
tags
.
key
.
srem
"
#{
self
.
id
}
"
delete_member
(
mem
)
end
end
end
end
super
super
...
@@ -40,11 +40,18 @@ module Noah
...
@@ -40,11 +40,18 @@ module Noah
def
delete_member
(
node
)
def
delete_member
(
node
)
nc
=
class_to_lower
(
node
.
class
.
to_s
)
+
"s"
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
}
"
)
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
end
self
.
save
end
end
def
to_hash
def
to_hash
...
...
lib/noah/taggable.rb
View file @
349e759b
...
@@ -24,18 +24,10 @@ module Noah::Taggable
...
@@ -24,18 +24,10 @@ module Noah::Taggable
case
tag_name
.
class
.
to_s
case
tag_name
.
class
.
to_s
when
"Array"
when
"Array"
tag_name
.
each
do
|
t
|
tag_name
.
each
do
|
t
|
my_tag
=
::
Noah
::
Tag
.
find
(
:name
=>
t
).
first
remove_tag
(
t
)
if
self
.
tags
.
member?
(
my_tag
)
self
.
tags
.
key
.
srem
"
#{
my_tag
.
id
}
"
my_tag
.
delete_member
(
self
)
end
end
end
else
else
my_tag
=
::
Noah
::
Tag
.
find
(
:name
=>
tag_name
).
first
remove_tag
(
tag_name
)
if
self
.
tags
.
member?
(
my_tag
)
self
.
tags
.
key
.
srem
"
#{
my_tag
.
id
}
"
my_tag
.
delete_member
(
self
)
end
end
end
self
.
save
self
.
save
end
end
...
@@ -45,4 +37,13 @@ module Noah::Taggable
...
@@ -45,4 +37,13 @@ module Noah::Taggable
self
.
tags
.
sort
.
each
{
|
t
|
tag_arr
<<
t
.
name
}
if
self
.
tags
.
size
!=
0
self
.
tags
.
sort
.
each
{
|
t
|
tag_arr
<<
t
.
name
}
if
self
.
tags
.
size
!=
0
super
.
merge
(
:tags
=>
tag_arr
)
super
.
merge
(
:tags
=>
tag_arr
)
end
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
end
spec/tag_spec.rb
View file @
349e759b
...
@@ -60,6 +60,31 @@ describe "Using the Tag Model", :reset_redis => true do
...
@@ -60,6 +60,31 @@ describe "Using the Tag Model", :reset_redis => true do
end
end
end
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
end
describe
"should not"
do
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