array_decay 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/.ruby-version +1 -0
- data/.travis.yml +5 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +44 -0
- data/Rakefile +12 -0
- data/array_decay.gemspec +23 -0
- data/lib/array_decay.rb +25 -0
- data/lib/array_decay/version.rb +3 -0
- data/test/lib/array_decay_test.rb +13 -0
- data/test/test_helper.rb +3 -0
- metadata +86 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: ca265f3e30041bce50dc010403aeb4274305f8dd
|
4
|
+
data.tar.gz: 7c28602e80839d54b226841b463b446afcf9482f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ed52f5e6d46cec06b6f7f9890b701fc89e656fdf1bfe54676966e29e5b29e8ee10e68a8467f0da02cb0a116a28c932229e3db7f64e935f7546127fbc2047e168
|
7
|
+
data.tar.gz: 5b0b9b1a3d89ba5c3350c8c71e394bf85a61a76169322c81a46db1adf94270a41535b31d4a0a58265953bd0358cc4d03e63e37739658e33eda62a90fbcf6b5b4
|
data/.gitignore
ADDED
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.0.0-p247
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 sonnym
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
# Array Decay
|
2
|
+
|
3
|
+
[![Build Status](https://travis-ci.org/sonnym/array_decay.png?branch=master)](https://travis-ci.org/sonnym/array_decay)
|
4
|
+
[![Code Climate](https://codeclimate.com/github/sonnym/array_decay.png)](https://codeclimate.com/github/sonnym/array_decay)
|
5
|
+
|
6
|
+
A simple way to prevent increasing memory usage when iterating over objects
|
7
|
+
that grow during their method calls, e.g. batch processing ActiveRecord objects
|
8
|
+
that require lots of associated data.
|
9
|
+
|
10
|
+
## Installation
|
11
|
+
|
12
|
+
Add this line to your application's Gemfile:
|
13
|
+
|
14
|
+
gem 'array_decay'
|
15
|
+
|
16
|
+
And then execute:
|
17
|
+
|
18
|
+
$ bundle
|
19
|
+
|
20
|
+
Or install it yourself as:
|
21
|
+
|
22
|
+
$ gem install array_decay
|
23
|
+
|
24
|
+
## Usage
|
25
|
+
|
26
|
+
Simply call the `#decay!` method on your array before enumerating. This
|
27
|
+
instantiates and returns an enumerable `ArrayDecay::Enumerator` which
|
28
|
+
will unshift elements of the array.
|
29
|
+
|
30
|
+
```ruby
|
31
|
+
moribund_objects.decay!.each do |item|
|
32
|
+
item.perform_expensive_operation!
|
33
|
+
end
|
34
|
+
|
35
|
+
moribund_objects.count # 0
|
36
|
+
```
|
37
|
+
|
38
|
+
## Contributing
|
39
|
+
|
40
|
+
1. Fork it
|
41
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
42
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
43
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
44
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
data/array_decay.gemspec
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'array_decay/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'array_decay'
|
8
|
+
spec.version = ArrayDecay::VERSION
|
9
|
+
spec.authors = ['sonnym']
|
10
|
+
spec.email = ['michaud.sonny@gmail.com']
|
11
|
+
spec.description = 'Discard array elements during enumeration to free memory.'
|
12
|
+
spec.summary = spec.description
|
13
|
+
spec.homepage = ''
|
14
|
+
spec.license = 'MIT'
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ['lib']
|
20
|
+
|
21
|
+
spec.add_development_dependency 'bundler', '~> 1.3'
|
22
|
+
spec.add_development_dependency 'rake'
|
23
|
+
end
|
data/lib/array_decay.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
require_relative 'array_decay/version'
|
2
|
+
|
3
|
+
class Array
|
4
|
+
def decay!
|
5
|
+
ArrayDecay::Enumerator.new(self)
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
module ArrayDecay
|
10
|
+
class Enumerator
|
11
|
+
include Enumerable
|
12
|
+
|
13
|
+
attr_accessor :enumerator
|
14
|
+
|
15
|
+
def initialize(enumerator)
|
16
|
+
self.enumerator = enumerator
|
17
|
+
end
|
18
|
+
|
19
|
+
def each(&block)
|
20
|
+
until enumerator.empty?
|
21
|
+
block.call(enumerator.shift)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require_relative '../test_helper'
|
2
|
+
|
3
|
+
describe ArrayDecay do
|
4
|
+
it 'should create a new method on Array' do
|
5
|
+
assert_respond_to [], :decay!
|
6
|
+
end
|
7
|
+
|
8
|
+
it 'should cause the array to mutate when iterated over' do
|
9
|
+
original = [:foo, :bar, :baz]
|
10
|
+
original.decay!.map(&:to_s)
|
11
|
+
assert_empty original
|
12
|
+
end
|
13
|
+
end
|
data/test/test_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: array_decay
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- sonnym
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-10-12 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description: Discard array elements during enumeration to free memory.
|
42
|
+
email:
|
43
|
+
- michaud.sonny@gmail.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- .gitignore
|
49
|
+
- .ruby-version
|
50
|
+
- .travis.yml
|
51
|
+
- Gemfile
|
52
|
+
- LICENSE.txt
|
53
|
+
- README.md
|
54
|
+
- Rakefile
|
55
|
+
- array_decay.gemspec
|
56
|
+
- lib/array_decay.rb
|
57
|
+
- lib/array_decay/version.rb
|
58
|
+
- test/lib/array_decay_test.rb
|
59
|
+
- test/test_helper.rb
|
60
|
+
homepage: ''
|
61
|
+
licenses:
|
62
|
+
- MIT
|
63
|
+
metadata: {}
|
64
|
+
post_install_message:
|
65
|
+
rdoc_options: []
|
66
|
+
require_paths:
|
67
|
+
- lib
|
68
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
69
|
+
requirements:
|
70
|
+
- - '>='
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: '0'
|
73
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
74
|
+
requirements:
|
75
|
+
- - '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
requirements: []
|
79
|
+
rubyforge_project:
|
80
|
+
rubygems_version: 2.0.3
|
81
|
+
signing_key:
|
82
|
+
specification_version: 4
|
83
|
+
summary: Discard array elements during enumeration to free memory.
|
84
|
+
test_files:
|
85
|
+
- test/lib/array_decay_test.rb
|
86
|
+
- test/test_helper.rb
|