discard 0.1.0 → 0.2.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: '05822379b2886d4ccb77a0a4d949360995765ac9'
4
- data.tar.gz: e91766d115a3a52bc92c7f8a11caaa8ae07b0025
3
+ metadata.gz: e3d4174c8881bc3bf1fa453aafb3d966d8361292
4
+ data.tar.gz: 858b1edbe5d9c09144239a13cc3ca662f1485547
5
5
  SHA512:
6
- metadata.gz: 8d056bd501e220739f73021bb2054fc0b127a3f33b96eee7b570d0e4c8f5b133d8fc5522c58747517cbe84b82097b2d408285ad256174ed5fac8460db7644c1f
7
- data.tar.gz: f5012b9b5af4c812b52376635e64581c7ae7f403cfd4214b68769abdafc4d49ef2988b4e4874bcdbe57603b363b2f6c871ffbe4cd060c54d059711868deee555
6
+ metadata.gz: 1246d6187b35af15ceb8d5e8a1b914e09a45ba0380d833ca638305336d3075e67f60edc67fad55c49e994b0ab9e9f60b3d9a916acc837d3416b3b89ec56e2bcd
7
+ data.tar.gz: 1d098bf07dcefdd3d338b0a4a73b206dfd96e5c39b8abbabb17cd749970ff9c54efd3d35fe7f6f363f8c35b076b7e54f278f1f3cbb43de7330da0a363671f2f5
@@ -10,6 +10,14 @@ module Discard
10
10
  scope :undiscarded, ->{ where(discard_column => nil) }
11
11
  scope :discarded, ->{ where.not(discard_column => nil) }
12
12
  scope :with_discarded, ->{ unscope(where: discard_column) }
13
+
14
+ define_model_callbacks :discard
15
+ end
16
+
17
+ class_methods do
18
+ def discard_all
19
+ all.each(&:discard)
20
+ end
13
21
  end
14
22
 
15
23
  def discarded?
@@ -17,7 +25,19 @@ module Discard
17
25
  end
18
26
 
19
27
  def discard
20
- touch(self.class.discard_column) unless discarded?
28
+ unless discarded?
29
+ with_transaction_returning_status do
30
+ run_callbacks(:discard) do
31
+ self[self.class.discard_column] = Time.current
32
+ save
33
+ end
34
+ end
35
+ end
36
+ end
37
+
38
+ def undiscard
39
+ self[self.class.discard_column] = nil
40
+ save
21
41
  end
22
42
  end
23
43
  end
@@ -1,3 +1,3 @@
1
1
  module Discard
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: discard
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Hawthorn
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-04-28 00:00:00.000000000 Z
11
+ date: 2017-11-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord