activerecord-prunable 0.3.2 → 0.3.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: af74d6c4f68c35edcfa4b30e7ed7cb42e78758a3
4
- data.tar.gz: 27c2523ead3838ed6ce8afc8fb88019ab269e100
3
+ metadata.gz: 98eed29b171fce5713dbc74ab812c8d6ccd4531a
4
+ data.tar.gz: 41bf6db4104667a2eff427332acdb4f6ee1423c1
5
5
  SHA512:
6
- metadata.gz: 5b3e7b41eb481553f107e9b355ee95c1b8bb006e4cb57c87f44e60529f925f2cbcf5855270c9e0627a39c45e8cf0bfaa3a21aa0face394a8b7940fecb45a3df7
7
- data.tar.gz: c26196c6117ffb4cd35d04fab611ec2ea25f68cfb8fd9442562cb04bddb2d4a163a650d87ce157411335468e7b3e07868805d6299ac10a100cad85193bfd3298
6
+ metadata.gz: 531bf56a1a4e857af793da15fb681f90d93f549671872cdfbbef07805aa30fff9a45be76d8773d9b8cf0d0a9c2a834dedaf297cc05fee59d6928c85209e04510
7
+ data.tar.gz: 6aeceb2f4cc5cde6fe6634b6b1efeaec7bfa2c7eaed4da293a3f35190a431fce02ee5093f11d9fac02a0f2b3a2f8384c9d10714cd39cb23eb6f4d70d05cf3b65
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # Activerecord-prunable [![Gem Version](https://badge.fury.io/rb/activerecord-prunable.svg)](https://badge.fury.io/rb/activerecord-prunable) [![Build Status](https://travis-ci.org/dr2m/activerecord-prunable.svg?branch=master)](https://travis-ci.org/dr2m/activerecord-prunable) [![Code Climate](https://codeclimate.com/github/dr2m/activerecord-prunable/badges/gpa.svg)](https://codeclimate.com/github/dr2m/activerecord-prunable)
1
+ # Activerecord-prunable [![Gem Version](https://badge.fury.io/rb/activerecord-prunable.svg)](https://badge.fury.io/rb/activerecord-prunable) [![Build Status](https://travis-ci.org/dr2m/activerecord-prunable.svg?branch=master)](https://travis-ci.org/dr2m/activerecord-prunable) [![Code Climate](https://codeclimate.com/github/dr2m/activerecord-prunable/badges/gpa.svg)](https://codeclimate.com/github/dr2m/activerecord-prunable)
2
2
 
3
3
  Convenient removal of obsolete ActiveRecord models.
4
4
 
@@ -21,7 +21,7 @@ Or install it yourself as:
21
21
 
22
22
  ## Usage
23
23
 
24
- __1. Include the `Prunable` module in the ActiveRecord model which needs to be pruned.__
24
+ __1. Include the `Prunable` module in the ActiveRecord model which needs to be pruned.__
25
25
 
26
26
  __2. Define the `:prunable` scope which returns models to prune.__
27
27
 
@@ -37,7 +37,7 @@ __2. Define the `:prunable` scope which returns models to prune.__
37
37
  end
38
38
  ```
39
39
 
40
- or use one of the `prune_after`, `prune_created_after`, `prune_updated_after` methods
40
+ or use one of the `prune_after`, `prune_created_after`, `prune_updated_after` methods
41
41
 
42
42
  ```ruby
43
43
  class Notification < ApplicationRecord
@@ -47,9 +47,9 @@ __2. Define the `:prunable` scope which returns models to prune.__
47
47
  end
48
48
  ```
49
49
 
50
- `prune_after` is an alias for `prune_created_after`
51
- `prune_created_after(TTL)` defines `where('created_at < ?', current_time - TTL)` prunable scope
52
- `prune_updated_after(TTL)` defines `where('updated_at < ?', current_time - TTL)` prunable scope
50
+ `prune_after` is an alias for `prune_created_after`
51
+ `prune_created_after(TTL)` defines `where('created_at < ?', current_time - TTL)` prunable scope
52
+ `prune_updated_after(TTL)` defines `where('updated_at < ?', current_time - TTL)` prunable scope
53
53
 
54
54
  __3. Add a `Prunable.prune!` call to a periodic task.__
55
55
 
@@ -71,32 +71,34 @@ __Pruning a single model:__
71
71
  SomeModel.prune!
72
72
  ```
73
73
 
74
- __Pruning multiple models:__
75
- Note that the `Prunable.prune!` calls `Rails.application.eager_load!`. It can decrease free memory size.
74
+ __Pruning multiple models:__
75
+ Note that the `Prunable.prune!` calls `Rails.application.eager_load!`. It can decrease free memory size.
76
76
 
77
77
  ```ruby
78
78
  Prunable.prune!(SomeModel, AnotherModel)
79
79
  ```
80
80
 
81
- __Set default method of pruning (:destroy or :delete):__
81
+ __Set default method of pruning (:destroy or :delete):__
82
82
 
83
83
  ```ruby
84
84
  Prunable.prune!(prune_method: :delete)
85
85
  ```
86
86
 
87
- __Call `:prunable` scope with params:__
87
+ __Call `:prunable` scope with params:__
88
88
 
89
89
  ```ruby
90
90
  Prunable.prune!(params: [:foo, :bar])
91
91
  ```
92
92
 
93
- __Getting an array of all the models which include `ActiveRecord::Prunable`:__
93
+ __Getting an array of all the models which include `ActiveRecord::Prunable`:__
94
94
  ```ruby
95
95
  Prunable.models
96
96
  ```
97
97
 
98
- __Pruning all models which include `ActiveRecord::Prunable`:__
98
+ __Pruning all models which include `ActiveRecord::Prunable`:__
99
99
 
100
100
  ```ruby
101
101
  Prunable.prune!
102
102
  ```
103
+
104
+ You are also able to call `prune` method instead of `prune!` if you don't want to receive exceptions.
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |spec|
2
2
  spec.name = "activerecord-prunable"
3
- spec.version = "0.3.2"
3
+ spec.version = "0.3.3"
4
4
  spec.authors = ["dr2m"]
5
5
  spec.email = ["maletin@maletin.work"]
6
6
 
@@ -14,9 +14,26 @@ module Prunable
14
14
  def prune!(*models, prune_method: nil, current_time: nil, params: [])
15
15
  models = self.models if models.empty?
16
16
 
17
+ models.each_with_object({}) do |model, pruned|
18
+ pruned[model.table_name] = model.prune!(*params, prune_method: prune_method, current_time: current_time)
19
+ end
20
+ end
21
+
22
+ def prune(*models, prune_method: nil, current_time: nil, params: [])
23
+ models = self.models if models.empty?
24
+
25
+ pruned = {}
26
+ errors = []
27
+
17
28
  models.each do |model|
18
- model.prune!(*params, prune_method: prune_method, current_time: current_time)
29
+ begin
30
+ pruned[model.table_name] = model.prune!(*params, prune_method: prune_method, current_time: current_time)
31
+ rescue => e
32
+ errors << e
33
+ end
19
34
  end
35
+
36
+ [pruned, errors]
20
37
  end
21
38
  end
22
39
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activerecord-prunable
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 0.3.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - dr2m
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-10-16 00:00:00.000000000 Z
11
+ date: 2017-12-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec