model_iterator 1.0.4 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 99afeb3b36405d067e41fd305efccf904b992ac4
4
+ data.tar.gz: 0c9caa876f8d4566eeca4bf0c2da655f71d4eb68
5
+ SHA512:
6
+ metadata.gz: 06c0aa15153f69b15381acac1aa5235a56778fb7d3cc8e31e4226621db62ee2606561f1ea990f210f883d49f421a0cb8f1f50c5026255ea25abb1d0916ff3eb0
7
+ data.tar.gz: 40021312de9cb5f1bff81d28d88ad2bc8e41f320e462776ddc17bba4ca4112b9a1160700705f8d159b8467fb33b523e1e52ffb78417aa50be3aae9cdf072f8d9
data/Gemfile CHANGED
@@ -3,8 +3,6 @@ source 'https://rubygems.org'
3
3
  gemspec
4
4
 
5
5
  group :dev do
6
- gem 'rake'
7
- gem 'activerecord'
8
6
  gem 'sqlite3'
9
7
  end
10
8
 
@@ -1,6 +1,6 @@
1
1
  # Iterates over large models, storing state in Redis.
2
2
  class ModelIterator
3
- VERSION = "1.0.4"
3
+ VERSION = "2.0.0"
4
4
 
5
5
  class MaxIterations < StandardError
6
6
  attr_reader :iterator
@@ -204,7 +204,11 @@ class ModelIterator
204
204
  # Returns an Array of ActiveRecord::Base instances if any results are
205
205
  # returned, or nil.
206
206
  def records
207
- arr = @klass.all(find_options)
207
+ options = find_options
208
+ query = @klass.where(options[:conditions]).limit(options[:limit]).order(options[:order])
209
+ query = query.select(options[:select]) if options[:select]
210
+ query = query.joins(options[:joins]) if options[:joins]
211
+ arr = query.to_a
208
212
  arr.empty? ? nil : arr
209
213
  end
210
214
 
@@ -12,8 +12,8 @@ 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.4'
16
- s.date = '2013-05-01'
15
+ s.version = '2.0.0'
16
+ s.date = '2016-03-31'
17
17
  s.rubyforge_project = 'model_iterator'
18
18
 
19
19
  ## Make sure your summary is short. The description may be as long
@@ -32,6 +32,7 @@ Gem::Specification.new do |s|
32
32
  ## require 'NAME.rb' or'/lib/NAME/file.rb' can be as require 'NAME/file.rb'
33
33
  s.require_paths = %w[lib]
34
34
 
35
+ s.add_dependency 'activerecord', '>=4.0'
35
36
  s.add_development_dependency 'rake'
36
37
  s.add_development_dependency 'test-unit'
37
38
 
@@ -3,18 +3,32 @@ require 'test/unit'
3
3
  require 'active_record'
4
4
  require File.expand_path("../../lib/model_iterator", __FILE__)
5
5
 
6
+ ActiveRecord::Base.establish_connection :adapter => 'sqlite3', :database => ':memory:'
6
7
  class ModelIterator::TestCase < Test::Unit::TestCase
7
8
  class Model < ActiveRecord::Base
8
- establish_connection :adapter => 'sqlite3', :database => ':memory:'
9
9
  connection.create_table table_name do |c|
10
10
  c.column :name, :string
11
11
  end
12
12
 
13
+ has_one :associated_model
14
+
13
15
  %w(a b c).each do |s|
14
16
  create!(:name => s)
15
17
  end
16
18
  end
17
19
 
20
+ class AssociatedModel < ActiveRecord::Base
21
+ connection.create_table table_name do |c|
22
+ c.integer :model_id
23
+ end
24
+
25
+ belongs_to :model
26
+
27
+ Model.all.each do |m|
28
+ create!(:model => m)
29
+ end
30
+ end
31
+
18
32
  class RedisClient
19
33
  def initialize(hash = nil)
20
34
  @hash = hash || {}
@@ -133,6 +133,23 @@ class IterateTest < ModelIterator::TestCase
133
133
  assert_equal %w(a b c), names
134
134
  end
135
135
 
136
+ def test_select_option_honored
137
+ names = []
138
+ redis = RedisClient.new
139
+ iter = ModelIterator.new Model, :redis => redis, :limit => 1, :select => :id
140
+ iter.each do |m|
141
+ assert_false m.attributes.has_key?(:name)
142
+ end
143
+ end
144
+
145
+ def test_joins_can_be_used
146
+ redis = RedisClient.new
147
+ iter = ModelIterator.new Model, :redis => redis, :limit => 1, :joins => :associated_model
148
+ iter.each do |m|
149
+ assert_not_nil m.associated_model
150
+ end
151
+ end
152
+
136
153
  class ExpectedError < StandardError; end
137
154
  end
138
155
 
metadata CHANGED
@@ -1,46 +1,55 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: model_iterator
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.4
5
- prerelease:
4
+ version: 2.0.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Rick Olson
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-05-01 00:00:00.000000000 Z
11
+ date: 2016-03-31 00:00:00.000000000 Z
13
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activerecord
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '4.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '4.0'
14
27
  - !ruby/object:Gem::Dependency
15
28
  name: rake
16
29
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
30
  requirements:
19
- - - ! '>='
31
+ - - '>='
20
32
  - !ruby/object:Gem::Version
21
33
  version: '0'
22
34
  type: :development
23
35
  prerelease: false
24
36
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
37
  requirements:
27
- - - ! '>='
38
+ - - '>='
28
39
  - !ruby/object:Gem::Version
29
40
  version: '0'
30
41
  - !ruby/object:Gem::Dependency
31
42
  name: test-unit
32
43
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
44
  requirements:
35
- - - ! '>='
45
+ - - '>='
36
46
  - !ruby/object:Gem::Version
37
47
  version: '0'
38
48
  type: :development
39
49
  prerelease: false
40
50
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
51
  requirements:
43
- - - ! '>='
52
+ - - '>='
44
53
  - !ruby/object:Gem::Version
45
54
  version: '0'
46
55
  description: Iterate through large ActiveRecord datasets
@@ -62,28 +71,24 @@ files:
62
71
  - test/iterate_test.rb
63
72
  homepage: http://github.com/technoweenie/model_iterator
64
73
  licenses: []
74
+ metadata: {}
65
75
  post_install_message:
66
76
  rdoc_options: []
67
77
  require_paths:
68
78
  - lib
69
79
  required_ruby_version: !ruby/object:Gem::Requirement
70
- none: false
71
80
  requirements:
72
- - - ! '>='
81
+ - - '>='
73
82
  - !ruby/object:Gem::Version
74
83
  version: '0'
75
- segments:
76
- - 0
77
- hash: 1098997578076474898
78
84
  required_rubygems_version: !ruby/object:Gem::Requirement
79
- none: false
80
85
  requirements:
81
- - - ! '>='
86
+ - - '>='
82
87
  - !ruby/object:Gem::Version
83
88
  version: 1.3.5
84
89
  requirements: []
85
90
  rubyforge_project: model_iterator
86
- rubygems_version: 1.8.23
91
+ rubygems_version: 2.0.14
87
92
  signing_key:
88
93
  specification_version: 2
89
94
  summary: Iterate through large ActiveRecord datasets