freeze_tag 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/Gemfile.lock +1 -1
- data/README.md +1 -1
- data/lib/freeze_tag/taggable.rb +8 -10
- data/lib/freeze_tag/version.rb +1 -1
- data/lib/generators/freeze_tag/install/templates/create_freeze_tag_tables.rb +5 -5
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d7026c601f2468b7dbc1c55128bcb05f2e0e5b69
|
4
|
+
data.tar.gz: 95aa739db8ed9f23ff7b9f669aa25d31b1403305
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3f0bc37e41913104bad687f23aa95a9b0f1209304b9126ac302ba2e5b369965afaedabca3fde1306eb8d6ff0dd8b0d0829e5e3ef317d617654b661e751adcc10
|
7
|
+
data.tar.gz: 630ffb47d31a07a01f9e039e8b92cc01c41fb3b8cf9f5cc39135bb656b182111d1a9caf8bc74c2d27ae049f7cca7886c610b06b82fd097e79a1e309c9eef0f33
|
data/.gitignore
CHANGED
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -8,7 +8,7 @@ As excellent and useful as ActsAsTaggable is, this library is attempt to reconci
|
|
8
8
|
|
9
9
|
1. Freeze tag allows for a more "stateless" approach to tagging.
|
10
10
|
|
11
|
-
Tags are never deleted, instead they have an "
|
11
|
+
Tags are never deleted, instead they have an "expired_at" column, which can be updated to make them inactive.
|
12
12
|
|
13
13
|
2. The associations are more simple.
|
14
14
|
|
data/lib/freeze_tag/taggable.rb
CHANGED
@@ -7,7 +7,7 @@ module FreezeTag
|
|
7
7
|
|
8
8
|
included do
|
9
9
|
has_many :freeze_tags, as: :taggable, class_name: "FreezeTag::Tag"
|
10
|
-
has_many :active_freeze_tags, -> { where("
|
10
|
+
has_many :active_freeze_tags, -> { where("expired_at IS NULL OR expired_at > ?", DateTime.now) }, as: :taggable, class_name: "FreezeTag::Tag"
|
11
11
|
|
12
12
|
def freeze_tag(as: [], expire_others: false, list: nil)
|
13
13
|
ActiveRecord::Base.transaction do
|
@@ -15,13 +15,11 @@ module FreezeTag
|
|
15
15
|
as = as.map(&:downcase) if self.class.try(:freeze_tag_case_sensitive)
|
16
16
|
|
17
17
|
if expire_others == true
|
18
|
-
active_freeze_tags.where(list: list).where.not(tag: as).update_all(
|
18
|
+
active_freeze_tags.where(list: list).where.not(tag: as).update_all(expired_at: DateTime.now)
|
19
19
|
end
|
20
20
|
|
21
21
|
as.each do |t|
|
22
|
-
ft = FreezeTag::Tag.find_or_create_by(taggable_type: self.class.name, taggable_id: self.id, tag: t, list: list)
|
23
|
-
ft.ended_at = nil
|
24
|
-
ft.save! if ft.changed?
|
22
|
+
ft = FreezeTag::Tag.find_or_create_by(taggable_type: self.class.name, taggable_id: self.id, tag: t, list: list, expired_at: nil)
|
25
23
|
end
|
26
24
|
end
|
27
25
|
end
|
@@ -39,7 +37,7 @@ module FreezeTag
|
|
39
37
|
to_exp = freeze_tags.find_by(tag: tag, list: list)
|
40
38
|
return nil unless to_exp.present?
|
41
39
|
exp_at = date.present? ? date : DateTime.now
|
42
|
-
to_exp.
|
40
|
+
to_exp.expired_at = exp_at
|
43
41
|
to_exp.save
|
44
42
|
end
|
45
43
|
|
@@ -49,18 +47,18 @@ module FreezeTag
|
|
49
47
|
def freeze_tagged(as: nil, list: nil)
|
50
48
|
as = as.downcase if self.try(:freeze_tag_case_sensitive)
|
51
49
|
if list.present?
|
52
|
-
self.joins("INNER JOIN freeze_tags ON freeze_tags.taggable_id = #{self.table_name}.id AND (freeze_tags.
|
50
|
+
self.joins("INNER JOIN freeze_tags ON freeze_tags.taggable_id = #{self.table_name}.id AND (freeze_tags.expired_at IS NULL OR freeze_tags.expired_at > '#{DateTime.now}') AND freeze_tags.tag = '#{as}' AND freeze_tags.list = '#{list}'")
|
53
51
|
else
|
54
|
-
self.joins("INNER JOIN freeze_tags ON freeze_tags.taggable_id = #{self.table_name}.id AND (freeze_tags.
|
52
|
+
self.joins("INNER JOIN freeze_tags ON freeze_tags.taggable_id = #{self.table_name}.id AND (freeze_tags.expired_at IS NULL OR freeze_tags.expired_at > '#{DateTime.now}') AND freeze_tags.tag = '#{as}'")
|
55
53
|
end
|
56
54
|
end
|
57
55
|
|
58
56
|
def previously_freeze_tagged(as: nil, list: nil)
|
59
57
|
as = as.downcase if self.try(:freeze_tag_case_sensitive)
|
60
58
|
if list.present?
|
61
|
-
self.joins("INNER JOIN freeze_tags ON freeze_tags.taggable_id = #{self.table_name}.id AND freeze_tags.
|
59
|
+
self.joins("INNER JOIN freeze_tags ON freeze_tags.taggable_id = #{self.table_name}.id AND freeze_tags.expired_at < '#{DateTime.now}' AND freeze_tags.tag = '#{as}' AND freeze_tags.list = '#{list}'")
|
62
60
|
else
|
63
|
-
self.joins("INNER JOIN freeze_tags ON freeze_tags.taggable_id = #{self.table_name}.id AND freeze_tags.
|
61
|
+
self.joins("INNER JOIN freeze_tags ON freeze_tags.taggable_id = #{self.table_name}.id AND freeze_tags.expired_at < '#{DateTime.now}' AND freeze_tags.tag = '#{as}'")
|
64
62
|
end
|
65
63
|
end
|
66
64
|
|
data/lib/freeze_tag/version.rb
CHANGED
@@ -9,13 +9,13 @@ class CreateFreezeTagTables < ActiveRecord::Migration
|
|
9
9
|
t.string :list, index: true
|
10
10
|
# t.uuid :taggable_id, index: true, null: false # Use this if you're mapping using UUIDs as a primary key
|
11
11
|
# t.integer :taggable_id, index: true, null: false # Use this if you're mapping using Integer Primary Keys
|
12
|
-
t.datetime :
|
12
|
+
t.datetime :expired_at, index: true
|
13
13
|
t.timestamps
|
14
14
|
end
|
15
15
|
|
16
|
-
add_index :freeze_tags, [:taggable_type, :taggable_id, :tag, :
|
17
|
-
add_index :freeze_tags, [:taggable_type, :taggable_id, :
|
18
|
-
add_index :freeze_tags, [:tag, :
|
19
|
-
add_index :freeze_tags, [:taggable_type, :taggable_id, :tag, :list], unique: true, name: "
|
16
|
+
add_index :freeze_tags, [:taggable_type, :taggable_id, :tag, :expired_at, :list]
|
17
|
+
add_index :freeze_tags, [:taggable_type, :taggable_id, :expired_at, :list]
|
18
|
+
add_index :freeze_tags, [:tag, :expired_at, :list]
|
19
|
+
add_index :freeze_tags, [:taggable_type, :taggable_id, :tag, :list, :expired_at], unique: true, name: "fz_unique_tt_tid_t_li_ex_at"
|
20
20
|
end
|
21
21
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: freeze_tag
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Paul Franzen
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-04-
|
11
|
+
date: 2018-04-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|