left_joins 1.0.0 → 1.0.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: 5362727169b04c38c3b37c234c0b3715c2132286
4
- data.tar.gz: becd033a2f61633f2de9b789b76663c2a8aa8650
3
+ metadata.gz: 9fe2a83d6cffc287bbf6724737c4e8dbfbe3ea6f
4
+ data.tar.gz: 2838cceb023ba1586a31efddc33aaac6349ad4f6
5
5
  SHA512:
6
- metadata.gz: 24d64ceda8105b8766566cc76f12e2ef0d499489e5c3b45ae08e4c215b93918b7d5478056db1154c93a3967289ac5c4bc03c8212e6d660d29a91488285f404ac
7
- data.tar.gz: 76bb7ab2512b61e17c061460a8d2d439fc346d290be078b0a954f2b509018a72f6c77e495d37965cd099828ec0efc3a3c42df74f7ddd6ea8885f98cc54b46342
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 not method_defined?(:check_if_method_has_arguments!)
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
 
@@ -1,3 +1,3 @@
1
1
  module LeftJoins
2
- VERSION = "1.0.0"
2
+ VERSION = "1.0.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: left_joins
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - khiav reoy