Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
  • 2 commits
  • 3 files changed
  • 0 comments
  • 1 contributor
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 3 changed files with 24 additions and 22 deletions. Show diff stats Hide diff stats

  1. +2 1  .gitignore
  2. +20 19 lib/class_methods.rb
  3. +2 2 lib/delete_softly.rb
3  .gitignore
... ... @@ -1,4 +1,5 @@
1 1 pkg
2 2 doc
3 3 test/db.sqlite3
4   -*.gem
  4 +*.gem
  5 +\.idea
39 lib/class_methods.rb
@@ -21,25 +21,26 @@ def without_deleted
21 21 # end
22 22 # 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"
23 23 # IHaveManyItems.first.items.with_deleted #=> SELECT "items".* FROM "items" WHERE ("items".i_have_many_items_id = 1) ORDER BY "items"."content"
24   - def with_deleted(&block)
25   - if scoped_methods.any? # There are scoped methods in place
26   -
27   - # remove deleted at condition if present
28   - del = scoped_methods.last.where_values.delete(:deleted_at => nil)
29   -
30   - # Execute block with deleted or just run scoped
31   - r = block_given? ? yield : scoped
32   -
33   - # Add deleted condition if it was present
34   - scoped_methods.last.where_values << del if del
35   -
36   - # Return de relation generated without deleted_at => nil
37   - r
38   - else
39   - # Do not do anything special when there are no scoped_methods
40   - r = block_given? ? yield : scoped
41   - end
42   - end
  24 + # 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.
  25 + #def with_deleted(&block)
  26 + # if scoped_methods.any? # There are scoped methods in place
  27 + #
  28 + # # remove deleted at condition if present
  29 + # del = scoped_methods.last.where_values.delete(:deleted_at => nil)
  30 + #
  31 + # # Execute block with deleted or just run scoped
  32 + # r = block_given? ? yield : scoped
  33 + #
  34 + # # Add deleted condition if it was present
  35 + # scoped_methods.last.where_values << del if del
  36 + #
  37 + # # Return de relation generated without deleted_at => nil
  38 + # r
  39 + # else
  40 + # # Do not do anything special when there are no scoped_methods
  41 + # r = block_given? ? yield : scoped
  42 + # end
  43 + #end
43 44
44 45 def deleted
45 46 with_deleted.where("deleted_at is not null")
4 lib/delete_softly.rb
@@ -47,8 +47,8 @@ def active
47 47 # class Post < ActiveRecord::Base
48 48 # delete_softly :enforce => false
49 49 # end
50   - # An object will still be available after destroy is called,
51   - def delete_softly(options = {:enforce => :active})
  50 + # An object will still be available after destroy is called.
  51 + def delete_softly(options = {:enforce => :without_deleted})
52 52 # Make destroy! the old destroy
53 53 alias_method :destroy!, :destroy
54 54

No commit comments for this range

Something went wrong with that request. Please try again.