left_joins 1.0.0 → 1.0.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/left_joins.rb +23 -1
- data/lib/left_joins/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9fe2a83d6cffc287bbf6724737c4e8dbfbe3ea6f
|
4
|
+
data.tar.gz: 2838cceb023ba1586a31efddc33aaac6349ad4f6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 655ca8dad040ed55ee43eab786bc935e27afd74c3dfc43a3462ba3ab98232bb5c0e85121ee66c739e51a92522672562de94bd4e60d5ec5867b03530edc7296ba
|
7
|
+
data.tar.gz: 0f55aa90871bd786842f941c3446dae67c221554d31c7f56ca850a2cf59f4024d7ce8e5f50b33ae1e98d8810a8819a67bdacf29c9c03b53700b4f9223c95852f
|
data/lib/left_joins.rb
CHANGED
@@ -4,7 +4,7 @@ require 'active_record/relation'
|
|
4
4
|
|
5
5
|
module ActiveRecord::QueryMethods
|
6
6
|
IS_RAILS3_FLAG = Gem::Version.new(ActiveRecord::VERSION::STRING) < Gem::Version.new('4.0.0')
|
7
|
-
if
|
7
|
+
if IS_RAILS3_FLAG
|
8
8
|
def check_if_method_has_arguments!(method_name, args)
|
9
9
|
if args.blank?
|
10
10
|
raise ArgumentError, "The method .#{method_name}() must contain arguments."
|
@@ -69,6 +69,28 @@ module ActiveRecord::QueryMethods
|
|
69
69
|
end
|
70
70
|
end
|
71
71
|
end
|
72
|
+
|
73
|
+
module ActiveRecord::Calculations
|
74
|
+
def perform_calculation(operation, column_name, options = {})
|
75
|
+
operation = operation.to_s.downcase
|
76
|
+
|
77
|
+
# If #count is used with #distinct (i.e. `relation.distinct.count`) it is
|
78
|
+
# considered distinct.
|
79
|
+
distinct = IS_RAILS3_FLAG ? options[:distinct] || self.uniq_value : self.distinct_value
|
80
|
+
|
81
|
+
if operation == "count"
|
82
|
+
column_name ||= select_for_count
|
83
|
+
column_name = primary_key if column_name == :all && distinct
|
84
|
+
distinct = nil if column_name =~ /\s*DISTINCT[\s(]+/i
|
85
|
+
end
|
86
|
+
|
87
|
+
if group_values.any?
|
88
|
+
execute_grouped_calculation(operation, column_name, distinct)
|
89
|
+
else
|
90
|
+
execute_simple_calculation(operation, column_name, distinct)
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
72
94
|
end
|
73
95
|
end
|
74
96
|
|
data/lib/left_joins/version.rb
CHANGED