rails_soft_deletable 0.2.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- MjQyMzFlNDJkNjk3MDYyN2M4ODBkYTllOWUxOWI1MDg2YWU1OGZlYw==
4
+ YzMzYzk5MzBhMWI5OTM3ZjI4MGNmNWY2M2YzNTNlNjI1ZjMwMTZlMQ==
5
5
  data.tar.gz: !binary |-
6
- Y2RlYzY3YTNmYjA4ZjQ0ZTc4MTFkZWY1NzNjYWE2MmEyMWEzYThmNg==
6
+ Y2EyOTgzYmQ5ZmQ0OGE0MTA4MDQxMWY4YWRlMTMzODBhMGEwYTk3MA==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- YjVlYTJkN2EyNzk4MTY4ZTNkMjFlYmJkYWQ5Y2I5NzNhNmFkZTQ1NjdhZjNj
10
- NGQ2ODM5MzNlMzc2OTRkNzg1ZGVhNDlhYjJkMzFmODg1NTM0YWQzYWJiOTgz
11
- ZmJmMTgwOWJlY2E3YzJjMDQ2MTY2Y2EwYzYzMmEyYjYzZDIyOWM=
9
+ YWNiN2EyMWY0YTNlZTZjYzgwMTkzZDYxMTgwODIxODY2MmFmZGVjNjRmNTYx
10
+ YTdiZDRlZjllNWFiZmY2NzA2NDAzZmJkMDZmNWIxZjg4MDUyMDYxNzhkNjFl
11
+ ZDRiZGRkZjAwODcyYTlhN2Y1ZDAwMjM5MmMyY2RmNmJhY2VlMzM=
12
12
  data.tar.gz: !binary |-
13
- OGRmYjE0MWQxYjBkODcxMGYxYjU0ZWM1YmY5MjA5YmRhMmQ4MmE1YWE1MTdj
14
- NDU1NGMxODk0NTAxZDYyNTlhZWUwYjRjNTRhYTYwZDk1NmI0MDI3MzQzNzZj
15
- YzA3ZTg5ZTUxYjM1ZDRlZTc5Y2RiNGExZGIyMTRhYmQ5YWNlYzM=
13
+ NDAzZjUxODlkMzBjMDEwOTMzZmIzZjY3YTlhODdjYjA2NTQwOTZjYWM4ZmQ0
14
+ ZWY0NjgyYjRhNjA5MWE2YmM2ODQzOWQ5NTM5MDk3NzAwMjU3ZDJiOTJiM2Nh
15
+ ODdjYWQzNjAzOTAyMTM5YWMyZjM5MTUyOGYzY2UwODNmMjJiYWY=
@@ -7,16 +7,16 @@ module RailsSoftDeletable
7
7
  included do
8
8
  define_callbacks :restore
9
9
 
10
- define_singleton_method("before_restore") do |*args, &block|
11
- set_callback(:restore, :before, *args, &block)
10
+ define_singleton_method("before_restore") do |*args, block|
11
+ set_callback(:restore, :before, *args, block)
12
12
  end
13
13
 
14
- define_singleton_method("around_restore") do |*args, &block|
15
- set_callback(:restore, :around, *args, &block)
14
+ define_singleton_method("around_restore") do |*args, block|
15
+ set_callback(:restore, :around, *args, block)
16
16
  end
17
17
 
18
- define_singleton_method("after_restore") do |*args, &block|
19
- set_callback(:restore, :after, *args, &block)
18
+ define_singleton_method("after_restore") do |*args, block|
19
+ set_callback(:restore, :after, *args, block)
20
20
  end
21
21
  end
22
22
 
@@ -54,7 +54,7 @@ module RailsSoftDeletable
54
54
  # update_column(soft_deletable_column, 0)
55
55
 
56
56
  name = soft_deletable_column.to_s
57
- updated_count = self.class.unscoped.where(self.class.primary_key => id).update_all(name => 0 )
57
+ updated_count = self.class.unscoped.where(self.class.primary_key => id).update_all(name => 0)
58
58
  raw_write_attribute(name, 0)
59
59
 
60
60
  updated_count == 1
@@ -10,7 +10,9 @@ module RailsSoftDeletable
10
10
  end
11
11
 
12
12
  def with_deleted
13
- if ::ActiveRecord::VERSION::STRING >= "4.0"
13
+ if ::ActiveRecord::VERSION::STRING >= "4.1"
14
+ self.unscope(where: soft_deletable_column).all
15
+ elsif ::ActiveRecord::VERSION::STRING >= "4.0"
14
16
  all.tap { |x| x.default_scoped = false }
15
17
  else
16
18
  scoped.tap { |x| x.default_scoped = false }
@@ -23,7 +23,7 @@ module RailsSoftDeletable
23
23
  class_attribute :soft_deletable_column
24
24
 
25
25
  self.soft_deletable_column = options[:column] || :deleted_at
26
- default_scope { where(self.quoted_table_name + ".#{soft_deletable_column} = 0") }
26
+ default_scope { where(soft_deletable_column => 0) }
27
27
  end
28
28
 
29
29
  def soft_deletable?
@@ -1,3 +1,3 @@
1
1
  module RailsSoftDeletable
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.1"
3
3
  end
@@ -4,4 +4,6 @@ class DecimalModel < ActiveRecord::Base
4
4
  soft_deletable
5
5
 
6
6
  include SoftDeletableModelCallbacks
7
+
8
+ belongs_to :integer_model
7
9
  end
@@ -4,4 +4,7 @@ class IntegerModel < ActiveRecord::Base
4
4
  soft_deletable
5
5
 
6
6
  include SoftDeletableModelCallbacks
7
+
8
+ has_many :decimal_models
9
+ has_many :decimal_models_with_deleted, -> { unscope where: :deleted_at }, class_name: "DecimalModel"
7
10
  end
Binary file
File without changes