active_record_query_fixer 0.0.2 → 0.0.3

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: 3bf2b49f0a63f435b0f58e0658e018a3d738728f
4
- data.tar.gz: f8985015577b6c039a5fca1f6ca0a3f42bbf95a8
3
+ metadata.gz: 87c898d6d7d8bd5a191024b09c414d29496a34e2
4
+ data.tar.gz: 5a6405a8f8d1dfdb6a2a2de53081c90c8184f0a5
5
5
  SHA512:
6
- metadata.gz: f55ef85d975ec9a09126a88f030a50ea8b1a9f2f61332db9e4eca55a3cbb69ffb22d5a3484ab9e9a5781a69d603e298e96c29d333fc69f2abe92cc32a7b57b5f
7
- data.tar.gz: 27670b512d1c16e700145195d791cc81c90e8c9e66ef6e064523a39b49ce8f282a0cdc5e25c613b1c35fd5e4ea107b9a5febd394277d2334bd4d30a08a94c5cb
6
+ metadata.gz: 0cc9600b2a48b33ef00a0dc61956a5225ffbef4a029d68e3c66d30b2ac98c008cf059fb24408cc2dc9b0b80b68487a4e83c6b04d847a32fef5c64de06a533ac3
7
+ data.tar.gz: 28b261d8608b7645d3063a05f465d97d0e62206210c69883e9a335098b7d5af4f1d2d318e0a024eab8a02cab32c94912a98c004167ea1fabed4fc33b2e40ddfc
@@ -0,0 +1,5 @@
1
+ module ActiveRecordQueryFixer::RelationExtentions
2
+ def fix
3
+ ActiveRecordQueryFixer.fix(self)
4
+ end
5
+ end
@@ -1,3 +1,3 @@
1
1
  class ActiveRecordQueryFixer
2
- VERSION = "0.0.2".freeze
2
+ VERSION = "0.0.3".freeze
3
3
  end
@@ -1,4 +1,6 @@
1
1
  class ActiveRecordQueryFixer
2
+ autoload :RelationExtentions, "#{__dir__}/active_record_query_fixer/relation_extentions"
3
+
2
4
  attr_reader :query
3
5
 
4
6
  def self.fix(query)
@@ -19,7 +21,7 @@ class ActiveRecordQueryFixer
19
21
  def fix_order_group
20
22
  @query = @query.group("#{@query.model.table_name}.#{@query.model.primary_key}")
21
23
 
22
- @query.values[:order].each do |order|
24
+ @query&.values[:order]&.each do |order|
23
25
  @query = @query.group(extract_table_and_column_from_expression(order))
24
26
  end
25
27
 
@@ -28,7 +30,7 @@ class ActiveRecordQueryFixer
28
30
 
29
31
  def fix_order_select_distinct
30
32
  changed = false
31
- @query.values[:order].each do |order|
33
+ @query&.values[:order]&.each do |order|
32
34
  @query = @query.select("#{extract_table_and_column_from_expression(order)} AS active_record_query_fixer_#{@count_select}")
33
35
  changed = true
34
36
  @count_select += 1
@@ -55,10 +57,12 @@ private
55
57
  end
56
58
 
57
59
  def fix_order_group?
58
- @query.values[:joins].blank? && @query.values[:distinct].present?
60
+ @query&.values[:joins]&.blank? && @query&.values[:distinct]&.present?
59
61
  end
60
62
 
61
63
  def fix_order_select_distinct?
62
- @query.values[:distinct].present?
64
+ @query&.values[:distinct]&.present?
63
65
  end
64
66
  end
67
+
68
+ ActiveRecord::Relation.include ActiveRecordQueryFixer::RelationExtentions
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_record_query_fixer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - kaspernj
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-04-16 00:00:00.000000000 Z
11
+ date: 2018-06-03 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: A library for automatically added `.select` on a column used for `.distinct`
14
14
  or automatically adding `.group` for a column used for order.
@@ -22,6 +22,7 @@ files:
22
22
  - README.md
23
23
  - Rakefile
24
24
  - lib/active_record_query_fixer.rb
25
+ - lib/active_record_query_fixer/relation_extentions.rb
25
26
  - lib/active_record_query_fixer/version.rb
26
27
  - lib/tasks/active_record_query_fixer_tasks.rake
27
28
  homepage: https://www.github.com/kaspernj/active_record_query_fixer
@@ -44,7 +45,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
44
45
  version: '0'
45
46
  requirements: []
46
47
  rubyforge_project:
47
- rubygems_version: 2.6.8
48
+ rubygems_version: 2.6.13
48
49
  signing_key:
49
50
  specification_version: 4
50
51
  summary: A library for automatically added `.select` on a column used for `.distinct`