polytag 0.0.1 → 0.0.2
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/README.md +2 -0
- data/circle.yml +3 -0
- data/lib/polytag.rb +25 -7
- data/lib/polytag/tag_group.rb +4 -0
- data/lib/polytag/version.rb +1 -1
- data/spec/specs/polytag_querying_spec.rb +5 -2
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a6d4b2e842f885c1ac09bcf1cc4660712164f336
|
4
|
+
data.tar.gz: 52c8c36367c902a736735c68de3fb224cb94a4f4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 55e8dac4832358fa356f6573e5d67252e547a309826641782cacc224b6dec2645245cd8b7ca9d90d212a9d0bfead1eae88cf1c067def7c705e6bc44cca01c7db
|
7
|
+
data.tar.gz: a64fe6106e4c2b6aaaeef87ed9c04f87857e1cab3663dcab4f53fe52312d7200230e37924386a2e21eb671d8aea794f23e7d4f3fd29f7a7291150b95579ec369
|
data/README.md
CHANGED
data/circle.yml
ADDED
data/lib/polytag.rb
CHANGED
@@ -8,24 +8,42 @@ module Polytag
|
|
8
8
|
base.extend(ClassMethods)
|
9
9
|
base.has_many :polytag_tag_relations, as: :tagged, class_name: '::Polytag::TagRelation'
|
10
10
|
base.has_many :polytag_tags, through: :polytag_tag_relations, class_name: '::Polytag::Tag'
|
11
|
-
base.__send__(:alias_method, :tag_relations, :polytag_tag_relations)
|
12
|
-
base.__send__(:alias_method, :tags, :polytag_tags)
|
11
|
+
base.__send__(:alias_method, :tag_relations, :polytag_tag_relations) unless base.method_defined?(:tag_relations)
|
12
|
+
base.__send__(:alias_method, :tags, :polytag_tags) unless base.method_defined?(:tags)
|
13
13
|
end
|
14
14
|
|
15
|
-
def tag_group(
|
16
|
-
|
15
|
+
def tag_group(_tag_group = nil)
|
16
|
+
@__polytag_tag_group_hash__ ||= {}
|
17
|
+
|
18
|
+
if _tag_group
|
19
|
+
@__polytag_tag_group_hash__.merge!(_tag_group)
|
20
|
+
@__polytag_tag_group__ = Polytag::TagGroup.search_by_hash(@__polytag_tag_group_hash__).first_or_create
|
21
|
+
else
|
22
|
+
@__polytag_tag_group_hash__ = {} if _tag_group.is_a?(Hash) && _tag_group.empty?
|
23
|
+
@__polytag_tag_group__
|
24
|
+
end
|
17
25
|
end
|
18
26
|
|
19
27
|
def add_tag(tag, _tag_group = {})
|
20
|
-
|
28
|
+
polytag_tags << polytag_tags.where(name: tag, polytag_tag_group_id: tag_group(_tag_group).try(&:id)).first_or_initialize
|
21
29
|
end
|
22
30
|
|
23
31
|
def add_tag!(tag, _tag_group = {})
|
24
|
-
|
32
|
+
polytag_tags << polytag_tags.where(name: tag, polytag_tag_group_id: tag_group(_tag_group).try(&:id)).first_or_create
|
33
|
+
end
|
34
|
+
|
35
|
+
def add_tags(*_tags)
|
36
|
+
_tag_group = _tags.pop if _tags.last.is_a?(Hash)
|
37
|
+
_tags.map { |x| add_tag(x, _tag_group || P{}) }
|
38
|
+
end
|
39
|
+
|
40
|
+
def add_tags!(*_tags)
|
41
|
+
_tag_group = _tags.pop if _tags.last.is_a?(Hash)
|
42
|
+
_tags.map { |x| add_tag!(x, _tag_group || {}) }
|
25
43
|
end
|
26
44
|
|
27
45
|
def remove_tag!(tag, _tag_group = {})
|
28
|
-
tag_id =
|
46
|
+
tag_id = polytag_tags.where(name: tag, polytag_tag_group_id: tag_group(_tag_group).try(&:id)).first.try(:id)
|
29
47
|
tag_relations.where("polytag_tag_relations.polytag_tag_id = ?", tag_id).delete_all
|
30
48
|
end
|
31
49
|
|
data/lib/polytag/tag_group.rb
CHANGED
data/lib/polytag/version.rb
CHANGED
@@ -3,11 +3,12 @@ require 'spec_helper'
|
|
3
3
|
describe "Create a a model with tags and query for them" do
|
4
4
|
|
5
5
|
# Create some random models with tags
|
6
|
-
let(:sample_classes) do
|
6
|
+
let!(:sample_classes) do
|
7
7
|
(0..5).to_a.map do |t|
|
8
8
|
klass = TestTaggableThree.create!(name: "test_#{Time.now}")
|
9
9
|
klass.tag_group(name: 'Apple')
|
10
|
-
|
10
|
+
entropy = ('A'..'E').to_a.shuffle.sample((2..3).to_a.sample)
|
11
|
+
klass.add_tags!(*entropy.concat(%w(A)))
|
11
12
|
klass
|
12
13
|
end
|
13
14
|
end
|
@@ -36,6 +37,8 @@ describe "Create a a model with tags and query for them" do
|
|
36
37
|
|
37
38
|
it "Should not find our `test_taggable` model in the `Apple` tag_group" do
|
38
39
|
TestTaggableThree.in_tag_group(name: 'Apple').should_not include(test_taggable)
|
40
|
+
TestTaggableThree.in_tag_group(name: 'Apple').should_not be_empty
|
41
|
+
TestTaggableThree.in_tag_group(name: 'Apple').count.should == 6
|
39
42
|
end
|
40
43
|
|
41
44
|
it "Should not find our `test_taggable` model in the `Apple` tag_group even if it shares a tag name" do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: polytag
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kelly Becker
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-10-
|
11
|
+
date: 2013-10-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -135,6 +135,7 @@ files:
|
|
135
135
|
- LICENSE.txt
|
136
136
|
- README.md
|
137
137
|
- Rakefile
|
138
|
+
- circle.yml
|
138
139
|
- lib/generators/polytag/install/install_generator.rb
|
139
140
|
- lib/generators/polytag/install/templates/create_polytag_tables.rb
|
140
141
|
- lib/polytag.rb
|