superstore 2.4.2 → 2.4.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: af5b7a4f7df6e0232687243d560e264dcaacd2f7
4
- data.tar.gz: ab924e212308d0b1dc27188f98c50956b40b0f5d
3
+ metadata.gz: bff1f7868f9525ae36d1a003c33422d12fea5e8e
4
+ data.tar.gz: eb8cfbe4048d28e3b7097bad7f51d36e8fde1aa5
5
5
  SHA512:
6
- metadata.gz: 1eb40fa34f43ba5646a636b967caf19daa6a0feac9077f5f41a3285422b7957a142da13b7facb8898f36a4f665211fc2b2b1672e288c69b1a18203b2356e2d78
7
- data.tar.gz: 93d4b920deb331bf6c8173154c56222b4be68777cd0cee0ba2acacb674f0d1fe4da0ef78c51bd93e2058ea867d4285b164f2b62c596a5278f4f340ae2c6a4e3f
6
+ metadata.gz: 41d1fc61dcad51d35ac4feb6d46ff3cad2dd423ea39b1070b275f1cfd0a0a5f51279e10866e823a8ea4925f1d57fc42157b9bb3c10ad401acd8c688d300a5dcf
7
+ data.tar.gz: fb7104cda38cc586278b0ac28ee1330ab1d97705e11bff14379d01f255d1fc12fadcded56b41d5b00cd236e630ad41f961dae7b35d1ff4adf73d5dcfc45ead6c
@@ -143,7 +143,18 @@ module Superstore
143
143
  def update(table, id, attributes)
144
144
  return if attributes.empty?
145
145
 
146
- value_update = "jsonb_strip_nulls(document || #{to_quoted_jsonb(attributes)})"
146
+ nil_properties = attributes.each_key.select { |k| attributes[k].nil? }
147
+ not_nil_attributes = attributes.reject { |key, value| value.nil? }
148
+
149
+ value_update = "document"
150
+ nil_properties.each do |property|
151
+ value_update = "(#{value_update} - '#{property}')"
152
+ end
153
+
154
+ if not_nil_attributes.any?
155
+ value_update = "(#{value_update} || #{to_quoted_jsonb(not_nil_attributes)})"
156
+ end
157
+
147
158
  statement = "UPDATE #{table} SET document = #{value_update} WHERE #{primary_key_column} = #{quote(id)}"
148
159
 
149
160
  execute_batchable statement
@@ -13,6 +13,7 @@ module Superstore
13
13
 
14
14
  extend ActiveRecord::Delegation::DelegateCache
15
15
  extend ActiveRecord::ConnectionHandling
16
+ include ActiveRecord::Persistence
16
17
  include ActiveRecord::ModelSchema
17
18
  include ActiveRecord::Inheritance
18
19
  include ActiveRecord::Attributes
@@ -15,12 +15,6 @@ module Superstore
15
15
  adapter.execute "TRUNCATE #{table_name}"
16
16
  end
17
17
 
18
- def create(attributes = {}, &block)
19
- new(attributes, &block).tap do |object|
20
- object.save
21
- end
22
- end
23
-
24
18
  def insert_record(id, attributes)
25
19
  adapter.insert table_name, id, encode_attributes(attributes)
26
20
  end
@@ -91,7 +85,7 @@ module Superstore
91
85
  end
92
86
 
93
87
  def save(*)
94
- new_record? ? create_self : update_self
88
+ create_or_update
95
89
  end
96
90
 
97
91
  def destroy
@@ -119,15 +113,6 @@ module Superstore
119
113
 
120
114
  alias update_attributes! update!
121
115
 
122
- def becomes(klass)
123
- became = klass.new
124
- became.instance_variable_set("@attributes", @attributes)
125
- became.instance_variable_set("@changed_attributes", changed_attributes || {})
126
- became.instance_variable_set("@new_record", new_record?)
127
- became.instance_variable_set("@destroyed", destroyed?)
128
- became
129
- end
130
-
131
116
  def reload
132
117
  clear_association_cache
133
118
  @attributes = self.class.find(id).instance_variable_get('@attributes')
@@ -136,6 +121,10 @@ module Superstore
136
121
 
137
122
  private
138
123
 
124
+ def create_or_update
125
+ new_record? ? create_self : update_self
126
+ end
127
+
139
128
  def create_self
140
129
  write :insert_record
141
130
  end
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = 'superstore'
5
- s.version = '2.4.2'
5
+ s.version = '2.4.3'
6
6
  s.description = 'ActiveModel-based JSONB document store'
7
7
  s.summary = 'ActiveModel for JSONB documents'
8
8
  s.authors = ['Michael Koziarski', 'Infogroup']
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.4.2
4
+ version: 2.4.3
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-09-26 00:00:00.000000000 Z
12
+ date: 2016-11-23 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activemodel