Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
93 commits
Select commit Hold shift + click to select a range
f23ef44
use bang bang
May 17, 2013
18dd3f1
Formatting and strings
Jul 2, 2013
7bbd9a8
Upgrade some gems
Jul 2, 2013
434a0d9
Use all instead of scoped
Jul 2, 2013
fda5b32
Fix broken tests
Jul 2, 2013
52946b9
Add travis ruby versions
Jul 2, 2013
bcbd4d9
Use https://rubygems.org for Gemfile source
radar Jul 8, 2013
4e48a78
Force dependency on only AR 3.2 for master branch
radar Jul 8, 2013
e384eff
Use #all because #scoped is deprecated
radar Jul 8, 2013
cd02d0d
Add pry for debugging purposes
radar Jul 8, 2013
1e703ba
Use string for where_values_hash rather than symbol
radar Jul 8, 2013
e1d8ea1
exists? in AR now returns nil when a record cannot be found.
radar Jul 8, 2013
a2db597
Bump to 1.3.0
radar Jul 8, 2013
366c3e1
Update README with rails4 instructions
radar Jul 8, 2013
cd7bd20
Use 'scoped', not 'all' in only_deleted and with_deleted
radar Jul 8, 2013
6670dce
Bump to 1.3.1
radar Jul 8, 2013
6420d26
change git branch rails-4 to rails4
Jul 9, 2013
c7f2a72
Add aliases to sync with mongoid paranoia
Jul 11, 2013
2f74123
Merge conflicts
Jul 11, 2013
c27a5c1
Fix conflict merges
Jul 11, 2013
6762f97
Merge branch 'feature/mongoid-paranoia-sync' into develop
Jul 11, 2013
2d79e57
Fix scoped vs all
Jul 11, 2013
30c87c8
Merge pull request #64 from delba/patch-1
radar Jul 12, 2013
7773418
Remove debugger
Jul 16, 2013
63ffba7
Merge pull request #66 from jwg2s/develop
radar Jul 18, 2013
11cf0f1
Add Model.restore(ids) function
Sep 9, 2013
0914990
Fix issue with default scope clashing with deletion. "update_column" …
heisenbugged Sep 17, 2013
62756c0
Merge pull request #70 from laspluviosillas/master
radar Sep 23, 2013
9c5cd2b
destroy! when destroying deleted? records
michaltn Oct 4, 2013
4ece33f
Add test for destroy of a deleted? object
michaltn Oct 9, 2013
8d36866
Add description of destroy! behavior to README
michaltn Oct 9, 2013
3b9e594
Merge pull request #71 from michaltn/master
radar Oct 10, 2013
714fb9f
Add callbacks for 'new' AR lifecycle :restore
michaeljd Oct 17, 2013
378b51c
Remove conflict from paranoia_test
radar Oct 20, 2013
4c617bb
Merge pull request #57 from delba/bangbang
radar Oct 24, 2013
fbf95d1
Reuse with_deleted for only_deleted
radar Oct 24, 2013
f57695b
Use quoted table name in default scope (call me paranoid)
sohara Oct 23, 2013
ffa40a2
Bump to 1.3.2
radar Oct 24, 2013
b81b3af
Add configuration option for column name
quainjn Oct 24, 2013
d28a4a0
Add anti-regression test for #81
radar Nov 5, 2013
0af156c
add tests for plain models callback
alfa-jpn Nov 6, 2013
6e72b84
Notify observers of paranoid restores
arsduo Dec 9, 2013
4677f90
Update Gemfile and gemspec to allow JRuby and Rubinius. Add JRuby and…
petergoldstein Dec 15, 2013
d7bdb06
Add details about accessing soft-deleted associations
radar Dec 17, 2013
a0ec1c9
Add :recursive option on restore to restore associations
remi Dec 17, 2013
13397e5
Update README with more usage examples
radar Dec 17, 2013
ea6c242
Syntax highlighting makes everything better
radar Dec 17, 2013
a789bd9
It's :recursive, not :restore
radar Dec 18, 2013
113c8f4
Revert behaviour of calling destroy twice deleting records
radar Jan 3, 2014
9680034
update README for #92
radar Jan 3, 2014
2fc1a01
Support Ruby 2.1.0
radar Jan 3, 2014
b5df36e
Fix some syntax errors in README.md
GRoguelon Jan 3, 2014
f4689a3
Merge pull request #97 from GRoguelon/master
radar Jan 6, 2014
2ce98a2
Update README.md
TigerWolf Jan 10, 2014
ce77089
Update README.md
TigerWolf Jan 10, 2014
1156052
Merge pull request #99 from TigerWolf/patch-1
radar Jan 10, 2014
d6653bb
Bump to 1.3.3
radar Jan 16, 2014
d2ac658
Update README.md, clarifying behaviour of acts_as_paranoid call.
TigerWolf Jan 15, 2014
79da3a4
Fix destroy return value.
kouno Jan 25, 2014
4a41dda
Update README
davidpiegza Feb 1, 2014
16cb49d
Merge pull request #105 from davidpiegza/master
radar Feb 6, 2014
e0f693d
Use really_destroy! for really destroying things
radar Feb 6, 2014
dfd6eb0
Use rails3 branch instead of 'master'
radar Feb 6, 2014
8151fc8
Add index to deleted_at column in README
rvanlieshout Feb 13, 2014
ad84169
Merge pull request #113 from rvanlieshout/rails3
radar Feb 17, 2014
acbc916
Regression tests and full fix for #118
pobocks Mar 7, 2014
d8c9ce4
Merge pull request #119 from pobocks/issue_118_fix
radar Mar 11, 2014
c8cfa18
Explicitly load AR unless already loaded
andrewslotin Mar 17, 2014
2301d5e
Add rspec matcher: act_as_paranoid
Mar 18, 2014
bbfac32
really_destroy! will now really destroy dependent = :destroy associat…
radar Apr 8, 2014
d25cae9
Use an unscoped call on associations within really_destroy to REALLY …
radar Apr 8, 2014
07028f1
Revert "Use an unscoped call on associations within really_destroy to…
radar Apr 8, 2014
7e9b1e8
Revert "Revert "Use an unscoped call on associations within really_de…
radar Apr 8, 2014
9a305b2
Really only destroy associated records
radar Apr 8, 2014
72bc7c0
Mention latest changes to really_destroy in the readme
radar Apr 8, 2014
dabef4b
Adds #really_destroyed? method as a fallback to default rails #destro…
yratanov Apr 11, 2014
b7714ec
Merge pull request #128 from yratanov/really_destroyed
radar May 5, 2014
ad3e711
Update paranoia_test.rb
mjording Jun 13, 2014
b1ec37e
Rails 3.1 is fine
tamird Jun 23, 2014
48c6c90
Replace deprecated RSpec failure_message_for_should syntax
lime Aug 12, 2014
08e3743
Rephrase matcher failure messages according to RSpec 3 style
lime Aug 12, 2014
16027f7
Retain compatibility with RSpec 2 matchers
lime Aug 12, 2014
68794fd
Bump to 1.3.4
Jan 19, 2015
11171c7
add failing test that shows Paranoia not working with validates_uniqu…
codeodor Mar 12, 2014
971a6cd
Ensure uniqueness validation is scoped by deleted_at
codeodor Mar 16, 2014
4a4497e
Add test/unit as a dev dependency
codeodor Jun 18, 2015
926c4ff
Merge pull request #122 from codeodor/rails3
radar Jun 20, 2015
48a7137
Fix "normal" validates_uniqueness_of after #122 broke it
codeodor Jun 21, 2015
0f69a0d
Merge pull request #246 from codeodor/rails3
radar Jun 22, 2015
fa68929
Fix restore to be scoped and add callbacks for real destroys
Nov 9, 2015
070f4c3
Merge pull request #1 from OfficeSpace/fix_restore_and_add_really_des…
ikokli Nov 9, 2015
0ba5ff0
Fix for collections and if relation isnt paranoid
Nov 10, 2015
98c6cfb
Zai commit: restore now updates timestamps
Jun 11, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
language: ruby
rvm:
- 1.9.3
- 2.0.0
- 2.1.0
- jruby-19mode
- rbx
11 changes: 10 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
source :gemcutter
source 'https://rubygems.org'

gem 'sqlite3', :platforms => [:ruby]
gem 'activerecord-jdbcsqlite3-adapter', :platforms => [:jruby]

platforms :rbx do
gem 'rubysl', '~> 2.0'
gem 'rubysl-test-unit'
gem 'rubinius-developer_tools'
end

# Specify your gem's dependencies in paranoia.gemspec
gemspec
107 changes: 102 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,30 @@ Paranoia is a re-implementation of [acts\_as\_paranoid](http://github.com/techno

You would use either plugin / gem if you wished that when you called `destroy` on an Active Record object that it didn't actually destroy it, but just "hid" the record. Paranoia does this by setting a `deleted_at` field to the current time when you `destroy` a record, and hides it by scoping all queries on your model to only include records which do not have a `deleted_at` field.

If you wish to actually destroy an object you may call `really_destroy!`. **WARNING**: This will also *really destroy* all `dependent: destroy` records, so please aim this method away from face when using.**

If a record has `has_many` associations defined AND those associations have `dependent: :destroy` set on them, then they will also be soft-deleted if ``acts_as_paranoid`` is set, otherwise the normal destroy will be called.

## Installation & Usage

Put this in your Gemfile:
For Rails 3, please use version 1 of Paranoia:

```ruby
gem 'paranoia', '~> 1.0'
```

For Rails 4, please use version 2 of Paranoia:

```ruby
gem 'paranoia', '~> 2.0'
```

Of course you can install this from GitHub as well:

```ruby
gem 'paranoia'
gem 'paranoia', :github => 'radar/paranoia', :branch => 'rails3'
# or
gem 'paranoia', :github => 'radar/paranoia', :branch => 'rails4'
```

Then run:
Expand All @@ -25,7 +43,7 @@ Updating is as simple as `bundle update paranoia`.
Run:

```shell
rails generate migration AddDeletedAtToClients deleted_at:datetime
rails generate migration AddDeletedAtToClients deleted_at:datetime:index
```

and now you have a migration
Expand All @@ -34,6 +52,7 @@ and now you have a migration
class AddDeletedAtToClients < ActiveRecord::Migration
def change
add_column :clients, :deleted_at, :datetime
add_index :clients, :deleted_at
end
end
```
Expand All @@ -50,9 +69,23 @@ class Client < ActiveRecord::Base
end
```

Hey presto, it's there!
Hey presto, it's there! Calling `destroy` will now set the `deleted_at` column:


```
>> client.deleted_at => nil
>> client.destroy => client
>> client.deleted_at => [current timestamp]
```

If you want a method to be called on destroy, simply provide a _before\_destroy_ callback:
If you really want it gone *gone*, call `destroy!`

```
>> client.deleted_at => nil
>> client.destroy! => client
```

If you want a method to be called on destroy, simply provide a `before_destroy` callback:

```ruby
class Client < ActiveRecord::Base
Expand All @@ -68,6 +101,70 @@ class Client < ActiveRecord::Base
end
```

If you want to use a column other than `deleted_at`, you can pass it as an option:

```ruby
class Client < ActiveRecord::Base
acts_as_paranoid column: :destroyed_at

...
end
```

If you want to access soft-deleted associations, override the getter method:

```ruby
def product
Product.unscoped { super }
end
```

If you want to find all records, even those which are deleted:

```ruby
Client.with_deleted
```

If you want to find only the deleted records:

```ruby
Client.only_deleted
```

If you want to check if a record is soft-deleted:

```ruby
client.destroyed?
```

If you want to restore a record:

```ruby
Client.restore(id)
```

If you want to restore a whole bunch of records:

```ruby
Client.restore([id1, id2, ..., idN])
```

If you want to restore a record and their dependently destroyed associated records:

```ruby
Client.restore(id, :recursive => true)
```

If you want callbacks to trigger before a restore:

```ruby
before_restore :callback_name_goes_here
```

For more information, please look at the tests.

## Acts As Paranoid Migration

You can replace the older acts_as_paranoid methods as follows:

| Old Syntax | New Syntax |
Expand Down
Loading