tag_ramaprasad 1.0.1 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/db/migrate/1_tag_tables.rb +1 -1
- data/lib/tag_ramaprasad.rb +1 -2
- data/lib/tag_ramaprasad/active_record.rb +12 -2
- data/lib/tag_ramaprasad/tag_names.rb +51 -0
- data/spec/acceptance/tag_names_spec.rb +64 -0
- data/tag_ramaprasad-1.0.1.gem +0 -0
- data/tag_ramaprasad.gemspec +5 -5
- metadata +20 -17
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a67d0beb0f53f3476122947cc96b9fb088ac02ad176e4413bfecbb83d9fe89ac
|
4
|
+
data.tar.gz: 4ff20bdfd94f76c06c4e0b9ff719fe0670185eb2362384945e8340c2a97c6aa0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 69d11c7108e2059eb6801280df66fef4209a8c52cefb64703adfa5067560ad76bd3692746d5708d34f7b0f8bf52a0ee1f9d5e2a1081e9c121986315dbefc054e
|
7
|
+
data.tar.gz: 3f06484d566f8411907af09053c5e816f2dc412009c6bd869dd791d18a7f7369f42aff637d324685ac3127461ce75892af1eaee3e3b9df4e9730eb5f1a59512f
|
data/db/migrate/1_tag_tables.rb
CHANGED
data/lib/tag_ramaprasad.rb
CHANGED
@@ -1,11 +1,9 @@
|
|
1
1
|
module TagRamaprasad::ActiveRecord
|
2
2
|
def self.included(base)
|
3
|
-
# include our class methods
|
4
3
|
base.extend TagRamaprasad::ActiveRecord::ClassMethods
|
5
4
|
end
|
6
5
|
|
7
6
|
module ClassMethods
|
8
|
-
# Set up the underlying tag associations in the model
|
9
7
|
def has_many_tags
|
10
8
|
has_many :taggings, :class_name => 'TagRamaprasad::Tagging',
|
11
9
|
:as => :taggable, :dependent => :destroy
|
@@ -13,4 +11,16 @@ module TagRamaprasad::ActiveRecord
|
|
13
11
|
:through => :taggings
|
14
12
|
end
|
15
13
|
end
|
14
|
+
|
15
|
+
def tag_names
|
16
|
+
@tag_names ||= TagRamaprasad::TagNames.new self
|
17
|
+
end
|
18
|
+
|
19
|
+
def tag_names=(names)
|
20
|
+
if names.is_a?(TagRamaprasad::TagNames)
|
21
|
+
@tag_names = names
|
22
|
+
else
|
23
|
+
@tag_names = TagRamaprasad::TagNames.new_with_names self, names
|
24
|
+
end
|
25
|
+
end
|
16
26
|
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
class TagRamaprasad::TagNames
|
2
|
+
include Enumerable
|
3
|
+
|
4
|
+
def self.new_with_names(taggable, names)
|
5
|
+
tag_names = new(taggable)
|
6
|
+
tag_names.clear
|
7
|
+
names.each { |name| tag_names << name }
|
8
|
+
tag_names
|
9
|
+
end
|
10
|
+
|
11
|
+
def initialize(taggable)
|
12
|
+
@taggable = taggable
|
13
|
+
end
|
14
|
+
|
15
|
+
def to_a
|
16
|
+
taggable.tags.collect &:name
|
17
|
+
end
|
18
|
+
|
19
|
+
def +(array)
|
20
|
+
array.each { |name| self.<< name }
|
21
|
+
self
|
22
|
+
end
|
23
|
+
|
24
|
+
def -(array)
|
25
|
+
array.each { |name| self.delete name }
|
26
|
+
self
|
27
|
+
end
|
28
|
+
|
29
|
+
def <<(name)
|
30
|
+
tag = TagRamaprasad::Tag.where(:name => name).first ||
|
31
|
+
TagRamaprasad::Tag.create(:name => name)
|
32
|
+
|
33
|
+
taggable.tags << tag
|
34
|
+
end
|
35
|
+
|
36
|
+
def clear
|
37
|
+
taggable.tags.clear
|
38
|
+
end
|
39
|
+
|
40
|
+
def delete(name)
|
41
|
+
taggable.tags.delete TagRamaprasad::Tag.where(:name => name).first
|
42
|
+
end
|
43
|
+
|
44
|
+
def each(&block)
|
45
|
+
to_a.each &block
|
46
|
+
end
|
47
|
+
|
48
|
+
private
|
49
|
+
|
50
|
+
attr_reader :taggable
|
51
|
+
end
|
@@ -0,0 +1,64 @@
|
|
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 << TagRamaprasad::Tag.create(:name => 'melbourne')
|
8
|
+
|
9
|
+
article.tag_names.to_a.should == ['melbourne']
|
10
|
+
end
|
11
|
+
|
12
|
+
it "adds tags via their names" do
|
13
|
+
article.tag_names << 'melbourne'
|
14
|
+
|
15
|
+
article.tags.collect(&:name).should == ['melbourne']
|
16
|
+
end
|
17
|
+
|
18
|
+
it "accepts a completely new set of tags" do
|
19
|
+
article.tag_names = ['portland', 'oregon']
|
20
|
+
|
21
|
+
article.tags.collect(&:name).should == ['portland', 'oregon']
|
22
|
+
end
|
23
|
+
|
24
|
+
it "enumerates through tag names" do
|
25
|
+
article.tag_names = ['melbourne', 'victoria']
|
26
|
+
names = []
|
27
|
+
|
28
|
+
article.tag_names.each do |name|
|
29
|
+
names << name
|
30
|
+
end
|
31
|
+
|
32
|
+
names.should == ['melbourne', 'victoria']
|
33
|
+
end
|
34
|
+
|
35
|
+
it "does not allow duplication of tags" do
|
36
|
+
existing = Article.create
|
37
|
+
existing.tags << TagRamaprasad::Tag.create(:name => 'portland')
|
38
|
+
|
39
|
+
article.tag_names = ['portland']
|
40
|
+
|
41
|
+
existing.tag_ids.should == article.tag_ids
|
42
|
+
end
|
43
|
+
|
44
|
+
it "appends tag names" do
|
45
|
+
article.tag_names = ['portland']
|
46
|
+
article.tag_names += ['oregon', 'ruby']
|
47
|
+
|
48
|
+
article.tags.collect(&:name).should == ['portland', 'oregon', 'ruby']
|
49
|
+
end
|
50
|
+
|
51
|
+
it "removes a single tag name" do
|
52
|
+
article.tag_names = ['portland', 'oregon']
|
53
|
+
article.tag_names.delete 'oregon'
|
54
|
+
|
55
|
+
article.tags.collect(&:name).should == ['portland']
|
56
|
+
end
|
57
|
+
|
58
|
+
it "removes tag names" do
|
59
|
+
article.tag_names = ['portland', 'oregon', 'ruby']
|
60
|
+
article.tag_names -= ['oregon', 'ruby']
|
61
|
+
|
62
|
+
article.tags.collect(&:name).should == ['portland']
|
63
|
+
end
|
64
|
+
end
|
Binary file
|
data/tag_ramaprasad.gemspec
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
2
|
Gem::Specification.new do |s|
|
3
3
|
s.name = 'tag_ramaprasad'
|
4
|
-
s.version = '1.0.
|
4
|
+
s.version = '1.0.2'
|
5
5
|
s.authors = ['Rama Prasad']
|
6
6
|
s.email = ['link2prasad@gmail.com']
|
7
7
|
s.homepage = 'https://github.com/link2prasad/tag_ramaprasad'
|
@@ -11,8 +11,8 @@ Gem::Specification.new do |s|
|
|
11
11
|
s.files = `git ls-files`.split("\n")
|
12
12
|
s.test_files = `git ls-files -- {spec}/*`.split("\n")
|
13
13
|
s.require_paths = ['lib']
|
14
|
-
s.add_runtime_dependency 'activerecord'
|
15
|
-
s.add_development_dependency 'combustion'
|
16
|
-
s.add_development_dependency 'rspec-rails'
|
17
|
-
s.add_development_dependency 'sqlite3'
|
14
|
+
s.add_runtime_dependency 'activerecord', '~> 6.1.3'
|
15
|
+
s.add_development_dependency 'combustion', '~> 1.3.1'
|
16
|
+
s.add_development_dependency 'rspec-rails', '~> 4.0.2'
|
17
|
+
s.add_development_dependency 'sqlite3', '~> 1.4.2'
|
18
18
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tag_ramaprasad
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rama Prasad
|
@@ -14,58 +14,58 @@ dependencies:
|
|
14
14
|
name: activerecord
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 6.1.3
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: 6.1.3
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: combustion
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
33
|
+
version: 1.3.1
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - "
|
38
|
+
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
40
|
+
version: 1.3.1
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rspec-rails
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - "
|
45
|
+
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version:
|
47
|
+
version: 4.0.2
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- - "
|
52
|
+
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version:
|
54
|
+
version: 4.0.2
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: sqlite3
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- - "
|
59
|
+
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version:
|
61
|
+
version: 1.4.2
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- - "
|
66
|
+
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version:
|
68
|
+
version: 1.4.2
|
69
69
|
description: This friendly ramaprasad gives you tags in your Rails app.
|
70
70
|
email:
|
71
71
|
- link2prasad@gmail.com
|
@@ -81,6 +81,8 @@ files:
|
|
81
81
|
- lib/tag_ramaprasad.rb
|
82
82
|
- lib/tag_ramaprasad/active_record.rb
|
83
83
|
- lib/tag_ramaprasad/engine.rb
|
84
|
+
- lib/tag_ramaprasad/tag_names.rb
|
85
|
+
- spec/acceptance/tag_names_spec.rb
|
84
86
|
- spec/acceptance/tags_spec.rb
|
85
87
|
- spec/internal/app/models/article.rb
|
86
88
|
- spec/internal/config/database.yml
|
@@ -88,6 +90,7 @@ files:
|
|
88
90
|
- spec/internal/log/.gitignore
|
89
91
|
- spec/spec_helper.rb
|
90
92
|
- tag_ramaprasad-0.0.1.gem
|
93
|
+
- tag_ramaprasad-1.0.1.gem
|
91
94
|
- tag_ramaprasad.gemspec
|
92
95
|
homepage: https://github.com/link2prasad/tag_ramaprasad
|
93
96
|
licenses: []
|