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
6972b229
Commit
6972b229
authored
8 years ago
by
Ben A. Morgan
Committed by
GitHub
8 years ago
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #371 from iaankrynauw/core
Use ActiveSupport.on_load to correctly re-open ActiveRecord::Base
parents
b5b38231
49b9e68e
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
40 additions
and
38 deletions
+40
-38
lib/paranoia.rb
+40
-38
No files found.
lib/paranoia.rb
View file @
6972b229
...
@@ -205,56 +205,58 @@ module Paranoia
...
@@ -205,56 +205,58 @@ module Paranoia
end
end
end
end
class
ActiveRecord
::
Base
ActiveSupport
.
on_load
(
:active_record
)
do
def
self
.
acts_as_paranoid
(
options
=
{})
class
ActiveRecord
::
Base
alias_method
:really_destroyed?
,
:destroyed?
def
self
.
acts_as_paranoid
(
options
=
{})
alias_method
:really_delete
,
:delete
alias_method
:really_destroyed?
,
:destroyed?
alias_method
:destroy_without_paranoia
,
:destroy
alias_method
:really_delete
,
:delete
alias_method
:destroy_without_paranoia
,
:destroy
include
Paranoia
class_attribute
:paranoia_column
,
:paranoia_sentinel_value
include
Paranoia
class_attribute
:paranoia_column
,
:paranoia_sentinel_value
self
.
paranoia_column
=
(
options
[
:column
]
||
:deleted_at
).
to_s
self
.
paranoia_sentinel_value
=
options
.
fetch
(
:sentinel_value
)
{
Paranoia
.
default_sentinel_value
}
self
.
paranoia_column
=
(
options
[
:column
]
||
:deleted_at
).
to_s
def
self
.
paranoia_scope
self
.
paranoia_sentinel_value
=
options
.
fetch
(
:sentinel_value
)
{
Paranoia
.
default_sentinel_value
}
where
(
paranoia_column
=>
paranoia_sentinel_value
)
def
self
.
paranoia_scope
end
where
(
paranoia_column
=>
paranoia_sentinel_value
)
class
<<
self
;
alias_method
:without_deleted
,
:paranoia_scope
end
end
class
<<
self
;
alias_method
:without_deleted
,
:paranoia_scope
end
unless
options
[
:without_default_scope
]
unless
options
[
:without_default_scope
]
default_scope
{
paranoia_scope
}
default_scope
{
paranoia_scope
}
end
end
before_restore
{
before_restore
{
self
.
class
.
notify_observers
(
:before_restore
,
self
)
if
self
.
class
.
respond_to?
(
:notify_observers
)
self
.
class
.
notify_observers
(
:before_restore
,
self
)
if
self
.
class
.
respond_to?
(
:notify_observers
)
}
}
after_restore
{
after_restore
{
self
.
class
.
notify_observers
(
:after_restore
,
self
)
if
self
.
class
.
respond_to?
(
:notify_observers
)
self
.
class
.
notify_observers
(
:after_restore
,
self
)
if
self
.
class
.
respond_to?
(
:notify_observers
)
}
}
end
end
# Please do not use this method in production.
# Please do not use this method in production.
# Pretty please.
# Pretty please.
def
self
.
I_AM_THE_DESTROYER!
def
self
.
I_AM_THE_DESTROYER!
# TODO: actually implement spelling error fixes
# TODO: actually implement spelling error fixes
puts
%Q{
puts
%Q{
Sharon: "There should be a method called I_AM_THE_DESTROYER!"
Sharon: "There should be a method called I_AM_THE_DESTROYER!"
Ryan: "What should this method do?"
Ryan: "What should this method do?"
Sharon: "It should fix all the spelling errors on the page!"
Sharon: "It should fix all the spelling errors on the page!"
}
}
end
end
def
self
.
paranoid?
;
false
;
end
def
self
.
paranoid?
;
false
;
end
def
paranoid?
;
self
.
class
.
paranoid?
;
end
def
paranoid?
;
self
.
class
.
paranoid?
;
end
private
private
def
paranoia_column
def
paranoia_column
self
.
class
.
paranoia_column
self
.
class
.
paranoia_column
end
end
def
paranoia_sentinel_value
def
paranoia_sentinel_value
self
.
class
.
paranoia_sentinel_value
self
.
class
.
paranoia_sentinel_value
end
end
end
end
end
...
...
This diff is collapsed.
Click to expand it.
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