batch_dependent_associations 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +15 -0
- data/lib/batch_dependent_associations.rb +10 -2
- data/lib/batch_dependent_associations/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 87f35494445fa7a274135a13b16c8147fd92d892
|
4
|
+
data.tar.gz: 42dbd8a1d923f5427072133f0707c468faa26936
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 256a1f97d10bda6ab367d0dbee8d5a31cce8eaa7ca6a78a468b159a902604dac4b7ec90b41677ff55f993ae7864f07e47c826acc4e7010cc75d6456d62440eba
|
7
|
+
data.tar.gz: bbaa0bb523b2759d756424319fc00cd46d0b07dfeaab3cbd197a1e33ecde1fcc08af08916b613b545731d1dc73ccb767e5bef11c01aec6bf7e4dc8eef0f54615
|
data/README.md
CHANGED
@@ -2,6 +2,8 @@
|
|
2
2
|
|
3
3
|
#### Use dependent associations with Rails safely, with automatic batching.
|
4
4
|
|
5
|
+
*You are viewing the README of version [v0.2.0](https://github.com/thisismydesign/batch_dependent_associations/releases/tag/v0.2.0). You can find other releases [here](https://github.com/thisismydesign/batch_dependent_associations/releases).*
|
6
|
+
|
5
7
|
| Branch | Status |
|
6
8
|
| ------ | ------ |
|
7
9
|
| Release | [![Build Status](https://travis-ci.org/thisismydesign/batch_dependent_associations.svg?branch=release)](https://travis-ci.org/thisismydesign/batch_dependent_associations) [![Coverage Status](https://coveralls.io/repos/github/thisismydesign/batch_dependent_associations/badge.svg?branch=release)](https://coveralls.io/github/thisismydesign/batch_dependent_associations?branch=release) [![Gem Version](https://badge.fury.io/rb/batch_dependent_associations.svg)](https://badge.fury.io/rb/batch_dependent_associations) [![Total Downloads](http://ruby-gem-downloads-badge.herokuapp.com/batch_dependent_associations?type=total)](https://rubygems.org/gems/batch_dependent_associations) |
|
@@ -56,6 +58,19 @@ class SafePerson < ActiveRecord::Base
|
|
56
58
|
end
|
57
59
|
```
|
58
60
|
|
61
|
+
### Custom batch size
|
62
|
+
|
63
|
+
Since [v0.2.0](https://github.com/thisismydesign/batch_dependent_associations/releases/tag/v0.2.0)
|
64
|
+
|
65
|
+
Can be set via the `dependent_associations_batch_size` class variable. Default is `1000` (same as Rails default).
|
66
|
+
|
67
|
+
```ruby
|
68
|
+
class SafePerson < ActiveRecord::Base
|
69
|
+
include BatchDependentAssociations
|
70
|
+
self.dependent_associations_batch_size = 500
|
71
|
+
end
|
72
|
+
```
|
73
|
+
|
59
74
|
## Development
|
60
75
|
|
61
76
|
```bash
|
@@ -10,12 +10,20 @@ module BatchDependentAssociations
|
|
10
10
|
before_destroy :batch_dependent_associations, prepend: true
|
11
11
|
end
|
12
12
|
|
13
|
+
module ClassMethods
|
14
|
+
attr_writer :dependent_associations_batch_size
|
15
|
+
|
16
|
+
def dependent_associations_batch_size
|
17
|
+
@dependent_associations_batch_size || 1000
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
13
21
|
private
|
14
22
|
|
15
23
|
def batch_dependent_associations
|
16
24
|
self.class.reflect_on_all_associations(:has_many).select { |v| v.options.has_key?(:dependent) && [:destroy, :delete_all].include?(v.options[:dependent]) }.each do |association|
|
17
|
-
send(association.name).find_each(batch_size:
|
18
|
-
send(association.name).find_each(batch_size:
|
25
|
+
send(association.name).find_each(batch_size: self.class.dependent_associations_batch_size, &:destroy) if association.options[:dependent].eql?(:destroy)
|
26
|
+
send(association.name).find_each(batch_size: self.class.dependent_associations_batch_size, &:delete) if association.options[:dependent].eql?(:delete_all)
|
19
27
|
end
|
20
28
|
end
|
21
29
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: batch_dependent_associations
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- thisismydesign
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-04-
|
11
|
+
date: 2018-04-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|