batch_dependent_associations 0.1.0 → 0.2.0

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,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 84ea82085a532496f98b03cbf2094f19f900e880
4
- data.tar.gz: c7839250e2b082423feb83aaaa3306bf93350a36
3
+ metadata.gz: 87f35494445fa7a274135a13b16c8147fd92d892
4
+ data.tar.gz: 42dbd8a1d923f5427072133f0707c468faa26936
5
5
  SHA512:
6
- metadata.gz: 351491b7ee686f32aace431102c249188ee7dc14e04e7b589f8ea3dfa179d911d21a88da2a646c887fd5b8ba1c1b3ac316085af0aed7a73ec0dc600850d81f2a
7
- data.tar.gz: 33dcc47696517143d348164b2385ced50ec22c7ecca3c6b248c21379f0bf83506dae3a4998a5c3defe3b916e7c201a90240485c24c2c11c3190342a88dfe6dc8
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: 5, &:destroy) if association.options[:dependent].eql?(:destroy)
18
- send(association.name).find_each(batch_size: 5, &:delete) if association.options[:dependent].eql?(:delete_all)
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
@@ -1,3 +1,3 @@
1
1
  module BatchDependentAssociations
2
- VERSION = "0.1.0".freeze
2
+ VERSION = "0.2.0".freeze
3
3
  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.1.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-09 00:00:00.000000000 Z
11
+ date: 2018-04-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport