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 +4 -4
- data/README.md +4 -1
- data/lib/kakurenbo.rb +16 -0
- data/lib/kakurenbo/core.rb +2 -2
- data/lib/kakurenbo/mixin_ar_base.rb +1 -1
- data/lib/kakurenbo/mixin_ar_callbacks.rb +13 -0
- data/lib/kakurenbo/mixin_ar_locking_optimistic.rb +19 -0
- data/lib/kakurenbo/mixin_ar_persistence.rb +22 -0
- data/lib/kakurenbo/mixin_ar_transactions.rb +12 -0
- data/lib/kakurenbo/version.rb +1 -1
- data/spec/kakurenbo/cores/associations_spec.rb +14 -0
- metadata +7 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e3aad6eafcf62a9e7ba09812cbac52dc20363462
|
4
|
+
data.tar.gz: 849e24be08990b146d1a0099245adff73f996016
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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'
|
data/lib/kakurenbo.rb
CHANGED
@@ -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
|
data/lib/kakurenbo/core.rb
CHANGED
@@ -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,
|
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,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
|
data/lib/kakurenbo/version.rb
CHANGED
@@ -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.
|
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:
|
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.
|
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
|