superstore 2.4.2 → 2.4.3
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 +4 -4
- data/lib/superstore/adapters/jsonb_adapter.rb +12 -1
- data/lib/superstore/base.rb +1 -0
- data/lib/superstore/persistence.rb +5 -16
- data/superstore.gemspec +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bff1f7868f9525ae36d1a003c33422d12fea5e8e
|
4
|
+
data.tar.gz: eb8cfbe4048d28e3b7097bad7f51d36e8fde1aa5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
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
|
data/lib/superstore/base.rb
CHANGED
@@ -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
|
-
|
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
|
data/superstore.gemspec
CHANGED
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.
|
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-
|
12
|
+
date: 2016-11-23 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activemodel
|