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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e36fd7d8b9c7762d6ff2258923456cb738082b89
4
- data.tar.gz: 261ad2b9b3b1ab7512dbf1c9685bb6204e2c9990
3
+ metadata.gz: 3dc2d766cf63542bf5d55cd2348de6c0ca5eab84
4
+ data.tar.gz: ffdc3f953816b73d169d5abe158d363dd1175988
5
5
  SHA512:
6
- metadata.gz: ff1093765357f7f5b8ef90443810ff81c784aaa6b62de45a90e452c3101e6d6ce6fb32174ba82d2188d57855c3f91e4cab90fd343736f691418dac148a638b67
7
- data.tar.gz: a25143352ee41f9cc595cad8e0ac2ee3ff5be5a76f0bcf067a7f6919e5d4d35a1d2b207899d1a498f032d45dc36f6a16c010792a5974d3ceea065a4dc9774c2f
6
+ metadata.gz: 88791f6a55fbf0f94055bd5275ba3e889c322282dea7db180220c8a67c38c6092c7d0cd35ded0791a8b45e1832f38a5e70d11a01bcfa94d1af4fb8e98617d4f5
7
+ data.tar.gz: faab880a177400c50cc428cf4fd9c7590d4e158dbb29cd2e137699297671f92daa9dde90e3ebc5c80bda3602a65fc3366d61d05ddde45724b6b12b3c989146b4
@@ -3,3 +3,4 @@ end
3
3
 
4
4
  require 'tag_bat/active_record'
5
5
  require 'tag_bat/engine'
6
+ require 'tag_bat/tag_names'
@@ -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
+
Binary file
Binary file
@@ -1,11 +1,11 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'tag_bat'
3
- s.version = '0.0.3'
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 (not stable at all!)'
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.3
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 (not stable at all!)
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: []