prelude-batch-loader 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/prelude.rb +1 -2
- data/lib/prelude/version.rb +1 -1
- data/spec/prelude_spec.rb +8 -4
- metadata +2 -3
- data/lib/prelude/relation.rb +0 -14
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cae99a6ad46de71ce518e50d1f2877efaebf2df5d23b4224fb10416417f69cd6
|
4
|
+
data.tar.gz: 3594cbeadbaa4e55fea9138570fc55fd8863c04698999737cb018290af95f310
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9519329f8ed99362489e9b434448879b1aae9c286e4b689b8b8376866e5b327fd055fcccd36e3e2edb7a4765ca2a478b26b24084808ca7d81b8e2520d261262a
|
7
|
+
data.tar.gz: c2e34af07621b2b2a06514eee82d010f867b67f4afefa50811a239f2536e0bbda6cc168a25f6c5138b5e922d7a012d4ce4c1e670537d2284da4c9f0a745e2bd7
|
data/lib/prelude.rb
CHANGED
@@ -1,13 +1,12 @@
|
|
1
1
|
require_relative 'prelude/version'
|
2
2
|
require_relative 'prelude/preloadable'
|
3
|
-
require_relative 'prelude/relation'
|
4
3
|
require_relative 'prelude/enumerator'
|
5
4
|
require 'active_support'
|
6
5
|
|
7
6
|
ActiveSupport.on_load :active_record do
|
8
7
|
include Prelude::Preloadable
|
9
|
-
ActiveRecord::Relation.prepend Prelude::Relation
|
10
8
|
end
|
11
9
|
|
12
10
|
# Patch into Enumerator to support with_prelude
|
13
11
|
Enumerator.include(Prelude::Enumerator)
|
12
|
+
Enumerable.include(Prelude::Enumerator)
|
data/lib/prelude/version.rb
CHANGED
data/spec/prelude_spec.rb
CHANGED
@@ -31,7 +31,7 @@ describe Prelude do
|
|
31
31
|
|
32
32
|
5.times { klass.create! }
|
33
33
|
|
34
|
-
expect(klass.all.map(&:number).uniq).to eq([42]) # all the same result
|
34
|
+
expect(klass.all.with_prelude.map(&:number).uniq).to eq([42]) # all the same result
|
35
35
|
expect(call_count).to eq(1) # only one call
|
36
36
|
end
|
37
37
|
|
@@ -103,13 +103,13 @@ describe Prelude do
|
|
103
103
|
end
|
104
104
|
|
105
105
|
it 'should be able to pass arguments to methods' do
|
106
|
-
|
106
|
+
call_arguments = []
|
107
107
|
|
108
108
|
klass = Class.new(ActiveRecord::Base) do
|
109
109
|
self.table_name = 'breweries'
|
110
110
|
|
111
111
|
define_prelude(:multiply_by) do |records, by|
|
112
|
-
|
112
|
+
call_arguments << [records.to_a, by]
|
113
113
|
Hash.new { |h, k| h[k] = 42 * by }
|
114
114
|
end
|
115
115
|
end
|
@@ -122,7 +122,11 @@ describe Prelude do
|
|
122
122
|
expect(i.multiply_by(2)).to eq(84)
|
123
123
|
end
|
124
124
|
|
125
|
-
|
125
|
+
# two calls with the appropriate arguments
|
126
|
+
expect(call_arguments).to eq([
|
127
|
+
[instances, 1], # deduped
|
128
|
+
[instances, 2]
|
129
|
+
])
|
126
130
|
end
|
127
131
|
|
128
132
|
it 'should be able to set a batch size' do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: prelude-batch-loader
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- John Crepezzi
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-04-
|
11
|
+
date: 2021-04-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -77,7 +77,6 @@ files:
|
|
77
77
|
- lib/prelude/method.rb
|
78
78
|
- lib/prelude/preloadable.rb
|
79
79
|
- lib/prelude/preloader.rb
|
80
|
-
- lib/prelude/relation.rb
|
81
80
|
- lib/prelude/version.rb
|
82
81
|
- spec/prelude_spec.rb
|
83
82
|
- spec/spec_helper.rb
|
data/lib/prelude/relation.rb
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
module Prelude
|
2
|
-
module Relation
|
3
|
-
def preload_associations(records)
|
4
|
-
# Keep existing behavior
|
5
|
-
super(records)
|
6
|
-
|
7
|
-
# Add in our behavior
|
8
|
-
if Preloadable === records.first
|
9
|
-
preloader = Preloader.new(records.first.class, records)
|
10
|
-
records.each { |r| r.prelude_preloader = preloader }
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|