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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5526b09bfd902ca3080ccb043d6e769e3f18f4cb2efedbee4f6b8a5fc49337d0
4
- data.tar.gz: bc46e7986a8b1a50d7852e65139de1b940ee444337fce6d353b3bd6300e58b2f
3
+ metadata.gz: a67d0beb0f53f3476122947cc96b9fb088ac02ad176e4413bfecbb83d9fe89ac
4
+ data.tar.gz: 4ff20bdfd94f76c06c4e0b9ff719fe0670185eb2362384945e8340c2a97c6aa0
5
5
  SHA512:
6
- metadata.gz: ca02e845305fa593f140479b7369950ed65d2f0597e5b9f29f461536810a6d628ab6816c0ad111e292d660d24710949ca958d4202d212eecf30f15b39b8917d6
7
- data.tar.gz: 948cb4e3991f2cf0b8290fbe54dc2aa7b88defa84cafc15e96a61fb72e5d1c22999df22ac426bc4165da2494ebe6052f80f3656ebce7a12264b6c7f5a5c40c3e
6
+ metadata.gz: 69d11c7108e2059eb6801280df66fef4209a8c52cefb64703adfa5067560ad76bd3692746d5708d34f7b0f8bf52a0ee1f9d5e2a1081e9c121986315dbefc054e
7
+ data.tar.gz: 3f06484d566f8411907af09053c5e816f2dc412009c6bd869dd791d18a7f7369f42aff637d324685ac3127461ce75892af1eaee3e3b9df4e9730eb5f1a59512f
@@ -1,4 +1,4 @@
1
- class TagTables < ActiveRecord::Migration
1
+ class TagTables < ActiveRecord::Migration[4.2]
2
2
  def up
3
3
  create_table :taggings do |t|
4
4
  t.integer :tag_id, :null => false
@@ -1,8 +1,7 @@
1
- # Declare our top level module
2
1
  module TagRamaprasad
3
2
  #
4
3
  end
5
4
 
6
- # Require the rest of the gem's files
7
5
  require 'tag_ramaprasad/active_record'
8
6
  require 'tag_ramaprasad/engine'
7
+ require 'tag_ramaprasad/tag_names'
@@ -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
@@ -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.1'
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.1
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: '0'
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: '0'
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: '0'
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: '0'
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: '0'
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: '0'
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: '0'
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: '0'
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: []