deleted_at 0.5.0.pre.1 → 0.5.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 +5 -5
- data/README.md +39 -3
- data/lib/deleted_at/core.rb +6 -7
- data/lib/deleted_at/legacy.rb +2 -2
- data/lib/deleted_at/version.rb +1 -1
- metadata +11 -9
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
|
-
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: 29aee507393739895b695138545e5c6898c21d95
|
|
4
|
+
data.tar.gz: f52a30d0f52ae37e24641f4e5a9c74324bc75186
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 0b5c88eb056b584f4aebcbe24ebf28fd4e84d78dea0d23e39a23d107e48f2f28aac213c5880028bf38896bb395b6ba1e42341665846ec75dd25406afbf237883
|
|
7
|
+
data.tar.gz: 128097c8e330be5ca187adb07b9f5ce8ef45a819400f9028b364c53a4af71d53bf34c6b7f128c6b9f804ae84c7e3176d8d9e0380f5a1d8e90f504d57b054e57a
|
data/README.md
CHANGED
|
@@ -2,16 +2,16 @@
|
|
|
2
2
|
[](https://travis-ci.org/TwilightCoders/deleted_at)
|
|
3
3
|
[](https://codeclimate.com/github/TwilightCoders/deleted_at/maintainability)
|
|
4
4
|
[](https://codeclimate.com/github/TwilightCoders/deleted_at/coverage)
|
|
5
|
-
[](https://depfu.com/github/TwilightCoders/deleted_at)
|
|
6
6
|
|
|
7
7
|
# DeletedAt
|
|
8
8
|
|
|
9
|
-
Hide your "deleted" data (unless specifically asked for) without resorting to `default_scope` by leveraging in-line sub-selects.
|
|
9
|
+
Hide your "deleted" data (unless specifically asked for) without resorting to `default_scope` by leveraging in-line sub-selects. (See the [Upgrading](#upgrading) section)
|
|
10
10
|
|
|
11
11
|
## Requirements
|
|
12
12
|
|
|
13
13
|
- Ruby 2.3+
|
|
14
|
-
- ActiveRecord 4.
|
|
14
|
+
- ActiveRecord 4.1+
|
|
15
15
|
|
|
16
16
|
## Installation
|
|
17
17
|
|
|
@@ -77,6 +77,42 @@ class CreatCommentsTable < ActiveRecord::Migration
|
|
|
77
77
|
end
|
|
78
78
|
```
|
|
79
79
|
|
|
80
|
+
## [Upgrading](#upgrading)
|
|
81
|
+
|
|
82
|
+
If you've used `deleted_at` prior to v0.5.0, you'll need to migrate your schema. The new version of `deleted_at` no longer uses views, instead constructing a subselect on the relations. This significantly reduces code polution and monkey patching, as well as reducing the runtime memory usage for rails. Your Database will look (and be) a lot cleaner with no `deleted_at` views and your ERDs will be much cleaner as well.
|
|
83
|
+
|
|
84
|
+
Here is an example of a migration for upgrading
|
|
85
|
+
```
|
|
86
|
+
require 'deleted_at/legacy'
|
|
87
|
+
|
|
88
|
+
DeletedAt.disable
|
|
89
|
+
|
|
90
|
+
class UpgradeDeletedAt < ActiveRecord::Migration
|
|
91
|
+
def up
|
|
92
|
+
# hip hip hooray!
|
|
93
|
+
models.each do |model|
|
|
94
|
+
DeletedAt::Legacy.uninstall(model)
|
|
95
|
+
end
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
def down
|
|
99
|
+
# booo hiss
|
|
100
|
+
models.each do |model|
|
|
101
|
+
DeletedAt::Legacy.install(model)
|
|
102
|
+
end
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
private
|
|
106
|
+
|
|
107
|
+
def models
|
|
108
|
+
[
|
|
109
|
+
User,
|
|
110
|
+
Post
|
|
111
|
+
]
|
|
112
|
+
end
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
```
|
|
80
116
|
## Development
|
|
81
117
|
|
|
82
118
|
After checking out the repo, run `bundle` to install dependencies. Then, run `bundle exec rspec` to run the tests.
|
data/lib/deleted_at/core.rb
CHANGED
|
@@ -6,9 +6,8 @@ module DeletedAt
|
|
|
6
6
|
|
|
7
7
|
def self.prepended(subclass)
|
|
8
8
|
class << subclass
|
|
9
|
-
cattr_accessor :deleted_at
|
|
10
|
-
|
|
11
|
-
end
|
|
9
|
+
cattr_accessor :deleted_at
|
|
10
|
+
self.deleted_at = {}
|
|
12
11
|
alias all_without_deleted_at all
|
|
13
12
|
end
|
|
14
13
|
|
|
@@ -21,17 +20,17 @@ module DeletedAt
|
|
|
21
20
|
end
|
|
22
21
|
|
|
23
22
|
def self.has_deleted_at_column?(klass)
|
|
24
|
-
klass.columns.map(&:name).include?(klass.deleted_at
|
|
23
|
+
klass.columns.map(&:name).include?(klass.deleted_at.dig(:column).to_s)
|
|
25
24
|
end
|
|
26
25
|
|
|
27
26
|
module ClassMethods
|
|
28
27
|
|
|
29
28
|
def with_deleted_at(options={}, &block)
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
self.deleted_at.merge(options)
|
|
29
|
+
self.deleted_at = DeletedAt::DEFAULT_OPTIONS.merge(options)
|
|
33
30
|
self.deleted_at[:proc] = block if block_given?
|
|
34
31
|
|
|
32
|
+
return if ::DeletedAt.disabled?
|
|
33
|
+
|
|
35
34
|
DeletedAt::Core.raise_missing(self) unless Core.has_deleted_at_column?(self)
|
|
36
35
|
|
|
37
36
|
self.prepend(DeletedAt::ActiveRecord)
|
data/lib/deleted_at/legacy.rb
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
module DeletedAt
|
|
2
2
|
module Legacy
|
|
3
3
|
def self.uninstall(model)
|
|
4
|
-
return false unless
|
|
4
|
+
return false unless Core.has_deleted_at_column?(model)
|
|
5
5
|
|
|
6
6
|
uninstall_deleted_view(model)
|
|
7
7
|
uninstall_present_view(model)
|
|
8
8
|
end
|
|
9
9
|
|
|
10
10
|
def self.install(model)
|
|
11
|
-
return false unless
|
|
11
|
+
return false unless Core.has_deleted_at_column?(model)
|
|
12
12
|
|
|
13
13
|
install_present_view(model)
|
|
14
14
|
install_deleted_view(model)
|
data/lib/deleted_at/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: deleted_at
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.5.0
|
|
4
|
+
version: 0.5.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Dale Stevens
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2018-
|
|
11
|
+
date: 2018-06-25 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: activerecord
|
|
@@ -16,7 +16,7 @@ dependencies:
|
|
|
16
16
|
requirements:
|
|
17
17
|
- - ">="
|
|
18
18
|
- !ruby/object:Gem::Version
|
|
19
|
-
version: '4.
|
|
19
|
+
version: '4.1'
|
|
20
20
|
- - "<"
|
|
21
21
|
- !ruby/object:Gem::Version
|
|
22
22
|
version: '6'
|
|
@@ -26,7 +26,7 @@ dependencies:
|
|
|
26
26
|
requirements:
|
|
27
27
|
- - ">="
|
|
28
28
|
- !ruby/object:Gem::Version
|
|
29
|
-
version: '4.
|
|
29
|
+
version: '4.1'
|
|
30
30
|
- - "<"
|
|
31
31
|
- !ruby/object:Gem::Version
|
|
32
32
|
version: '6'
|
|
@@ -100,7 +100,7 @@ dependencies:
|
|
|
100
100
|
- - "~>"
|
|
101
101
|
- !ruby/object:Gem::Version
|
|
102
102
|
version: '0.7'
|
|
103
|
-
description: Default scopes are bad. Don't delete your data.
|
|
103
|
+
description: Default scopes are bad. Don't delete your data.
|
|
104
104
|
email:
|
|
105
105
|
- dale@twilightcoders.net
|
|
106
106
|
executables: []
|
|
@@ -123,7 +123,9 @@ licenses:
|
|
|
123
123
|
- MIT
|
|
124
124
|
metadata:
|
|
125
125
|
allowed_push_host: https://rubygems.org
|
|
126
|
-
post_install_message:
|
|
126
|
+
post_install_message: |
|
|
127
|
+
If you're upgrading from < 0.5.0, please follow the upgrade instructions
|
|
128
|
+
on https://github.com/TwilightCoders/deleted_at.
|
|
127
129
|
rdoc_options: []
|
|
128
130
|
require_paths:
|
|
129
131
|
- lib
|
|
@@ -134,12 +136,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
134
136
|
version: '2.3'
|
|
135
137
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
136
138
|
requirements:
|
|
137
|
-
- - "
|
|
139
|
+
- - ">="
|
|
138
140
|
- !ruby/object:Gem::Version
|
|
139
|
-
version:
|
|
141
|
+
version: '0'
|
|
140
142
|
requirements: []
|
|
141
143
|
rubyforge_project:
|
|
142
|
-
rubygems_version: 2.
|
|
144
|
+
rubygems_version: 2.5.2.1
|
|
143
145
|
signing_key:
|
|
144
146
|
specification_version: 4
|
|
145
147
|
summary: Soft delete your data, but keep it clean.
|