dase 4.1.0 → 4.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fa21a89c14adc39b8906ec72c7b4b4c53dfefbe2
4
- data.tar.gz: 1742ddc3cfa7c83952d008ec7d3421e9946883c7
3
+ metadata.gz: b1a4d6f990d789d3a9a7a7d79995e3bd9177c98a
4
+ data.tar.gz: 5c4be473b6ddc9a2c8933207044ae224d8ebe1bc
5
5
  SHA512:
6
- metadata.gz: 4a3383ce22ef7a04bc1363a09b15037dd7b92417bf4a65abb12a4f7027a4895c8e7dd3d62e4cd52687acd93d3653c02a18c8301530a986d1ce2a2de80da3e5af
7
- data.tar.gz: ce0941ab55f4c38e9fe21b3e559f93640d9e0b61920d3ff744158a91fa1da524ecbf17b202b7d54bba61a3728dc2f7add3519de7dd551fc2ebdf630b0042e2cc
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.instance_eval(&proc) if proc
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
@@ -1,3 +1,3 @@
1
1
  module Dase
2
- VERSION = '4.1.0'
2
+ VERSION = '4.1.1'
3
3
  end
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.0
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-30 00:00:00.000000000 Z
11
+ date: 2014-10-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport