Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
paranoia
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ikcrm_common
paranoia
Commits
c98ad454
Commit
c98ad454
authored
Nov 01, 2017
by
John Hawthorn
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use define_model_callbacks
parent
ea0a0cee
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
2 additions
and
21 deletions
+2
-21
lib/paranoia.rb
+2
-21
No files found.
lib/paranoia.rb
View file @
c98ad454
...
...
@@ -14,7 +14,6 @@ module Paranoia
def
self
.
included
(
klazz
)
klazz
.
extend
Query
klazz
.
extend
Callbacks
end
module
Query
...
...
@@ -53,26 +52,6 @@ module Paranoia
end
end
module
Callbacks
def
self
.
extended
(
klazz
)
[
:restore
,
:real_destroy
].
each
do
|
callback_name
|
klazz
.
define_callbacks
callback_name
klazz
.
define_singleton_method
(
"before_
#{
callback_name
}
"
)
do
|*
args
,
&
block
|
set_callback
(
callback_name
,
:before
,
*
args
,
&
block
)
end
klazz
.
define_singleton_method
(
"around_
#{
callback_name
}
"
)
do
|*
args
,
&
block
|
set_callback
(
callback_name
,
:around
,
*
args
,
&
block
)
end
klazz
.
define_singleton_method
(
"after_
#{
callback_name
}
"
)
do
|*
args
,
&
block
|
set_callback
(
callback_name
,
:after
,
*
args
,
&
block
)
end
end
end
end
def
destroy
transaction
do
run_callbacks
(
:destroy
)
do
...
...
@@ -241,6 +220,8 @@ end
ActiveSupport
.
on_load
(
:active_record
)
do
class
ActiveRecord
::
Base
def
self
.
acts_as_paranoid
(
options
=
{})
define_model_callbacks
:restore
,
:real_destroy
alias_method
:really_destroyed?
,
:destroyed?
alias_method
:really_delete
,
:delete
alias_method
:destroy_without_paranoia
,
:destroy
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment