polytag 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/polytag.rb +12 -4
- data/lib/polytag/tag.rb +7 -3
- data/lib/polytag/tag_group.rb +5 -1
- data/lib/polytag/tag_group/owner.rb +13 -4
- data/lib/polytag/tag_relation.rb +1 -1
- data/lib/polytag/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b081aadd687235fc80ef0e6fe2ac99bdccf8edff
|
4
|
+
data.tar.gz: 559397b671a71e791ad423a0221260ca4112bb0c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a316be1f475ad261c166c43e3689091f70f4e98b881c195147400f71a62569eb7b3cd10add70f83965831d8a539a3075dedcd77d8f6e18d4e9613304384ae922
|
7
|
+
data.tar.gz: 8b37be6c30b19c9bf7ff2809bef05398f287fa36be499955c9765ceddea4b7669166932e84439a91f52faa44ca77274023e3fdf33361f09a8076d00c2839183a
|
data/lib/polytag.rb
CHANGED
@@ -7,10 +7,18 @@ require "polytag/tag_relation"
|
|
7
7
|
module Polytag
|
8
8
|
def self.included(base)
|
9
9
|
base.extend(ClassMethods)
|
10
|
-
base.has_many :polytag_tag_relations,
|
11
|
-
|
12
|
-
|
13
|
-
base.
|
10
|
+
base.has_many :polytag_tag_relations, class_name: '::Polytag::TagRelation',
|
11
|
+
as: :tagged
|
12
|
+
|
13
|
+
base.has_many :tag_relations, class_name: '::Polytag::TagRelation',
|
14
|
+
as: :tagged
|
15
|
+
|
16
|
+
base.has_many :polytag_tags, class_name: '::Polytag::Tag',
|
17
|
+
through: :polytag_tag_relations
|
18
|
+
|
19
|
+
base.has_many :tags, class_name: '::Polytag::Tag',
|
20
|
+
through: :polytag_tag_relations,
|
21
|
+
source: :polytag_tag
|
14
22
|
end
|
15
23
|
|
16
24
|
def tag_group(_tag_group = nil)
|
data/lib/polytag/tag.rb
CHANGED
@@ -1,17 +1,21 @@
|
|
1
1
|
class Polytag::Tag < ActiveRecord::Base
|
2
2
|
self.table_name = :polytag_tags
|
3
3
|
belongs_to :polytag_tag_group, class_name: '::Polytag::TagGroup'
|
4
|
+
belongs_to :tag_group, class_name: '::Polytag::TagGroup',
|
5
|
+
foreign_key: :polytag_tag_group_id
|
6
|
+
|
4
7
|
has_many :polytag_tag_relations, class_name: '::Polytag::TagRelation',
|
5
8
|
foreign_key: :polytag_tag_id,
|
6
9
|
dependent: :destroy
|
7
10
|
|
8
|
-
|
9
|
-
|
11
|
+
has_many :relations, class_name: '::Polytag::TagRelation',
|
12
|
+
foreign_key: :polytag_tag_id,
|
13
|
+
dependent: :destroy
|
10
14
|
|
11
15
|
# Indiscrimanetly get
|
12
16
|
# the tagged models
|
13
17
|
def tagged
|
14
|
-
polytag_tag_relations.tagged
|
18
|
+
polytag_tag_relations.tagged.flatten
|
15
19
|
end
|
16
20
|
|
17
21
|
# Cleanup group if there are
|
data/lib/polytag/tag_group.rb
CHANGED
@@ -1,11 +1,15 @@
|
|
1
1
|
class Polytag::TagGroup < ActiveRecord::Base
|
2
2
|
self.table_name = :polytag_tag_groups
|
3
|
+
|
3
4
|
has_many :polytag_tag, class_name: '::Polytag::Tag',
|
4
5
|
foreign_key: :polytag_tag_group_id,
|
5
6
|
dependent: :destroy
|
6
7
|
|
8
|
+
has_many :tag, class_name: '::Polytag::Tag',
|
9
|
+
foreign_key: :polytag_tag_group_id,
|
10
|
+
dependent: :destroy
|
11
|
+
|
7
12
|
belongs_to :owner, polymorphic: true
|
8
|
-
alias_method :tag, :polytag_tag
|
9
13
|
|
10
14
|
# Cleanup tag if there are
|
11
15
|
# no more relations left on the tag
|
@@ -1,8 +1,17 @@
|
|
1
1
|
module Polytag::TagGroup::Owner
|
2
2
|
def self.included(base)
|
3
|
-
base.has_many :polytag_tag_groups,
|
4
|
-
|
5
|
-
|
6
|
-
base.
|
3
|
+
base.has_many :polytag_tag_groups, class_name: '::Polytag::TagGroup',
|
4
|
+
as: :owner
|
5
|
+
|
6
|
+
base.has_many :tag_groups, class_name: '::Polytag::TagGroup',
|
7
|
+
as: :owner
|
8
|
+
|
9
|
+
base.has_many :polytag_owned_tags, class_name: '::Polytag::Tag',
|
10
|
+
through: :polytag_tag_groups,
|
11
|
+
source: :polytag_tag
|
12
|
+
|
13
|
+
base.has_many :owned_tags, class_name: '::Polytag::Tag',
|
14
|
+
through: :polytag_tag_groups,
|
15
|
+
source: :polytag_tag
|
7
16
|
end
|
8
17
|
end
|
data/lib/polytag/tag_relation.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
class Polytag::TagRelation < ActiveRecord::Base
|
2
2
|
self.table_name = :polytag_tag_relations
|
3
3
|
belongs_to :polytag_tag, class_name: '::Polytag::Tag'
|
4
|
+
belongs_to :tag, class_name: '::Polytag::Tag', foreign_key: :polytag_tag_id
|
4
5
|
belongs_to :tagged, polymorphic: true
|
5
|
-
alias_method :tag, :polytag_tag
|
6
6
|
|
7
7
|
# Cleanup tag if there are
|
8
8
|
# no more relations left on the tag
|
data/lib/polytag/version.rb
CHANGED