activerecord-precounter 0.3.2 → 0.3.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a5bf25aa0550622438acc6518baeb060cc7a8b3efb256d398aae6e10575654f8
4
- data.tar.gz: 51959a62fc7b3bee6bed30512711d7606b0ed3ac756b50fc51ad91ca42ef08ef
3
+ metadata.gz: '09078896e68490e75c8beb5645afcd62ad0d5ea91c00e4bce6caf56c78fef5a8'
4
+ data.tar.gz: 584556fa31db7232716409333ddc670679846fab59660a66c20432eef6eb95b5
5
5
  SHA512:
6
- metadata.gz: 8591c0865cbf9714089fa3ef8230a6cbe09248e49cff8bdbc6dba1dc74c89a9cb2d1cd3f3e5c13dc33e15c9c4b8079f626e790e86ca211ab33b163b0942ffc90
7
- data.tar.gz: b0286be1b1273b5f53390c022dad711cde8aeb41fdd546619da928fbfc18885a2a3feb7e6c2d54a5fe65321141729dc203c8388156241c6bec7ae7e2cb81e257
6
+ metadata.gz: 978b940f2cc5adf4206bb399fbdb0e35f745336095df5a411d9d7fc98e9c3f43b3e0974c905d23b3d96811c9a55cc75d1da1aa3c1f3317b3c33cc20412224d6d
7
+ data.tar.gz: 194cd5631328971a328c71ecf853cf80f10f309dff0cf3ff23a9b57275d3bd78b00cfd43ff8e070f6c023d0b5a4183b92fd03e9f2e2edc08e0f18257af38234f
data/.travis.yml CHANGED
@@ -5,6 +5,7 @@ cache: bundler
5
5
  branches:
6
6
  only:
7
7
  - master
8
+ dist: trusty
8
9
  matrix:
9
10
  include:
10
11
  - rvm: 2.4.1
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## v0.3.3
2
+
3
+ * Support passing a single record to `ActiveRecord::Precounter.new` [#8](https://github.com/k0kubun/activerecord-precounter/pull/8)
4
+
1
5
  ## v0.3.2
2
6
 
3
7
  * Support primary\_key option of belongs\_to association [#7](https://github.com/k0kubun/activerecord-precounter/pull/7)
@@ -12,17 +12,24 @@ module ActiveRecord
12
12
  # @param [Array<String,Symbol>] association_names - Eager loaded association names. e.g. `[:users, :likes]`
13
13
  # @return [Array<ActiveRecord::Base>]
14
14
  def precount(*association_names)
15
- records = @relation.to_a
16
- return [] if records.empty?
15
+ # Allow single record instances as well as relations to be passed.
16
+ # The splat here will return an array of the single record if it's
17
+ # not a relation or otherwise return the records themselves via #to_a.
18
+ records = *@relation
19
+ return records if records.empty?
20
+
21
+ # We need to get the relation's active class, which is the class itself
22
+ # in the case of a single record.
23
+ klass = @relation.respond_to?(:klass) ? @relation.klass : @relation.class
17
24
 
18
25
  association_names.each do |association_name|
19
26
  association_name = association_name.to_s
20
- reflection = @relation.klass.reflections.fetch(association_name)
27
+ reflection = klass.reflections.fetch(association_name)
21
28
 
22
29
  if reflection.inverse_of.nil?
23
30
  raise MissingInverseOf.new(
24
- "`#{reflection.klass}` does not have inverse of `#{@relation.klass}##{reflection.name}`. "\
25
- "Probably missing to call `#{reflection.klass}.belongs_to #{@relation.name.underscore.to_sym.inspect}`?"
31
+ "`#{reflection.klass}` does not have inverse of `#{klass}##{reflection.name}`. "\
32
+ "Probably missing to call `#{reflection.klass}.belongs_to #{klass.name.underscore.to_sym.inspect}`?"
26
33
  )
27
34
  end
28
35
 
@@ -1,5 +1,5 @@
1
1
  module ActiveRecord
2
2
  class Precounter
3
- VERSION = '0.3.2'
3
+ VERSION = '0.3.3'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activerecord-precounter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 0.3.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Takashi Kokubun
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-11-26 00:00:00.000000000 Z
11
+ date: 2019-10-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -153,8 +153,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
153
153
  - !ruby/object:Gem::Version
154
154
  version: '0'
155
155
  requirements: []
156
- rubyforge_project:
157
- rubygems_version: 2.7.6
156
+ rubygems_version: 3.0.3
158
157
  signing_key:
159
158
  specification_version: 4
160
159
  summary: Yet Another N+1 COUNT Query Killer for ActiveRecord