kakurenbo 0.2.2 → 0.2.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 788780b9941834c2ade270af22ea73d5d25d2e18
4
- data.tar.gz: 95a5300b26356040d8dac00be9431da7a6826480
3
+ metadata.gz: e3aad6eafcf62a9e7ba09812cbac52dc20363462
4
+ data.tar.gz: 849e24be08990b146d1a0099245adff73f996016
5
5
  SHA512:
6
- metadata.gz: 2be387caf4f5b04a6431e01a6cc62de14dfc884473d255efae57c0fe515ac392f4806ee639011e18d51afef655d544c44c1d015ff1c350e3f3f13ca2f5a3f03a
7
- data.tar.gz: bb6a270e83ce04f00b83056d7fdd4b8381773000eaa01d91c9674cefeb757ec4ec6ea35739b3ef744c24eb2484b91d5ca308d1ca075878d886e0a225d4e98f62
6
+ metadata.gz: c0f5d787f66cbd5c0a2da245b272533a76d93da7b56f4d8b4f24ce9a3401a35e842fb71e222cd07c17332d9d634c3eaa828ee5861373349de374f073c1eba72a
7
+ data.tar.gz: c99b96ca9429ca968895568383534d6723b0fb39908f21cc2151f7d76eeeb229ab367d5b1f807e6da7b87f34ac2e227be769d160e6424b9494cdedf7ee2f61ba
data/README.md CHANGED
@@ -6,9 +6,12 @@ Kakurenbo is a re-implementation of [paranoia](http://github.com/radar/paranoia)
6
6
  The usage of the Kakurenbo is very very very simple. Only add `deleted_at`(datetime) to column.
7
7
  Of course you can use `acts_as_paranoid`.In addition, Kakurenbo has many advantageous.
8
8
 
9
+ # Warning
10
+ ### kakurenbo is deprecated if you use in a new rails project!
11
+ ### You should use [kakurenbo-puti](http://github.com/alfa-jpn/kakurenbo-puti)!
9
12
 
10
- # Installation
11
13
 
14
+ # Installation
12
15
 
13
16
  ```ruby
14
17
  gem 'kakurenbo'
@@ -7,6 +7,10 @@ require "kakurenbo/version"
7
7
  require "kakurenbo/mixin_ar_base"
8
8
  require "kakurenbo/mixin_ar_associations"
9
9
  require "kakurenbo/mixin_ar_relation"
10
+ require "kakurenbo/mixin_ar_transactions"
11
+ require "kakurenbo/mixin_ar_callbacks"
12
+ require "kakurenbo/mixin_ar_persistence"
13
+ require "kakurenbo/mixin_ar_locking_optimistic"
10
14
  require "kakurenbo/core"
11
15
 
12
16
  # Kakurenbo Add ActiveRecord::RecordNotRestored to ActiveRecord
@@ -20,3 +24,15 @@ ActiveRecord::Relation.send :include, Kakurenbo::MixinARRelation
20
24
 
21
25
  # Kakurenbo Mixin to ActiveRecord::Associations
22
26
  ActiveRecord::Associations::Association.send :include, Kakurenbo::MixinARAssociations::Association
27
+
28
+ # Kakurenbo Mixin to ActiveRecord::Transaction
29
+ ActiveRecord::Transactions.send :include, Kakurenbo::MixinARTransactions
30
+
31
+ # Kakurenbo Mixin to ActiveRecord::Callbacks
32
+ ActiveRecord::Callbacks.send :include, Kakurenbo::MixinARCallbacks
33
+
34
+ # Kakurenbo Mixin to ActiveRecord::Persistence
35
+ ActiveRecord::Persistence.send :include, Kakurenbo::MixinARPersistence
36
+
37
+ # Kakurenbo Mixin to ActiveRecord::Locking::Optimistic
38
+ ActiveRecord::Locking::Optimistic.send :include, Kakurenbo::MixinARLockingOptimistic
@@ -94,8 +94,8 @@ module Kakurenbo
94
94
  destroy(options) || raise(ActiveRecord::RecordNotDestroyed)
95
95
  end
96
96
 
97
- def destroy_row
98
- relation_for_destroy.delete_all(nil, :hard => true)
97
+ def destroy_row(options = {:hard => true})
98
+ relation_for_destroy.delete_all(nil, options)
99
99
  end
100
100
 
101
101
  def destroyed?
@@ -25,7 +25,7 @@ module Kakurenbo
25
25
  remodel_as_soft_delete if has_kakurenbo_column?
26
26
 
27
27
  # Reset @table name, because ActiveRecord doesn't expect initialized at here.
28
- remove_instance_variable(:@table_name)
28
+ remove_instance_variable(:@table_name) if instance_variable_defined? :@table_name
29
29
  end
30
30
  end
31
31
 
@@ -0,0 +1,13 @@
1
+ module Kakurenbo
2
+ module MixinARCallbacks
3
+ # Override methods.
4
+ def self.included(base_class)
5
+ base_class.class_eval do
6
+ def destroy(options = {:hard => false})
7
+ run_callbacks(:destroy) { super(options) }
8
+ end
9
+ end
10
+ end
11
+ end
12
+ end
13
+
@@ -0,0 +1,19 @@
1
+ module Kakurenbo
2
+ module MixinARLockingOptimistic
3
+ # Override methods.
4
+ def self.included(base_class)
5
+ base_class.class_eval do
6
+ def destroy_row(options = {:hard => false})
7
+ affected_rows = super(options)
8
+
9
+ if locking_enabled? && affected_rows != 1
10
+ raise ActiveRecord::StaleObjectError.new(self, "destroy")
11
+ end
12
+
13
+ affected_rows
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
19
+
@@ -0,0 +1,22 @@
1
+ module Kakurenbo
2
+ module MixinARPersistence
3
+ # Override methods.
4
+ def self.included(base_class)
5
+ base_class.class_eval do
6
+ def destroy(options = {:hard => false})
7
+ raise ReadOnlyRecord if readonly?
8
+ destroy_associations
9
+ #destroy_row(options) if persisted?
10
+ destroy_row if persisted?
11
+ @destroyed = true
12
+ freeze
13
+ end
14
+
15
+ private
16
+ def destroy_row(options = {:hard => false})
17
+ relation_for_destroy.delete_all(nil, options)
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,12 @@
1
+ module Kakurenbo
2
+ module MixinARTransactions
3
+ # Override methods.
4
+ def self.included(base_class)
5
+ base_class.class_eval do
6
+ def destroy(options = {:hard => false})
7
+ with_transaction_returning_status { super(options) }
8
+ end
9
+ end
10
+ end
11
+ end
12
+ end
@@ -1,3 +1,3 @@
1
1
  module Kakurenbo
2
- VERSION = "0.2.2"
2
+ VERSION = "0.2.3"
3
3
  end
@@ -32,6 +32,10 @@ describe Kakurenbo::Core do
32
32
  expect { parent.restore! }.not_to change(child_class, :count)
33
33
  end
34
34
 
35
+ subject :subject_destroy_child_with_where do
36
+ expect { destroy_child_with_where }.to change(child_class, :count).by(2)
37
+ end
38
+
35
39
  let :create_unrelated_children do
36
40
  [
37
41
  child_class.create!,
@@ -43,6 +47,10 @@ describe Kakurenbo::Core do
43
47
  children.each {|child| child.destroy!}
44
48
  end
45
49
 
50
+ let :destroy_child_with_where do
51
+ parent.normal_child_models.where(id: children.first.id).destroy_all
52
+ end
53
+
46
54
  let :parent do
47
55
  parent_class.create!
48
56
  end
@@ -75,6 +83,12 @@ describe Kakurenbo::Core do
75
83
  subject_soft_delete
76
84
  end
77
85
  end
86
+
87
+ context 'when child is deleted by destroy_all with where,' do
88
+ it 'child will be delete.' do
89
+ subject_destroy_child_with_where
90
+ end
91
+ end
78
92
  end
79
93
 
80
94
  describe 'ParanoidChildModel(has_many)' do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kakurenbo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - alfa-jpn
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-08-17 00:00:00.000000000 Z
11
+ date: 2015-02-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -118,7 +118,11 @@ files:
118
118
  - lib/kakurenbo/core.rb
119
119
  - lib/kakurenbo/mixin_ar_associations.rb
120
120
  - lib/kakurenbo/mixin_ar_base.rb
121
+ - lib/kakurenbo/mixin_ar_callbacks.rb
122
+ - lib/kakurenbo/mixin_ar_locking_optimistic.rb
123
+ - lib/kakurenbo/mixin_ar_persistence.rb
121
124
  - lib/kakurenbo/mixin_ar_relation.rb
125
+ - lib/kakurenbo/mixin_ar_transactions.rb
122
126
  - lib/kakurenbo/version.rb
123
127
  - spec/kakurenbo/cores/associations_spec.rb
124
128
  - spec/kakurenbo/cores/callbacks_spec.rb
@@ -148,7 +152,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
148
152
  version: '0'
149
153
  requirements: []
150
154
  rubyforge_project:
151
- rubygems_version: 2.2.2
155
+ rubygems_version: 2.4.5
152
156
  signing_key:
153
157
  specification_version: 4
154
158
  summary: provides soft delete. Kakurenbo is a re-implementation of paranoia and acts_as_paranoid