tagalong 0.0.6 → 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +22 -11
- data/lib/tagalong/tagger.rb +4 -0
- data/lib/tagalong/version.rb +1 -1
- data/spec/lib/tagalong/tagger_spec.rb +14 -0
- metadata +9 -9
data/README.md
CHANGED
@@ -69,24 +69,20 @@ It is necessary to declare at least one Tagger and Taggable in addition to gener
|
|
69
69
|
|
70
70
|
Once Taggers and Taggables are declared, they can be used in numerous ways as outlined below.
|
71
71
|
|
72
|
-
###
|
72
|
+
### Tag Usage
|
73
73
|
|
74
|
-
|
74
|
+
##### Tagging
|
75
75
|
|
76
|
-
|
76
|
+
To tag a taggable, call the `tag` method on a Tagger object and hand it a persisted Taggable object with the given label that you want to apply.
|
77
77
|
|
78
|
-
|
78
|
+
@user.tag(@contact, "sometag")
|
79
|
+
|
80
|
+
##### Untagging
|
79
81
|
|
80
82
|
To untag, call the `untag` method on a Tagger object and hand it a persisted Taggable object with the given label that you want to untag.
|
81
83
|
|
82
84
|
@user.untag(@contact, "sometag")
|
83
|
-
|
84
|
-
### Deleting
|
85
|
-
|
86
|
-
To delete a tag, call the `delete_tag` method on a Tagger object and hand it the label of the tag you want to delete. This will remove the tag from the Tagger, as well as all Taggables that might be using it.
|
87
|
-
|
88
|
-
@user.delete_tag("sometag")
|
89
|
-
|
85
|
+
|
90
86
|
### List Tagger tags
|
91
87
|
|
92
88
|
To list Tagger tags, call the `tags` method on a Tagger object. This will return an array of all tags that Tagger has ever used in ascending alphabetical order.
|
@@ -141,6 +137,21 @@ To check if a Taggable is tagged with a tag, call the `tagged_with?` method on a
|
|
141
137
|
@contact.tagged_with?('some_tag')
|
142
138
|
# => true
|
143
139
|
|
140
|
+
### Tag Management
|
141
|
+
|
142
|
+
##### Creating
|
143
|
+
|
144
|
+
To create a tag on the Tagger object without applying the tag to a Taggable, call the `create_tag` method.
|
145
|
+
|
146
|
+
@user.create_tag("sometag")
|
147
|
+
|
148
|
+
|
149
|
+
##### Deleting
|
150
|
+
|
151
|
+
To delete a tag, call the `delete_tag` method on a Tagger object and hand it the label of the tag you want to delete. This will remove the tag from the Tagger, as well as all Taggables that might be using it.
|
152
|
+
|
153
|
+
@user.delete_tag("sometag")
|
154
|
+
|
144
155
|
## Credits
|
145
156
|
|
146
157
|
I just wanted to thank all of the other open source Rails tagging plugins out there. Especially, [acts-as-taggable-on](http://github.com/mbleigh/acts-as-taggable-on), [is_taggable](http://github.com/jamesgolick/is_taggable), and [rocket_tag](http://github.com/bradphelan/rocket_tag). I learned a lot from you all.
|
data/lib/tagalong/tagger.rb
CHANGED
@@ -20,6 +20,10 @@ module Tagalong
|
|
20
20
|
tag_manager.add_tag(tag_name)
|
21
21
|
end
|
22
22
|
|
23
|
+
def create_tag(tag_name)
|
24
|
+
TagalongTag.create!(:tagger_id => self.id, :tagger_type => self.class.to_s, :name => tag_name)
|
25
|
+
end
|
26
|
+
|
23
27
|
def untag(taggable_obj, tag_name)
|
24
28
|
raise Tagalong::TaggableNotPersisted, "Taggable must be persisted to untag it." if !taggable_obj.persisted?
|
25
29
|
tag_manager = Tagalong::TagManager.new(taggable_obj, self)
|
data/lib/tagalong/version.rb
CHANGED
@@ -17,6 +17,13 @@ describe "Tagger" do
|
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
20
|
+
describe "#create_tag" do
|
21
|
+
it "creates a new unassigned tag on the tagger" do
|
22
|
+
@user.create_tag('tag4')
|
23
|
+
@user.tags.should include('tag4')
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
20
27
|
describe "#untag" do
|
21
28
|
it "untags the tag from the given taggable object for the tagger" do
|
22
29
|
@contact.tagalong_tags.create!(:name => "bar", :tagger_id => @user.id, :tagger_type => @user.class.to_s)
|
@@ -135,6 +142,13 @@ describe "Tagger" do
|
|
135
142
|
end
|
136
143
|
end
|
137
144
|
|
145
|
+
describe "#create_tag" do
|
146
|
+
it "creates a new tagalong tag for the tagger" do
|
147
|
+
Tagalong::TagalongTag.should_receive(:create!).with(hash_including({:tagger_id => @user.id, :tagger_type => @user.class.to_s, :name => 'tag4'}))
|
148
|
+
@user.create_tag('tag4')
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
138
152
|
describe "#untag" do
|
139
153
|
it "creates an instance of the tag manager" do
|
140
154
|
tag_manager = stub('tag_manager', :remove_tag => nil)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tagalong
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.7
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -13,7 +13,7 @@ date: 2012-05-18 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activerecord
|
16
|
-
requirement: &
|
16
|
+
requirement: &70243968132040 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70243968132040
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: sqlite3
|
27
|
-
requirement: &
|
27
|
+
requirement: &70243968131560 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70243968131560
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: rspec
|
38
|
-
requirement: &
|
38
|
+
requirement: &70243968131120 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70243968131120
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: rake
|
49
|
-
requirement: &
|
49
|
+
requirement: &70243968130700 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
@@ -54,7 +54,7 @@ dependencies:
|
|
54
54
|
version: '0'
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *70243968130700
|
58
58
|
description: A Rails tagging plugin that makes sense.
|
59
59
|
email:
|
60
60
|
- cyphactor@gmail.com
|