duck_puncher 4.4.2 → 4.5.0

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
  SHA1:
3
- metadata.gz: 62f4cac1d15e159d6ba58d71681cec7e34be8c71
4
- data.tar.gz: 53ee95a89344c33f8960cf5d957cbb5dbf6d3562
3
+ metadata.gz: 197f08e7d41195a8d4d8281175dad2923da0a80d
4
+ data.tar.gz: f8591266f5145352bdb4a9847e13ed84d6f67e1e
5
5
  SHA512:
6
- metadata.gz: ea6d68c9efd49449907ccfb6aab5b810f6b0081ce399817afc78804a813cf0c66feea9ea0cfe74492e3b1091baa3011cc0cc1492d2bdb2ed6ca5e27433f9e9eb
7
- data.tar.gz: dd5bf802c09382798460d26c81650588f10f64de8e2cba77fec53d82e55fffb932fe785178233037d96965b53b9093c7088e2c2f87c608c23828df71f81b05c8
6
+ metadata.gz: 05b387372a27b20a7d31a96d6e6b0cce79f59c963f0456925a3cd65c90a3514b87db0fda498c6dd597f7abdec179831b6c04c29eee9c8aaefe33aad24fa11b2b
7
+ data.tar.gz: ea1ebe0ec61c32f7f0c3e3899a5dd21897cf43e702dd7688b97d5995135530380225a5e35663b106f53fd5ca1e450f973e85a15cab3d7ac76c8806d4a2f4daed
data/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ 4.5.0 (01/19/2016)
2
+ ==================
3
+
4
+ * Fix `ActiveRecord#associations` to use LIMIT 1 for has_many associations
5
+ * Remove redundant `ActiveRecord.latest`
6
+
1
7
  4.4.2 (01/10/2016)
2
8
  ==================
3
9
 
@@ -1,50 +1,56 @@
1
1
  module DuckPuncher
2
- module Ducks
3
- module ActiveRecord
4
- def self.included(base)
5
- base.extend(ClassMethods)
6
- end
7
-
8
- def associations?
9
- associations.present?
10
- end
11
-
12
- def associations
13
- reflections.select { |key, _| send(key).present? rescue nil }.keys
14
- end
15
-
16
- module ClassMethods
17
- def except_for(*ids)
18
- scoped.where("#{quoted_table_name}.id NOT IN (?)", ids)
19
- end
20
-
21
- def since(time)
22
- scoped.where("#{quoted_table_name}.created_at > ?", time)
23
- end
24
-
25
- alias created_since since
26
-
27
- def before(time)
28
- scoped.where("#{quoted_table_name}.created_at < ?", time)
29
- end
30
-
31
- def updated_since(time)
32
- scoped.where("#{quoted_table_name}.updated_at > ?", time)
33
- end
34
-
35
- def between(start_at, end_at)
36
- scoped.where("#{quoted_table_name}.created_at BETWEEN ? AND ", start_at, end_at)
37
- end
38
-
39
- def latest
40
- scoped.order("#{quoted_table_name}.id ASC").last
41
- end
42
-
43
- # shim for backwards compatibility with Rails 3
44
- def scoped
45
- where(nil)
46
- end if ::Rails::VERSION::MAJOR > 3
47
- end
48
- end
49
- end
2
+ module Ducks
3
+ module ActiveRecord
4
+ def self.included(base)
5
+ base.extend(ClassMethods)
6
+ end
7
+
8
+ def associations?
9
+ associations.present?
10
+ end
11
+
12
+ def associations
13
+ reflections.select { |key, reflection|
14
+ begin
15
+ if reflection.macro.to_s =~ /many/
16
+ send(key).exists?
17
+ else
18
+ send(key).present?
19
+ end
20
+ rescue
21
+ nil
22
+ end
23
+ }.keys
24
+ end
25
+
26
+ module ClassMethods
27
+ def except_for(*ids)
28
+ scoped.where("#{quoted_table_name}.#{primary_key} NOT IN (?)", ids)
29
+ end
30
+
31
+ def since(time)
32
+ scoped.where("#{quoted_table_name}.created_at > ?", time)
33
+ end
34
+
35
+ alias created_since since
36
+
37
+ def before(time)
38
+ scoped.where("#{quoted_table_name}.created_at < ?", time)
39
+ end
40
+
41
+ def updated_since(time)
42
+ scoped.where("#{quoted_table_name}.updated_at > ?", time)
43
+ end
44
+
45
+ def between(start_at, end_at)
46
+ scoped.where("#{quoted_table_name}.created_at BETWEEN ? AND ", start_at, end_at)
47
+ end
48
+
49
+ # shim for backwards compatibility with Rails 3
50
+ def scoped
51
+ where(nil)
52
+ end if ::Rails::VERSION::MAJOR > 3
53
+ end
54
+ end
55
+ end
50
56
  end
@@ -1,3 +1,3 @@
1
1
  module DuckPuncher
2
- VERSION = '4.4.2'.freeze
2
+ VERSION = '4.5.0'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: duck_puncher
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.4.2
4
+ version: 4.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Buckley
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-01-11 00:00:00.000000000 Z
11
+ date: 2017-01-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: usable