pluck_map 0.6.0 → 0.6.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
  SHA256:
3
- metadata.gz: b299dd06b71f709f45a8b9df4e52b20c70785976a3502f5b2402f0f340da8160
4
- data.tar.gz: d4d4e2f78031b5fe3fa8c6492885bc2bfa17b73f30825c60fede8f10fec2e13c
3
+ metadata.gz: 719535934f95bc4fe3db48d59fb8f8c762f23260c6438763672612d82ea12feb
4
+ data.tar.gz: ada8d0481118adc7d04f47b3b801e826e4b07a60d07d0d063ef10a652c891568
5
5
  SHA512:
6
- metadata.gz: b6da4c576698798f98ac790f81a8dd4ff4f4b07b27212ef3c43f4d54966d04d139ff082f79b86a163abcaf3d3d64a27119c5cd84705baa32c7c39a7b3c369979
7
- data.tar.gz: 9862dd28a87a7e82385f14eeb3a055672aac462cf0f2496ec8a189fa476d51c74a24711780ab1c84640c568f92053cb872d75c88834f094a6dd7399ca948e836
6
+ metadata.gz: 9d35814e0ef40d24e7ff441250c692880116540f6668ef79ce047da3424e7ff98203964e013f81c4d32d100d4f29e3e3995beb74f7f166ffa4597e5653e893f3
7
+ data.tar.gz: c887937585d78ef34a9d44e7fedf9ad7810ba9dd5d54525b90c577ca77eaef9450575986adb43c5f9d97d874903a688bf3f81ab538f03b520d4fa849ce0bef7f
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## v0.6.1 (2019 May 12)
2
+
3
+ * FIX: Aliased SQL expressions to work-around a bug with Rails Postgres adapter (@kobsy)
4
+
1
5
  ## v0.6.0 (2019 May 5)
2
6
 
3
7
  * REFACTOR: Deprecated `Presenter#no_map?` and introduced `Attributes#will_map?` to replace it (@boblail)
@@ -1,5 +1,6 @@
1
1
  require "pluck_map/attribute_builder"
2
2
  require "pluck_map/presenters"
3
+ require "active_record"
3
4
 
4
5
  module PluckMap
5
6
  class Presenter
@@ -56,7 +57,32 @@ module PluckMap
56
57
  end
57
58
 
58
59
  def selects
59
- attributes.selects
60
+ @selects ||= attributes.selects.map.with_index { |select, index|
61
+
62
+ # Workaround for a bug that exists in Rails at the time of this commit.
63
+ # See:
64
+ #
65
+ # https://github.com/rails/rails/pull/36186
66
+ #
67
+ # Prior to the PR above, Rails will treat two results that have the
68
+ # same name as having the same type. On Postgres, values that are the
69
+ # result of an expression are given the name of the last function
70
+ # called in the expression. For example:
71
+ #
72
+ # psql> SELECT COALESCE(NULL, 'four'), COALESCE(NULL, 4);
73
+ # coalesce | coalesce
74
+ # ----------+----------
75
+ # four | 4
76
+ # (1 row)
77
+ #
78
+ # This patch mitigates that problem by aliasing SQL expressions before
79
+ # they are used in select statements.
80
+ select = select.as("__pluckmap_#{index}") if select.respond_to?(:as)
81
+
82
+ # On Rails 4.2, `pluck` can't accept Arel nodes
83
+ select = Arel.sql(select.to_sql) if ActiveRecord.version.segments.take(2) == [4,2] && select.respond_to?(:to_sql)
84
+ select
85
+ }
60
86
  end
61
87
 
62
88
  def attributes_by_id
@@ -1,3 +1,3 @@
1
1
  module PluckMapPresenter
2
- VERSION = "0.6.0"
2
+ VERSION = "0.6.1"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pluck_map
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.6.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bob Lail
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-05-06 00:00:00.000000000 Z
11
+ date: 2019-05-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord