pluck_all 2.0.2 → 2.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: f4e9c99236d4d19b7bce24b3d03f816856c12bf2
4
- data.tar.gz: 32b12e58e910477f6b07309cbd36517ceeb1bc03
3
+ metadata.gz: c81452c77b812b47946aa8f1b7d8d42722724707
4
+ data.tar.gz: 1eb4b3f65fd32ecd32065f0cb34938759c3a7ac8
5
5
  SHA512:
6
- metadata.gz: 609f211a5cec23ea23ed82e9e817eb65fbbe8dba4e06773b1cb996deaa0672aba6f5b5d93fb895701c952c4486a1ee7331fa039f4580ee46d099843314612867
7
- data.tar.gz: 2700b74ec0c40ba5cc8c3deb69ac432b9cd7857c1de01a91efdf466cf539888418eefa8fe0b7d5d1f836e9d6a6382a16a32ff8afb652d3854c1a8fa93eea6d51
6
+ metadata.gz: ec691ecc0da995f34ac68785b8d9d36318e008435a9847301e6cea6769e5fa9e998fbb439fe1c0facf9f7c41dc6656b5b42bcfd146de329f0557cbb7ca0f18ce
7
+ data.tar.gz: 72302a9cfacab2337a4919eb1f7f69ffc6003c47c804231eb91ceac46847f94e2948de4c514cedcbe6fc0452eefc0e728b7928fc71368bacf26475a314dc475f
@@ -1,5 +1,10 @@
1
1
  ## Change Log
2
2
 
3
+ ### [upcoming](https://github.com/khiav223577/pluck_all/compare/v2.0.1...HEAD) 2018/06/29
4
+ - [#28](https://github.com/khiav223577/pluck_all/pull/28) Fix test cases and the result format may be wrong when plucking multiple columns with nil value may (@khiav223577)
5
+ - [#27](https://github.com/khiav223577/pluck_all/pull/27) [Feature] Mongoid Hooks And Tests Separation (@berniechiu)
6
+ - [#26](https://github.com/khiav223577/pluck_all/pull/26) [FIX] Wrong Module Skipped (@berniechiu)
7
+
3
8
  ### [v2.0.1](https://github.com/khiav223577/pluck_all/compare/v2.0.0...v2.0.1) 2018/05/27
4
9
  - [#25](https://github.com/khiav223577/pluck_all/pull/25) Fix that project without mongoid will raise LoadError (@khiav223577)
5
10
 
@@ -22,9 +22,21 @@ module ActiveRecord
22
22
  end
23
23
 
24
24
  class ActiveRecord::Relation
25
+ def cast_need_columns(column_names, _klass = nil)
26
+ @pluck_all_cast_need_columns = column_names.map(&:to_s)
27
+ @pluck_all_cast_klass = _klass
28
+ return self
29
+ end
30
+
31
+ def select_all(*column_names)
32
+ relation = clone
33
+ return klass.connection.select_all(relation.select(column_names).to_sql)
34
+ end
35
+
25
36
  if Gem::Version.new(ActiveRecord::VERSION::STRING) < Gem::Version.new('4.0.0')
26
- def pluck_all(*args, cast_uploader_url: true)
27
- result = select_all(*args)
37
+ def pluck_all(*column_names, cast_uploader_url: true)
38
+ column_names.map!(&to_sql_column_name)
39
+ result = select_all(*column_names)
28
40
  result.map! do |attributes| # This map! behaves different to array#map!
29
41
  initialized_attributes = klass.initialize_attributes(attributes)
30
42
  attributes.each do |key, attribute|
@@ -34,9 +46,23 @@ class ActiveRecord::Relation
34
46
  next attributes
35
47
  end
36
48
  end
49
+
50
+ private
51
+
52
+ def to_sql_column_name
53
+ proc do |column_name|
54
+ if column_name.is_a?(Symbol) && column_names.include?(column_name.to_s)
55
+ "#{connection.quote_table_name(table_name)}.#{connection.quote_column_name(column_name)}"
56
+ else
57
+ column_name.to_s
58
+ end
59
+ end
60
+ end
37
61
  else
38
- def pluck_all(*args, cast_uploader_url: true)
39
- result = select_all(*args)
62
+ def pluck_all(*column_names, cast_uploader_url: true)
63
+ column_names.map!(&to_sql_column_name)
64
+ return construct_relation_for_association_calculations.pluck_all(*column_names) if has_include?(column_names.first)
65
+ result = select_all(*column_names)
40
66
  attribute_types = klass.attribute_types
41
67
  result.map! do |attributes| # This map! behaves different to array#map!
42
68
  attributes.each do |key, attribute|
@@ -46,27 +72,18 @@ class ActiveRecord::Relation
46
72
  next attributes
47
73
  end
48
74
  end
49
- end
50
75
 
51
- def cast_need_columns(column_names, _klass = nil)
52
- @pluck_all_cast_need_columns = column_names.map(&:to_s)
53
- @pluck_all_cast_klass = _klass
54
- return self
55
- end
56
-
57
- private
76
+ private
58
77
 
59
- def select_all(*args)
60
- args.map! do |column_name|
61
- if column_name.is_a?(Symbol) && column_names.include?(column_name.to_s)
62
- "#{connection.quote_table_name(table_name)}.#{connection.quote_column_name(column_name)}"
63
- else
64
- column_name.to_s
78
+ def to_sql_column_name
79
+ proc do |column_name|
80
+ if column_name.is_a?(Symbol) && attribute_alias?(column_name)
81
+ attribute_alias(column_name)
82
+ else
83
+ column_name.to_s
84
+ end
65
85
  end
66
86
  end
67
- relation = clone
68
- return klass.connection.select_all(relation.select(args).to_sql)
69
- #return klass.connection.select_all(relation.arel)
70
87
  end
71
88
 
72
89
  # ----------------------------------------------------------------
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module PluckAll
3
- VERSION = '2.0.2'
3
+ VERSION = '2.0.3'
4
4
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pluck_all
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.2
4
+ version: 2.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - khiav reoy
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-06-29 00:00:00.000000000 Z
11
+ date: 2018-07-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport