records_rip 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +33 -0
- data/Gemfile.lock +1 -1
- data/README.md +23 -2
- data/Rakefile +9 -1
- data/lib/records_rip/model.rb +11 -2
- data/lib/records_rip/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8fecd3e94adbd056f3f663df95e1b82cb833c8286df376b0429693d57b05b3e0
|
4
|
+
data.tar.gz: 5640b2b8b6004984ecebfbaf2adbb6f8f25d38e094e1833cc3295748114c9c0c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5357c054043a34603c920f8a48aca5f051bbecd276510187cbb094497725511f6bf4c7a0fdb7ec51fe7e8051244068512c25d046242bdc06e3471b3d9272b077
|
7
|
+
data.tar.gz: e5bc1f6e9fea4caeb38a772592d965f5b8e28ea396902e73b470fce7b5765d6dbada047bede91e5d36e5a1d2f41f82adf6f47353dae29cf2dbcda1ebe18544f3
|
data/.travis.yml
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
language: ruby
|
2
|
+
cache: bundler
|
3
|
+
|
4
|
+
# For ruby compatibility, we test the highest and lowest minor versions only.
|
5
|
+
# For example, if our gemspec says `required_ruby_version = ">= 2.3.0"`, and
|
6
|
+
# ruby 2.5.0 has just been released, then we test 2.3 and 2.5, but not 2.4.
|
7
|
+
rvm:
|
8
|
+
- 2.3.8
|
9
|
+
- 2.4.5
|
10
|
+
- 2.5.3
|
11
|
+
|
12
|
+
env:
|
13
|
+
global:
|
14
|
+
- TRAVIS=true
|
15
|
+
matrix:
|
16
|
+
- DB=mysql
|
17
|
+
- DB=postgres
|
18
|
+
- DB=sqlite
|
19
|
+
|
20
|
+
# We want to use `sudo: false` because the container infrastructure is supposed
|
21
|
+
# to be faster, but Travis is having issues with containers lately ..
|
22
|
+
#
|
23
|
+
# > No output has been received in the last 10m0s
|
24
|
+
#
|
25
|
+
# .. and they recommend we use the VM infrastructure (`sudo: required`) in
|
26
|
+
# the meantime.
|
27
|
+
sudo: required
|
28
|
+
|
29
|
+
before_install:
|
30
|
+
- gem update bundler
|
31
|
+
|
32
|
+
addons:
|
33
|
+
postgresql: "9.4"
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -1,8 +1,11 @@
|
|
1
1
|
# Records, R.I.P.
|
2
2
|
|
3
|
+
[![Build Status](https://travis-ci.org/ts-3156/records_rip.svg?branch=master)](https://travis-ci.org/ts-3156/records_rip)
|
4
|
+
[![Gem Version](https://badge.fury.io/rb/records_rip.svg)](https://badge.fury.io/rb/records_rip)
|
5
|
+
|
3
6
|
This gem is a place to let deleted records rest in peace. :coffin:
|
4
7
|
|
5
|
-
Soft deletes are evil.
|
8
|
+
Soft deletes are evil. __Blest be y man y spares thes stones. And curst be he y moves my bones.__
|
6
9
|
|
7
10
|
## Getting Started
|
8
11
|
|
@@ -25,7 +28,25 @@ end
|
|
25
28
|
You can perform WHERE queries for `tombs#epitaph` based on attributes:
|
26
29
|
|
27
30
|
```ruby
|
28
|
-
User.
|
31
|
+
user = User.create(name: 'Smith')
|
32
|
+
user.destroy
|
33
|
+
|
34
|
+
User.tomb(name: 'Smith').to_a
|
35
|
+
# => [#<RecordsRip::Tomb id: 1, item_type: "User", item_id: 1, epitaph: "{\"id\"=>1, \"name\"=>\"Smith\"}">]
|
36
|
+
```
|
37
|
+
|
38
|
+
#### Change serialization method
|
39
|
+
|
40
|
+
```ruby
|
41
|
+
class User < ApplicationRecord
|
42
|
+
rest_in_place {|record| Hash[record.attributes.map {|k, v| [k, "Great #{v}"]}] }
|
43
|
+
end
|
44
|
+
|
45
|
+
user = User.create(name: 'Smith')
|
46
|
+
user.destroy
|
47
|
+
|
48
|
+
User.tomb(name: 'Great Smith').to_a
|
49
|
+
# => [#<RecordsRip::Tomb id: 1, item_type: "User", item_id: 1, epitaph: "{\"id\"=>1, \"name\"=>\"Great Smith\"}">]
|
29
50
|
```
|
30
51
|
|
31
52
|
## Contributing
|
data/Rakefile
CHANGED
data/lib/records_rip/model.rb
CHANGED
@@ -5,13 +5,22 @@ module RecordsRip
|
|
5
5
|
extend ActiveSupport::Concern
|
6
6
|
|
7
7
|
class_methods do
|
8
|
-
def rest_in_place
|
8
|
+
def rest_in_place(&block)
|
9
9
|
model_class = self
|
10
10
|
|
11
|
+
serializer =
|
12
|
+
if block_given?
|
13
|
+
block
|
14
|
+
else
|
15
|
+
lambda do |record|
|
16
|
+
Hash[record.attributes.map {|k, v| [k, v]}]
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
11
20
|
model_class.send(
|
12
21
|
"before_destroy",
|
13
22
|
lambda do |record|
|
14
|
-
epitaph =
|
23
|
+
epitaph = serializer.call(record)
|
15
24
|
::RecordsRip::Tomb.create(item_id: record.id, item_type: record.class.name, epitaph: epitaph)
|
16
25
|
end
|
17
26
|
)
|
data/lib/records_rip/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: records_rip
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ts-3156
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-12-
|
11
|
+
date: 2018-12-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -108,6 +108,7 @@ extensions: []
|
|
108
108
|
extra_rdoc_files: []
|
109
109
|
files:
|
110
110
|
- ".gitignore"
|
111
|
+
- ".travis.yml"
|
111
112
|
- Gemfile
|
112
113
|
- Gemfile.lock
|
113
114
|
- LICENSE.txt
|