needle_in_a_haystack 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/lib/needle_in_a_haystack/haystack_tag.rb +6 -12
- data/lib/needle_in_a_haystack/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dcc57ef8ef5c022fd98794c87852be14133a293b05b765f5b1152384dbf4b944
|
4
|
+
data.tar.gz: 67a37aa74001245538ba6e467e28bd3a1a23117a1452dcd1af8b5c68e6ef8ad0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bd9bfdf36861ad29009088e358833bca69a1612e078229d8cd4205a57386459bfaff8325cb967e474e7cc83b3df70b62586a8a9768ab8fb12c7ad3bb8176b40b
|
7
|
+
data.tar.gz: b752e74b8f878ed842691f85cb4bd6e89cfe116e880769447a92ab3107daf2be6f979acd349d1e72cff9352d7e5177dd3005a513deabbec31ccdd6ca32b9c183
|
@@ -1,25 +1,19 @@
|
|
1
1
|
class HaystackTag < ApplicationRecord
|
2
|
-
belongs_to :parent_tag, class_name: "
|
3
|
-
has_many :children, class_name: "
|
2
|
+
belongs_to :parent_tag, class_name: "HaystackTag", optional: true
|
3
|
+
has_many :children, class_name: "HaystackTag", foreign_key: "parent_tag_id", dependent: :destroy, inverse_of: :parent_tag
|
4
4
|
has_many :haystack_taggings, dependent: :destroy
|
5
5
|
has_many :taggables, through: :haystack_taggings
|
6
6
|
|
7
|
-
if NeedleInAHaystack.respond_to?(:configuration) && NeedleInAHaystack.configuration&.taggable_models
|
8
|
-
NeedleInAHaystack.configuration.taggable_models.each do |model|
|
9
|
-
has_many "taggable_#{model.name.underscore.pluralize}".to_sym, through: :haystack_taggings, source: :taggable, source_type: model.name
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
7
|
validates :name, presence: true
|
14
8
|
validates :description, presence: true
|
15
9
|
validate :prevent_circular_reference
|
16
10
|
|
17
11
|
def ancestors
|
18
12
|
ancestors = []
|
19
|
-
|
20
|
-
while
|
21
|
-
ancestors <<
|
22
|
-
|
13
|
+
current = self
|
14
|
+
while current.parent_tag
|
15
|
+
ancestors << current.parent_tag
|
16
|
+
current = current.parent_tag
|
23
17
|
end
|
24
18
|
ancestors
|
25
19
|
end
|
@@ -1 +1 @@
|
|
1
|
-
VERSION = "1.0.
|
1
|
+
VERSION = "1.0.2".freeze
|