storage_unit 0.0.2 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +5 -1
- data/lib/storage_unit/core.rb +8 -0
- data/lib/storage_unit/version.rb +1 -1
- data/spec/storage_unit_spec.rb +9 -0
- 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: e9b686097ab6166d0cd66e90befe241fe8e0d256
|
4
|
+
data.tar.gz: 0ffecafa0a2ed6be9eea6c9df9458ae4b6955158
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e3dce4c8c63d991a29fb95b81b55e76c4471fd4414b195af8429cf0eee6326d688ef80b5325895c659c0b0fa9c6dc9fb94c73b9e3c9553632e44f18c7522bf8c
|
7
|
+
data.tar.gz: 21d4d67daffd46dc445769bd42781a512cff16a959b5591fc1727ce46a607680a2ccbbb78293d98424f78f2dfeb8014c63661c66410386857208da52de14f6ff
|
data/README.md
CHANGED
@@ -46,7 +46,11 @@ post.trashed? # => false
|
|
46
46
|
post.trash!
|
47
47
|
post.trashed? # => true
|
48
48
|
Post.all # => []
|
49
|
-
Post.with_deleted
|
49
|
+
Post.with_deleted # => [post]
|
50
|
+
|
51
|
+
new_post = Post.create
|
52
|
+
Post.with_deleted # => [post, new_post]
|
53
|
+
Post.deleted_only # => [post]
|
50
54
|
|
51
55
|
post.recover!
|
52
56
|
post.trashed? # => false
|
data/lib/storage_unit/core.rb
CHANGED
@@ -13,6 +13,10 @@ module StorageUnit
|
|
13
13
|
all.table[storage_unit_opts[:column]].eq(nil).to_sql
|
14
14
|
end
|
15
15
|
|
16
|
+
def deleted_only_scope_sql
|
17
|
+
all.table[storage_unit_opts[:column]].not_eq(nil).to_sql
|
18
|
+
end
|
19
|
+
|
16
20
|
# lifted from acts_as_paranoid, works around https://github.com/rails/rails/issues/4306
|
17
21
|
# with this in place Post.limit(10).with_deleted, will work as expected
|
18
22
|
def with_deleted
|
@@ -20,6 +24,10 @@ module StorageUnit
|
|
20
24
|
scope.where_values.delete(with_deleted_scope_sql)
|
21
25
|
scope
|
22
26
|
end
|
27
|
+
|
28
|
+
def deleted_only
|
29
|
+
with_deleted.where(deleted_only_scope_sql)
|
30
|
+
end
|
23
31
|
end
|
24
32
|
|
25
33
|
def trashed?
|
data/lib/storage_unit/version.rb
CHANGED
data/spec/storage_unit_spec.rb
CHANGED
@@ -90,6 +90,15 @@ describe 'Default scope' do
|
|
90
90
|
end
|
91
91
|
end
|
92
92
|
|
93
|
+
describe '.deleted_only' do
|
94
|
+
let!(:user) { User.create }
|
95
|
+
let!(:deleted_user) { User.create(deleted_at: Time.now) }
|
96
|
+
|
97
|
+
it 'functions properly' do
|
98
|
+
expect(User.deleted_only.count).to eq 1
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
93
102
|
describe '#trashed?' do
|
94
103
|
let!(:user) { User.create }
|
95
104
|
subject { user }
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: storage_unit
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adam Becker
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-04-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|