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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a3ffb789a97a168f562d82cbbcbafe9cea792d9c
4
- data.tar.gz: 74e21ca1f03b52ea295964ccdcba756250423e61
3
+ metadata.gz: d7026c601f2468b7dbc1c55128bcb05f2e0e5b69
4
+ data.tar.gz: 95aa739db8ed9f23ff7b9f669aa25d31b1403305
5
5
  SHA512:
6
- metadata.gz: 9ae4657972deba0f249602afd6f1003167e95896b80e76b66933f56f100f71355bd7ff41a141ec72e5aed8d8bd2868be8d1cceee870286015ca43ce31f360b23
7
- data.tar.gz: 2e20761a2789411d0113e4ca7813b8fd32ced24b15e8c5d741895284a7980aeb74f1a9dc9d977e255a6b2af809bc2d108822b7595ec34573d51682c3b5c27bdf
6
+ metadata.gz: 3f0bc37e41913104bad687f23aa95a9b0f1209304b9126ac302ba2e5b369965afaedabca3fde1306eb8d6ff0dd8b0d0829e5e3ef317d617654b661e751adcc10
7
+ data.tar.gz: 630ffb47d31a07a01f9e039e8b92cc01c41fb3b8cf9f5cc39135bb656b182111d1a9caf8bc74c2d27ae049f7cca7886c610b06b82fd097e79a1e309c9eef0f33
data/.gitignore CHANGED
@@ -10,3 +10,4 @@
10
10
  # rspec failure tracking
11
11
  .rspec_status
12
12
  .byebug_history
13
+ *.gem
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- freeze_tag (0.1.0)
4
+ freeze_tag (0.1.1)
5
5
  rails (>= 4.2)
6
6
 
7
7
  GEM
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 "ended_at" column, which can be updated to make them active or inactive.
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
 
@@ -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("ended_at IS NULL OR ended_at > ?", DateTime.now) }, as: :taggable, class_name: "FreezeTag::Tag"
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(ended_at: DateTime.now)
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.ended_at = exp_at
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.ended_at IS NULL OR freeze_tags.ended_at > '#{DateTime.now}') AND freeze_tags.tag = '#{as}' AND freeze_tags.list = '#{list}'")
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.ended_at IS NULL OR freeze_tags.ended_at > '#{DateTime.now}') AND freeze_tags.tag = '#{as}'")
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.ended_at < '#{DateTime.now}' AND freeze_tags.tag = '#{as}' AND freeze_tags.list = '#{list}'")
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.ended_at < '#{DateTime.now}' AND freeze_tags.tag = '#{as}'")
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
 
@@ -1,3 +1,3 @@
1
1
  module FreezeTag
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
@@ -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 :ended_at, index: true
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, :ended_at]
17
- add_index :freeze_tags, [:taggable_type, :taggable_id, :ended_at]
18
- add_index :freeze_tags, [:tag, :ended_at]
19
- add_index :freeze_tags, [:taggable_type, :taggable_id, :tag, :list], unique: true, name: "unique"
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.0
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-05 00:00:00.000000000 Z
11
+ date: 2018-04-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails