left_joins 1.0.1 → 1.0.2

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: 9fe2a83d6cffc287bbf6724737c4e8dbfbe3ea6f
4
- data.tar.gz: 2838cceb023ba1586a31efddc33aaac6349ad4f6
3
+ metadata.gz: 7e53341751b336f45518a17f999a01edce0a82e2
4
+ data.tar.gz: d846380c736ba9b8c6e08a3f354b8b2cb23b0dcc
5
5
  SHA512:
6
- metadata.gz: 655ca8dad040ed55ee43eab786bc935e27afd74c3dfc43a3462ba3ab98232bb5c0e85121ee66c739e51a92522672562de94bd4e60d5ec5867b03530edc7296ba
7
- data.tar.gz: 0f55aa90871bd786842f941c3446dae67c221554d31c7f56ca850a2cf59f4024d7ce8e5f50b33ae1e98d8810a8819a67bdacf29c9c03b53700b4f9223c95852f
6
+ metadata.gz: e84494efa9cb604ca6f03499e009b186a3e3d936e7824f403026dcf9faecb25a6a7b64ec6277a19b06328cc9751e4649e0f80f90d20899174e15dc409493695a
7
+ data.tar.gz: 819bfefd4723df868dcfc2f038ed12b1772453f3c9ecded4991fb702f29c4a148e27c78415eefde05c64068729fabfa35319dc6783bf0c4ebc2ce3aa57e98cc4
@@ -31,6 +31,7 @@ Gem::Specification.new do |spec|
31
31
  spec.add_development_dependency "rake", "~> 12.0"
32
32
  spec.add_development_dependency "sqlite3", "~> 1.3"
33
33
  spec.add_development_dependency "minitest", "~> 5.0"
34
+ spec.add_development_dependency "pluck_all", ">= 1.2.3"
34
35
 
35
36
  spec.add_dependency "activerecord", ">= 3"
36
37
 
@@ -2,9 +2,16 @@ require "left_joins/version"
2
2
  require 'active_record'
3
3
  require 'active_record/relation'
4
4
 
5
- module ActiveRecord::QueryMethods
5
+ module LeftJoins
6
6
  IS_RAILS3_FLAG = Gem::Version.new(ActiveRecord::VERSION::STRING) < Gem::Version.new('4.0.0')
7
- if IS_RAILS3_FLAG
7
+ end
8
+
9
+ module ActiveRecord::QueryMethods
10
+
11
+ # ----------------------------------------------------------------
12
+ # ● Implement check_if_method_has_arguments! method for Rails 3
13
+ # ----------------------------------------------------------------
14
+ if LeftJoins::IS_RAILS3_FLAG
8
15
  def check_if_method_has_arguments!(method_name, args)
9
16
  if args.blank?
10
17
  raise ArgumentError, "The method .#{method_name}() must contain arguments."
@@ -12,13 +19,17 @@ module ActiveRecord::QueryMethods
12
19
  end
13
20
  end
14
21
  if not method_defined?(:left_outer_joins!)
22
+ # ----------------------------------------------------------------
23
+ # ● Storing left joins values into @left_outer_joins_values
24
+ # ----------------------------------------------------------------
25
+ attr_accessor :left_outer_joins_values
15
26
  def left_outer_joins(*args)
16
27
  check_if_method_has_arguments!(:left_outer_joins, args)
17
28
 
18
29
  args.compact!
19
30
  args.flatten!
20
31
 
21
- return (IS_RAILS3_FLAG ? clone : spawn).left_outer_joins!(*args)
32
+ return (LeftJoins::IS_RAILS3_FLAG ? clone : spawn).left_outer_joins!(*args)
22
33
  end
23
34
 
24
35
  def left_outer_joins!(*args)
@@ -26,6 +37,9 @@ module ActiveRecord::QueryMethods
26
37
  self
27
38
  end
28
39
 
40
+ # ----------------------------------------------------------------
41
+ # ● Implement left joins when building arel
42
+ # ----------------------------------------------------------------
29
43
  alias_method :left_joins, :left_outer_joins
30
44
  alias_method :build_arel_without_outer_joins, :build_arel
31
45
  def build_arel(*args)
@@ -55,7 +69,7 @@ module ActiveRecord::QueryMethods
55
69
  end
56
70
 
57
71
  class ::ActiveRecord::Associations::JoinDependency
58
- if IS_RAILS3_FLAG
72
+ if LeftJoins::IS_RAILS3_FLAG
59
73
  alias_method :build_without_hooking_join_type, :build
60
74
  def build(associations, parent = nil, join_type = Arel::Nodes::InnerJoin)
61
75
  join_type = Thread.current.thread_variable_get :left_joins_join_type || join_type
@@ -76,7 +90,7 @@ module ActiveRecord::QueryMethods
76
90
 
77
91
  # If #count is used with #distinct (i.e. `relation.distinct.count`) it is
78
92
  # considered distinct.
79
- distinct = IS_RAILS3_FLAG ? options[:distinct] || self.uniq_value : self.distinct_value
93
+ distinct = LeftJoins::IS_RAILS3_FLAG ? options[:distinct] || self.uniq_value : self.distinct_value
80
94
 
81
95
  if operation == "count"
82
96
  column_name ||= select_for_count
@@ -94,3 +108,33 @@ module ActiveRecord::QueryMethods
94
108
  end
95
109
  end
96
110
 
111
+ # ----------------------------------------------------------------
112
+ # ● Implement left joins when merging relations
113
+ # ----------------------------------------------------------------
114
+ if not LeftJoins::IS_RAILS3_FLAG
115
+ require 'active_record/relation/merger'
116
+ class ActiveRecord::Relation
117
+ class Merger
118
+ alias_method :merge_without_left_joins, :merge
119
+ def merge
120
+ values = other.left_outer_joins_values
121
+ relation.left_outer_joins!(*values) if values.present?
122
+ return merge_without_left_joins
123
+ end
124
+ end
125
+ end
126
+
127
+ module ActiveRecord
128
+ module SpawnMethods
129
+
130
+ private
131
+
132
+ alias_method :relation_with_without_left_joins, :relation_with
133
+ def relation_with(values) # :nodoc:
134
+ result = relation_with_without_left_joins(values)
135
+ result.left_outer_joins_values = self.left_outer_joins_values
136
+ return result
137
+ end
138
+ end
139
+ end
140
+ end
@@ -1,3 +1,3 @@
1
1
  module LeftJoins
2
- VERSION = "1.0.1"
2
+ VERSION = "1.0.2"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: left_joins
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - khiav reoy
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-12-25 00:00:00.000000000 Z
11
+ date: 2018-01-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -66,6 +66,20 @@ dependencies:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: '5.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: pluck_all
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: 1.2.3
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: 1.2.3
69
83
  - !ruby/object:Gem::Dependency
70
84
  name: activerecord
71
85
  requirement: !ruby/object:Gem::Requirement