tag_bat 0.0.3 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/tag_bat.rb +1 -0
- data/lib/tag_bat/active_record.rb +12 -0
- data/lib/tag_bat/tag_names.rb +47 -0
- data/spec/acceptance/tag_names_spec.rb +59 -0
- data/tag_bat-0.0.3.gem +0 -0
- data/tag_bat-0.1.0.gem +0 -0
- data/tag_bat.gemspec +2 -2
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3dc2d766cf63542bf5d55cd2348de6c0ca5eab84
|
4
|
+
data.tar.gz: ffdc3f953816b73d169d5abe158d363dd1175988
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 88791f6a55fbf0f94055bd5275ba3e889c322282dea7db180220c8a67c38c6092c7d0cd35ded0791a8b45e1832f38a5e70d11a01bcfa94d1af4fb8e98617d4f5
|
7
|
+
data.tar.gz: faab880a177400c50cc428cf4fd9c7590d4e158dbb29cd2e137699297671f92daa9dde90e3ebc5c80bda3602a65fc3366d61d05ddde45724b6b12b3c989146b4
|
data/lib/tag_bat.rb
CHANGED
@@ -3,6 +3,18 @@ module TagBat::ActiveRecord
|
|
3
3
|
base.extend TagBat::ActiveRecord::ClassMethods
|
4
4
|
end
|
5
5
|
|
6
|
+
def tag_names
|
7
|
+
@tag_names ||= TagBat::TagNames.new self
|
8
|
+
end
|
9
|
+
|
10
|
+
def tag_names=(names)
|
11
|
+
if names.is_a?(TagBat::TagNames)
|
12
|
+
@tag_names = names
|
13
|
+
else
|
14
|
+
@tag_names = TagBat::TagNames.new_with_names self, names
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
6
18
|
module ClassMethods
|
7
19
|
def has_many_tags
|
8
20
|
has_many :taggings, :class_name => 'TagBat::Tagging',
|
@@ -0,0 +1,47 @@
|
|
1
|
+
class TagBat::TagNames
|
2
|
+
include Enumerable
|
3
|
+
|
4
|
+
attr_reader :taggable
|
5
|
+
|
6
|
+
def self.new_with_names(taggable, names)
|
7
|
+
tag_names = new(taggable)
|
8
|
+
tag_names.clear
|
9
|
+
names.each { |name| tag_names << name }
|
10
|
+
tag_names
|
11
|
+
end
|
12
|
+
|
13
|
+
def clear
|
14
|
+
taggable.tags.clear
|
15
|
+
end
|
16
|
+
|
17
|
+
def initialize(taggable)
|
18
|
+
@taggable = taggable
|
19
|
+
end
|
20
|
+
|
21
|
+
def to_a
|
22
|
+
taggable.tags.collect &:name
|
23
|
+
end
|
24
|
+
|
25
|
+
def <<(name)
|
26
|
+
tag = TagBat::Tag.where(name: name).first || TagBat::Tag.create(name: name)
|
27
|
+
taggable.tags << tag
|
28
|
+
end
|
29
|
+
|
30
|
+
def delete(name)
|
31
|
+
taggable.tags.delete TagBat::Tag.where(name: name).first
|
32
|
+
end
|
33
|
+
|
34
|
+
def +(array)
|
35
|
+
array.each { |name| self.<< name }
|
36
|
+
self
|
37
|
+
end
|
38
|
+
|
39
|
+
def -(array)
|
40
|
+
array.each { |name| self.delete name }
|
41
|
+
self
|
42
|
+
end
|
43
|
+
|
44
|
+
def each(&block)
|
45
|
+
to_a.each &block
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "Managing tags via names" do
|
4
|
+
let(:article) { Article.create }
|
5
|
+
|
6
|
+
it "returns tag names" do
|
7
|
+
article.tags << TagBat::Tag.create(name: 'melbourne')
|
8
|
+
article.tag_names.to_a.should == ['melbourne']
|
9
|
+
end
|
10
|
+
|
11
|
+
it "adds tags via their names" do
|
12
|
+
article.tag_names << 'melbourne'
|
13
|
+
article.tags.collect(&:name).should == [ 'melbourne']
|
14
|
+
end
|
15
|
+
|
16
|
+
it "accepts a completely new set of tags" do
|
17
|
+
article.tag_names = ['portland', 'oregon']
|
18
|
+
article.tags.collect(&:name).should == ['portland', 'oregon']
|
19
|
+
end
|
20
|
+
|
21
|
+
it "enumerates through tag names" do
|
22
|
+
article.tag_names = ['melbourne', 'victoria']
|
23
|
+
names = []
|
24
|
+
|
25
|
+
article.tag_names.each do |name|
|
26
|
+
names << name
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
it "does not allow duplications of tags" do
|
31
|
+
existing = Article.create
|
32
|
+
existing.tags << TagBat::Tag.create(:name => "portland")
|
33
|
+
|
34
|
+
article.tag_names = ['portland']
|
35
|
+
existing.tag_ids.should == article.tag_ids
|
36
|
+
end
|
37
|
+
|
38
|
+
it "appends tag names" do
|
39
|
+
article.tag_names = ['portland']
|
40
|
+
article.tag_names += ['oregon', 'ruby']
|
41
|
+
|
42
|
+
article.tags.collect(&:name).should == ['portland', 'oregon', 'ruby']
|
43
|
+
end
|
44
|
+
|
45
|
+
it "removes a single tag name" do
|
46
|
+
article.tag_names = ['portland', 'oregon']
|
47
|
+
article.tag_names.delete 'oregon'
|
48
|
+
|
49
|
+
article.tags.collect(&:name).should == ['portland']
|
50
|
+
end
|
51
|
+
|
52
|
+
it "removes tag names" do
|
53
|
+
article.tag_names = ['portland', 'oregon', 'ruby']
|
54
|
+
article.tag_names -= ['oregon', 'ruby']
|
55
|
+
|
56
|
+
article.tags.collect(&:name).should == ['portland']
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
data/tag_bat-0.0.3.gem
ADDED
Binary file
|
data/tag_bat-0.1.0.gem
ADDED
Binary file
|
data/tag_bat.gemspec
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = 'tag_bat'
|
3
|
-
s.version = '0.0
|
3
|
+
s.version = '0.1.0'
|
4
4
|
s.authors = ['Nasser Al Zahrani']
|
5
5
|
s.email = ['nassersala@gmail.com']
|
6
6
|
s.homepage = 'https://github.com/nassersala/tag_bat'
|
7
7
|
s.summary = 'The Tag Bat'
|
8
|
-
s.description = 'yet another tagging library for Rails
|
8
|
+
s.description = 'yet another tagging library for Rails'
|
9
9
|
s.files = `git ls-files`.split("\n")
|
10
10
|
s.test_files = `git ls-files -- {spec}/*`.split("\n")
|
11
11
|
s.require_paths = ['lib']
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tag_bat
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nasser Al Zahrani
|
@@ -66,7 +66,7 @@ dependencies:
|
|
66
66
|
- - ~>
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: 1.3.7
|
69
|
-
description: yet another tagging library for Rails
|
69
|
+
description: yet another tagging library for Rails
|
70
70
|
email:
|
71
71
|
- nassersala@gmail.com
|
72
72
|
executables: []
|
@@ -82,6 +82,8 @@ files:
|
|
82
82
|
- lib/tag_bat.rb
|
83
83
|
- lib/tag_bat/active_record.rb
|
84
84
|
- lib/tag_bat/engine.rb
|
85
|
+
- lib/tag_bat/tag_names.rb
|
86
|
+
- spec/acceptance/tag_names_spec.rb
|
85
87
|
- spec/acceptance/tags_spec.rb
|
86
88
|
- spec/internal/app/models/article.rb
|
87
89
|
- spec/internal/config/database.yml
|
@@ -89,6 +91,8 @@ files:
|
|
89
91
|
- spec/internal/log/.gitignore
|
90
92
|
- spec/spec_helper.rb
|
91
93
|
- tag_bat-0.0.1.gem
|
94
|
+
- tag_bat-0.0.3.gem
|
95
|
+
- tag_bat-0.1.0.gem
|
92
96
|
- tag_bat.gemspec
|
93
97
|
homepage: https://github.com/nassersala/tag_bat
|
94
98
|
licenses: []
|