Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

We’re showing branches in this repository, but you can also compare across forks.

base fork: coroutine/delete_softly
base: c9f079c917
...
head fork: coroutine/delete_softly
compare: f852328367
  • 2 commits
  • 3 files changed
  • 0 commit comments
  • 1 contributor
Commits on Apr 23, 2012
mirelabk mirelabk Changing the gem to make it work with rails 3.2. Passing without_dele…
…ted as a default parameter to the delete_softly method. Also commenting out with_deleted method as ti was using some ActiveRecord::Base private methods that do not exist any more. We should be using unscoped method to remove all the scoped to achieve the same behavior.
e3ac06a
mirelabk mirelabk Updating .gitignore file f852328
Showing with 24 additions and 22 deletions.
  1. +2 −1  .gitignore
  2. +20 −19 lib/class_methods.rb
  3. +2 −2 lib/delete_softly.rb
3  .gitignore
View
@@ -1,4 +1,5 @@
pkg
doc
test/db.sqlite3
-*.gem
+*.gem
+\.idea
39 lib/class_methods.rb
View
@@ -21,25 +21,26 @@ def without_deleted
# end
# IHaveManyItems.first.items #=> SELECT "items".* FROM "items" WHERE ("items"."deleted_at" IS NULL) AND ("items".i_have_many_items_id = 1) ORDER BY "items"."content"
# IHaveManyItems.first.items.with_deleted #=> SELECT "items".* FROM "items" WHERE ("items".i_have_many_items_id = 1) ORDER BY "items"."content"
- def with_deleted(&block)
- if scoped_methods.any? # There are scoped methods in place
-
- # remove deleted at condition if present
- del = scoped_methods.last.where_values.delete(:deleted_at => nil)
-
- # Execute block with deleted or just run scoped
- r = block_given? ? yield : scoped
-
- # Add deleted condition if it was present
- scoped_methods.last.where_values << del if del
-
- # Return de relation generated without deleted_at => nil
- r
- else
- # Do not do anything special when there are no scoped_methods
- r = block_given? ? yield : scoped
- end
- end
+ # For rails 3.2 method is being commented out as it uses private methods that have been removed from the 3.2. To achieve the same behavior, unscoped method should be used.
+ #def with_deleted(&block)
+ # if scoped_methods.any? # There are scoped methods in place
+ #
+ # # remove deleted at condition if present
+ # del = scoped_methods.last.where_values.delete(:deleted_at => nil)
+ #
+ # # Execute block with deleted or just run scoped
+ # r = block_given? ? yield : scoped
+ #
+ # # Add deleted condition if it was present
+ # scoped_methods.last.where_values << del if del
+ #
+ # # Return de relation generated without deleted_at => nil
+ # r
+ # else
+ # # Do not do anything special when there are no scoped_methods
+ # r = block_given? ? yield : scoped
+ # end
+ #end
def deleted
with_deleted.where("deleted_at is not null")
4 lib/delete_softly.rb
View
@@ -47,8 +47,8 @@ def active
# class Post < ActiveRecord::Base
# delete_softly :enforce => false
# end
- # An object will still be available after destroy is called,
- def delete_softly(options = {:enforce => :active})
+ # An object will still be available after destroy is called.
+ def delete_softly(options = {:enforce => :without_deleted})
# Make destroy! the old destroy
alias_method :destroy!, :destroy

No commit comments for this range

Something went wrong with that request. Please try again.