model_iterator 1.0.0 → 1.0.1
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.
- data/lib/model_iterator.rb +8 -3
- data/model_iterator.gemspec +1 -1
- data/test/init_test.rb +10 -1
- metadata +2 -2
data/lib/model_iterator.rb
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Iterates over large models, storing state in Redis.
|
|
2
2
|
class ModelIterator
|
|
3
|
-
VERSION = "1.0.
|
|
3
|
+
VERSION = "1.0.1"
|
|
4
4
|
|
|
5
5
|
class MaxIterations < StandardError
|
|
6
6
|
attr_reader :iterator
|
|
@@ -10,6 +10,11 @@ class ModelIterator
|
|
|
10
10
|
end
|
|
11
11
|
end
|
|
12
12
|
|
|
13
|
+
class << self
|
|
14
|
+
# Gets or sets a default Redis client object for iterators.
|
|
15
|
+
attr_accessor :redis
|
|
16
|
+
end
|
|
17
|
+
|
|
13
18
|
# Gets a reference to the ActiveRecord::Base class that is iterated.
|
|
14
19
|
#
|
|
15
20
|
# Returns a Class.
|
|
@@ -51,7 +56,7 @@ class ModelIterator
|
|
|
51
56
|
# iterating. This is set automatically by #each.
|
|
52
57
|
attr_accessor :job
|
|
53
58
|
|
|
54
|
-
# Gets or
|
|
59
|
+
# Gets or sets the Redis client object.
|
|
55
60
|
attr_accessor :redis
|
|
56
61
|
|
|
57
62
|
# Initializes a ModelIterator instance.
|
|
@@ -89,7 +94,7 @@ class ModelIterator
|
|
|
89
94
|
else
|
|
90
95
|
{}
|
|
91
96
|
end
|
|
92
|
-
@redis = @options[:redis]
|
|
97
|
+
@redis = @options[:redis] || self.class.redis
|
|
93
98
|
@id_field = @options[:id_field] || klass.primary_key
|
|
94
99
|
@id_clause = @options[:id_clause] || "#{klass.table_name}.#{@id_field}"
|
|
95
100
|
@order = @options[:order] == :desc ? :desc : :asc
|
data/model_iterator.gemspec
CHANGED
|
@@ -12,7 +12,7 @@ Gem::Specification.new do |s|
|
|
|
12
12
|
## If your rubyforge_project name is different, then edit it and comment out
|
|
13
13
|
## the sub! line in the Rakefile
|
|
14
14
|
s.name = 'model_iterator'
|
|
15
|
-
s.version = '1.0.
|
|
15
|
+
s.version = '1.0.1'
|
|
16
16
|
s.date = '2012-09-07'
|
|
17
17
|
s.rubyforge_project = 'model_iterator'
|
|
18
18
|
|
data/test/init_test.rb
CHANGED
|
@@ -28,10 +28,15 @@ end
|
|
|
28
28
|
|
|
29
29
|
class InitializationTestWithOptions < ModelIterator::TestCase
|
|
30
30
|
def setup
|
|
31
|
-
|
|
31
|
+
ModelIterator.redis = @redis = RedisClient.new
|
|
32
|
+
@iter = ModelIterator.new Model,
|
|
32
33
|
:start_id => 5, :limit => 10, :prefix => 'foo'
|
|
33
34
|
end
|
|
34
35
|
|
|
36
|
+
def teardown
|
|
37
|
+
ModelIterator.redis = nil
|
|
38
|
+
end
|
|
39
|
+
|
|
35
40
|
def test_sets_klass
|
|
36
41
|
assert_equal Model, @iter.klass
|
|
37
42
|
end
|
|
@@ -51,6 +56,10 @@ class InitializationTestWithOptions < ModelIterator::TestCase
|
|
|
51
56
|
def test_sets_redis_prefix
|
|
52
57
|
assert_equal 'foo:ModelIterator:ModelIterator::TestCase::Model', @iter.prefix
|
|
53
58
|
end
|
|
59
|
+
|
|
60
|
+
def test_sets_default_redis
|
|
61
|
+
assert_equal @redis, @iter.redis
|
|
62
|
+
end
|
|
54
63
|
end
|
|
55
64
|
|
|
56
65
|
class InitializationTestWithCustomWhereClause < ModelIterator::TestCase
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: model_iterator
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.0.
|
|
4
|
+
version: 1.0.1
|
|
5
5
|
prerelease:
|
|
6
6
|
platform: ruby
|
|
7
7
|
authors:
|
|
@@ -72,7 +72,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
72
72
|
version: '0'
|
|
73
73
|
segments:
|
|
74
74
|
- 0
|
|
75
|
-
hash:
|
|
75
|
+
hash: -4149675607368163527
|
|
76
76
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
77
77
|
none: false
|
|
78
78
|
requirements:
|