dase 4.1.0 → 4.1.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.
- checksums.yaml +4 -4
- data/lib/dase/mp_active_record.rb +8 -0
- data/lib/dase/preloader_methods.rb +1 -1
- data/lib/dase/version.rb +1 -1
- data/test/test_dase.rb +8 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b1a4d6f990d789d3a9a7a7d79995e3bd9177c98a
|
4
|
+
data.tar.gz: 5c4be473b6ddc9a2c8933207044ae224d8ebe1bc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1b41222641e271a29db1a2c7d9283d00d005f9ebdca0317d13d2bb8a11daa1d16e3c490afd3ca86ddbceb5bb0b58bbc3d870ed057d09c40c6f2d5596b3b07fa3
|
7
|
+
data.tar.gz: 4790d98c1bcfd56ba5e8334b0841814f5f4936163449a3c09b8d90682caa390f006fff51c3a59f28af127443f72f044f95212d2ceba9f3b13e38c1dc1565d846
|
@@ -6,6 +6,7 @@ module Dase
|
|
6
6
|
|
7
7
|
def includes_count_of(*args)
|
8
8
|
options = args.extract_options!
|
9
|
+
extract_proc_argument(args, options)
|
9
10
|
sanitize_dase_options(args, options)
|
10
11
|
apply_synonyms(options)
|
11
12
|
return self if args.empty?
|
@@ -17,6 +18,13 @@ module Dase
|
|
17
18
|
end
|
18
19
|
end
|
19
20
|
|
21
|
+
def extract_proc_argument(args, options)
|
22
|
+
if args.last.is_a?(Proc)
|
23
|
+
raise "Can't use :proc option together with ->{} syntax" if options.has_key?(:proc)
|
24
|
+
options[:proc] = args.pop
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
20
28
|
def merge(other)
|
21
29
|
super(other).tap do |result|
|
22
30
|
result.dase_values.merge!(other.dase_values || {}) if other # other == nil is fine too
|
@@ -25,7 +25,7 @@ module Dase
|
|
25
25
|
proc = options.delete(:proc)
|
26
26
|
|
27
27
|
# applying proc syntax: -> {...}
|
28
|
-
scope = scope.
|
28
|
+
scope = scope.instance_exec(&proc) if proc
|
29
29
|
|
30
30
|
options.slice(*VALID_ASSOCIATION_OPTIONS).each do |key, value|
|
31
31
|
scope = scope.send(key, value)
|
data/lib/dase/version.rb
CHANGED
data/test/test_dase.rb
CHANGED
@@ -63,6 +63,14 @@ describe 'includes_count_of' do
|
|
63
63
|
compare_counts(traditional_counts, dase_counts, true_counts)
|
64
64
|
end
|
65
65
|
|
66
|
+
it 'should support lambda syntax (where year 1990)' do
|
67
|
+
traditional_counts = Author.order(:name).map { |a| a.books.where(:year => 1990).count }
|
68
|
+
dase_counts = Author.includes_count_of(:books, lambda { where(:year => 1990) }).order(:name).map { |a| a.books_count }
|
69
|
+
# the order is: Bobby, Joe, Teddy - due to order(:name)
|
70
|
+
true_counts = [1, 2, 0] # see books.yml
|
71
|
+
compare_counts(traditional_counts, dase_counts, true_counts)
|
72
|
+
end
|
73
|
+
|
66
74
|
it 'should count books for year 2012 using :only option' do
|
67
75
|
dase_counts = Author.includes_count_of(:books, :only => Book.year2012).order(:name).map { |a| a.books_count }
|
68
76
|
# the order is: Bobby, Joe, Teddy - due to order(:name)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dase
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.1.
|
4
|
+
version: 4.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Vladimir Yartsev
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-10-
|
11
|
+
date: 2014-10-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|