superstore 2.2.0 → 2.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5693d8b8ef6d996873be8b90469953d6d43da3d9
4
- data.tar.gz: 3441e366eb68a131363c9d8376905bc3c4dfd68a
3
+ metadata.gz: efa28ad8771bdcf6a918cf33a4d81f3e6945581a
4
+ data.tar.gz: 732be1d35bf085bc141c1772d7beef1e1655f397
5
5
  SHA512:
6
- metadata.gz: f9b800bb4f54c8e9bda088ebc7dbe97fb64eea4bc84f3e601658495b0d9afeb897a03738de445bf55c4527128f1d8a7fa2845663df1164deb68aef1d973054bf
7
- data.tar.gz: 2324d4e9d7cff4f03db292828eee93973e138b38637a206eae00f9b04889e595b0656d6711abf3456586159f6550eb8a8e53cf55fbc1134b7b406df722956cf9
6
+ metadata.gz: c8f18bbcabe090e89e0ff5a19058689b7e2002488be9332c666e62cc556e78a58573918e27081c48f13eb9ed30c26a60cab90d6c39abe0f0e2522f6e90770786
7
+ data.tar.gz: bfc9b5f6637f4955ad45753f0a2996be1f5892aba8ac15646ee9deb4194237b2300c1d57ef42c22e310f8e6e261aedc7c75bcdca58fc40a5fad36395a0f2c0da
data/.travis.yml CHANGED
@@ -1,9 +1,23 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 2.0.0-p647
4
- - 2.1.7
5
- - 2.2.3
6
- sudo: false
3
+ - 2.1.10
4
+ - 2.2.5
5
+ - 2.3.1
6
+ sudo: required
7
+ dist: trusty
7
8
  cache: bundler
8
- addons:
9
- postgresql: '9.4'
9
+ before_install:
10
+ # https://github.com/travis-ci/travis-ci/issues/4264
11
+ - sudo cp /etc/postgresql/9.4/main/pg_hba.conf /tmp
12
+ - sudo add-apt-repository "deb http://apt.postgresql.org/pub/repos/apt/ $(lsb_release -cs)-pgdg 9.5"
13
+ - sudo apt-key adv --keyserver keys.gnupg.net --recv-keys 7FCC7D46ACCC4CF8
14
+ - sudo apt-get update
15
+ - sudo service postgresql stop
16
+ - for version in 9.1 9.2 9.3 9.4; do sudo pg_dropcluster --stop $version main; done
17
+ - sudo apt-get remove --purge --yes postgresql-9.[1234]
18
+ - sudo apt-get install --no-install-recommends --yes postgresql-client-9.5 postgresql-9.5
19
+ - sudo apt-get autoremove --yes
20
+ - sudo cp /tmp/pg_hba.conf /etc/postgresql/9.5/main/
21
+ - sudo service postgresql restart
22
+ - sudo -u postgres createuser -s travis
23
+ - sudo -u postgres createdb -O travis travis
data/CHANGELOG.md CHANGED
@@ -1,3 +1,11 @@
1
+ # 2.2.0
2
+
3
+ Released 2016-06-02.
4
+
5
+ ## New Features
6
+
7
+ * Add `geo_point` type.
8
+
1
9
  # 2.1.2
2
10
 
3
11
  Released 2016-05-04.
data/Rakefile CHANGED
@@ -1,12 +1,9 @@
1
- require 'bundler/setup'
2
- require 'rake'
1
+ require 'bundler/gem_tasks'
3
2
  require 'rake/testtask'
4
3
 
5
4
  task default: :test
6
5
 
7
6
  Rake::TestTask.new(:test) do |t|
8
- t.libs << 'lib'
9
- t.libs << 'test'
7
+ t.libs = %w(lib test)
10
8
  t.pattern = 'test/unit/**/*_test.rb'
11
- t.verbose = true
12
9
  end
@@ -30,7 +30,8 @@ module Superstore
30
30
  elsif @scope.select_values == [@adapter.primary_key_column]
31
31
  @adapter.primary_key_column
32
32
  else
33
- "#{@adapter.primary_key_column}, jsonb_slice(document, #{@adapter.fields_to_postgres_array(@scope.select_values)}) as document"
33
+ selects = @scope.select_values.map { |key| "#{@adapter.quote(key)},document->>#{@adapter.quote(key)}" }
34
+ "#{@adapter.primary_key_column}, json_build_object(#{selects * ','}) as document"
34
35
  end
35
36
  end
36
37
 
@@ -142,18 +143,9 @@ module Superstore
142
143
  def update(table, id, attributes)
143
144
  return if attributes.empty?
144
145
 
145
- not_nil_attributes = attributes.reject { |key, value| value.nil? }
146
- nil_attributes = attributes.select { |key, value| value.nil? }
147
-
148
- if not_nil_attributes.any? && nil_attributes.any?
149
- value_update = "jsonb_merge(jsonb_delete(document, #{fields_to_postgres_array(nil_attributes.keys)}), #{to_quoted_jsonb(not_nil_attributes)})"
150
- elsif not_nil_attributes.any?
151
- value_update = "jsonb_merge(document, #{to_quoted_jsonb(not_nil_attributes)})"
152
- elsif nil_attributes.any?
153
- value_update = "jsonb_delete(document, #{fields_to_postgres_array(nil_attributes.keys)})"
154
- end
155
-
146
+ value_update = "jsonb_strip_nulls(document || #{to_quoted_jsonb(attributes)})"
156
147
  statement = "UPDATE #{table} SET document = #{value_update} WHERE #{primary_key_column} = #{quote(id)}"
148
+
157
149
  execute_batchable statement
158
150
  end
159
151
 
@@ -205,54 +197,6 @@ module Superstore
205
197
  def to_quoted_jsonb(data)
206
198
  "#{quote(Oj.dump(data, OJ_OPTIONS))}::JSONB"
207
199
  end
208
-
209
- JSON_FUNCTIONS = {
210
- # SELECT jsonb_slice('{"b": 2, "c": 3, "a": 4}', '{b, c}');
211
- 'jsonb_slice(data jsonb, keys text[])' => %{
212
- SELECT json_object_agg(key, value)::jsonb
213
- FROM (
214
- SELECT * FROM jsonb_each(data)
215
- ) t
216
- WHERE key =ANY(keys);
217
- },
218
-
219
- # SELECT jsonb_merge('{"a": 1}', '{"b": 2, "c": 3, "a": 4}');
220
- 'jsonb_merge(data jsonb, merge_data jsonb)' => %{
221
- SELECT json_object_agg(key, value)::jsonb
222
- FROM (
223
- WITH to_merge AS (
224
- SELECT * FROM jsonb_each(merge_data)
225
- )
226
- SELECT *
227
- FROM jsonb_each(data)
228
- WHERE key NOT IN (SELECT key FROM to_merge)
229
- UNION ALL
230
- SELECT * FROM to_merge
231
- ) t;
232
- },
233
-
234
- # SELECT jsonb_delete('{"b": 2, "c": 3, "a": 4}', '{b, c}');
235
- 'jsonb_delete(data jsonb, keys text[])' => %{
236
- SELECT json_object_agg(key, value)::jsonb
237
- FROM (
238
- SELECT * FROM jsonb_each(data)
239
- WHERE key <>ALL(keys)
240
- ) t;
241
- },
242
- }
243
- def define_jsonb_functions!
244
- JSON_FUNCTIONS.each do |signature, body|
245
- connection.execute %{
246
- CREATE OR REPLACE FUNCTION public.#{signature}
247
- RETURNS jsonb
248
- IMMUTABLE
249
- LANGUAGE sql
250
- AS $$
251
- #{body}
252
- $$;
253
- }
254
- end
255
- end
256
200
  end
257
201
  end
258
202
  end
data/superstore.gemspec CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = 'superstore'
5
- s.version = '2.2.0'
5
+ s.version = '2.3.0'
6
6
  s.description = 'ActiveModel for many attributes'
7
7
  s.summary = 'JSONB ActiveModel'
8
8
  s.authors = ["Michael Koziarski", "Infogroup"]
@@ -1,7 +1,6 @@
1
1
  class JsonbInitializer
2
2
  def self.initialize!
3
3
  Superstore::Base.adapter.create_table('issues')
4
- Superstore::Base.adapter.define_jsonb_functions!
5
4
  end
6
5
  end
7
6
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: superstore
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.0
4
+ version: 2.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Koziarski
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-06-02 00:00:00.000000000 Z
12
+ date: 2016-06-29 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activemodel