pg_serializable 2.0.0 → 3.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +19 -22
- data/README.md +18 -1
- data/lib/pg_serializable.rb +1 -2
- data/lib/pg_serializable/version.rb +1 -1
- data/lib/pg_serializable/visitors/json.rb +2 -2
- data/pg_serializable.gemspec +3 -5
- metadata +21 -38
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 181c689aa09605b1f74bbffdb786891117b964e594cab8eb9937407d6d05e9d0
|
4
|
+
data.tar.gz: 3abdee223e868fa8f569df557a624aa5d9181e87ca5c536c3e1223273bb80c91
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9976896c041b29e6f56026e9198ef89c6840821c4dd3926f6a26c4b78b8154a382879e51b73d40ab47a901adcd12d2434a70bfea80c8e17e564bb3a4ee355c56
|
7
|
+
data.tar.gz: a0d234f3602ee53002036a5a3fc9b2bb89e6920339a55fe9551029551fc6e027dd4e6c5160da04e833a93e327f8cc7cd3a8cd6f6658830ef6d0ecf1eb3ed3ee4
|
data/Gemfile.lock
CHANGED
@@ -1,50 +1,47 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
pg_serializable (
|
5
|
-
activerecord (
|
6
|
-
activesupport (
|
7
|
-
oj (~> 3.6)
|
4
|
+
pg_serializable (3.0.2)
|
5
|
+
activerecord (>= 5.2, < 7.0)
|
6
|
+
activesupport (>= 5.2, < 7.0)
|
8
7
|
pg (>= 1.1)
|
9
8
|
|
10
9
|
GEM
|
11
10
|
remote: https://rubygems.org/
|
12
11
|
specs:
|
13
|
-
activemodel (
|
14
|
-
activesupport (=
|
15
|
-
activerecord (
|
16
|
-
activemodel (=
|
17
|
-
activesupport (=
|
18
|
-
|
19
|
-
activesupport (5.2.3)
|
12
|
+
activemodel (6.0.3.1)
|
13
|
+
activesupport (= 6.0.3.1)
|
14
|
+
activerecord (6.0.3.1)
|
15
|
+
activemodel (= 6.0.3.1)
|
16
|
+
activesupport (= 6.0.3.1)
|
17
|
+
activesupport (6.0.3.1)
|
20
18
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
21
19
|
i18n (>= 0.7, < 2)
|
22
20
|
minitest (~> 5.1)
|
23
21
|
tzinfo (~> 1.1)
|
24
|
-
|
22
|
+
zeitwerk (~> 2.2, >= 2.2.2)
|
25
23
|
codecov (0.1.14)
|
26
24
|
json
|
27
25
|
simplecov
|
28
26
|
url
|
29
27
|
coderay (1.1.2)
|
30
|
-
concurrent-ruby (1.1.
|
28
|
+
concurrent-ruby (1.1.6)
|
31
29
|
database_cleaner (1.7.0)
|
32
30
|
diff-lcs (1.3)
|
33
31
|
docile (1.3.1)
|
34
32
|
factory_bot (5.0.2)
|
35
33
|
activesupport (>= 4.2.0)
|
36
34
|
ffaker (2.11.0)
|
37
|
-
i18n (1.
|
35
|
+
i18n (1.8.2)
|
38
36
|
concurrent-ruby (~> 1.0)
|
39
37
|
json (2.2.0)
|
40
38
|
method_source (0.9.2)
|
41
|
-
minitest (5.
|
42
|
-
|
43
|
-
pg (1.1.4)
|
39
|
+
minitest (5.14.1)
|
40
|
+
pg (1.2.3)
|
44
41
|
pry (0.12.2)
|
45
42
|
coderay (~> 1.1.0)
|
46
43
|
method_source (~> 0.9.0)
|
47
|
-
rake (
|
44
|
+
rake (13.0.1)
|
48
45
|
rspec (3.8.0)
|
49
46
|
rspec-core (~> 3.8.0)
|
50
47
|
rspec-expectations (~> 3.8.0)
|
@@ -64,23 +61,23 @@ GEM
|
|
64
61
|
simplecov-html (~> 0.10.0)
|
65
62
|
simplecov-html (0.10.2)
|
66
63
|
thread_safe (0.3.6)
|
67
|
-
tzinfo (1.2.
|
64
|
+
tzinfo (1.2.7)
|
68
65
|
thread_safe (~> 0.1)
|
69
66
|
url (0.3.2)
|
67
|
+
zeitwerk (2.3.0)
|
70
68
|
|
71
69
|
PLATFORMS
|
72
70
|
ruby
|
73
71
|
|
74
72
|
DEPENDENCIES
|
75
|
-
bundler (~> 1.16)
|
76
73
|
codecov
|
77
74
|
database_cleaner
|
78
75
|
factory_bot
|
79
76
|
ffaker
|
80
77
|
pg_serializable!
|
81
78
|
pry
|
82
|
-
rake (~>
|
79
|
+
rake (~> 13.0)
|
83
80
|
rspec (~> 3.0)
|
84
81
|
|
85
82
|
BUNDLED WITH
|
86
|
-
1.
|
83
|
+
2.1.4
|
data/README.md
CHANGED
@@ -7,6 +7,23 @@
|
|
7
7
|
|
8
8
|
Serialize json directly from postgres (9.4+).
|
9
9
|
|
10
|
+
## Upgrading from version 2.x.x to 3.x.x
|
11
|
+
|
12
|
+
Serialization returns a PORO instead of a json string. If you have code like:
|
13
|
+
```ruby
|
14
|
+
OJ.load(Product.where(id: ids).json)
|
15
|
+
```
|
16
|
+
|
17
|
+
You can replace it with:
|
18
|
+
```ruby
|
19
|
+
Product.where(id: ids).json
|
20
|
+
```
|
21
|
+
|
22
|
+
To automatically use OJ to serialize your POROs to json strings, add this code to your initialization:
|
23
|
+
```ruby
|
24
|
+
Oj.optimize_rails()
|
25
|
+
```
|
26
|
+
|
10
27
|
## Motivation
|
11
28
|
Models:
|
12
29
|
```ruby
|
@@ -533,7 +550,7 @@ class Variation < ApplicationRecord
|
|
533
550
|
serializable do
|
534
551
|
default do
|
535
552
|
attributes :id
|
536
|
-
belongs_to
|
553
|
+
belongs_to :color
|
537
554
|
end
|
538
555
|
|
539
556
|
trait :for_products do
|
data/lib/pg_serializable.rb
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
require 'oj'
|
2
1
|
require 'active_support/concern'
|
3
2
|
require 'active_support/core_ext/module/delegation'
|
4
3
|
require 'pg_serializable/errors'
|
@@ -57,7 +56,7 @@ module PgSerializable
|
|
57
56
|
|
58
57
|
def to_pg_json(scope)
|
59
58
|
res = scope.as_json.first
|
60
|
-
|
59
|
+
res['coalesce'] || res['json_build_object']
|
61
60
|
end
|
62
61
|
|
63
62
|
private
|
@@ -56,8 +56,8 @@ module PgSerializable
|
|
56
56
|
key = "\'#{subject.label}\'"
|
57
57
|
enum_hash = subject.klass.defined_enums[subject.column_name.to_s]
|
58
58
|
val = "CASE \"#{table_alias}\".\"#{subject.column_name}\" " +
|
59
|
-
enum_hash.map do |
|
60
|
-
"WHEN #{
|
59
|
+
enum_hash.map do |enum_key, enum_value|
|
60
|
+
"WHEN #{enum_value.is_a?(String) ? "'#{enum_value}'" : enum_value} THEN \'#{subject.prc ? subject.prc.call(enum_key) : enum_key}\'"
|
61
61
|
end.join(' ') + " ELSE NULL END"
|
62
62
|
"#{key}, #{val}"
|
63
63
|
end
|
data/pg_serializable.gemspec
CHANGED
@@ -21,17 +21,15 @@ Gem::Specification.new do |spec|
|
|
21
21
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
22
22
|
spec.require_paths = ["lib"]
|
23
23
|
|
24
|
-
spec.add_development_dependency "bundler", "~> 1.16"
|
25
24
|
spec.add_development_dependency "codecov"
|
26
25
|
spec.add_development_dependency "database_cleaner"
|
27
26
|
spec.add_development_dependency "factory_bot"
|
28
27
|
spec.add_development_dependency "ffaker"
|
29
28
|
spec.add_development_dependency "pry"
|
30
|
-
spec.add_development_dependency "rake", "~>
|
29
|
+
spec.add_development_dependency "rake", "~> 13.0"
|
31
30
|
spec.add_development_dependency "rspec", "~> 3.0"
|
32
31
|
|
33
|
-
spec.add_runtime_dependency "activesupport", "
|
34
|
-
spec.add_runtime_dependency "activerecord", "
|
32
|
+
spec.add_runtime_dependency "activesupport", ">= 5.2", "< 7.0"
|
33
|
+
spec.add_runtime_dependency "activerecord", ">= 5.2", "< 7.0"
|
35
34
|
spec.add_runtime_dependency "pg", ">= 1.1"
|
36
|
-
spec.add_runtime_dependency "oj", "~> 3.6"
|
37
35
|
end
|
metadata
CHANGED
@@ -1,29 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pg_serializable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 3.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- matthewjf
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-06-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
-
- !ruby/object:Gem::Dependency
|
14
|
-
name: bundler
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - "~>"
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: '1.16'
|
20
|
-
type: :development
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - "~>"
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: '1.16'
|
27
13
|
- !ruby/object:Gem::Dependency
|
28
14
|
name: codecov
|
29
15
|
requirement: !ruby/object:Gem::Requirement
|
@@ -100,14 +86,14 @@ dependencies:
|
|
100
86
|
requirements:
|
101
87
|
- - "~>"
|
102
88
|
- !ruby/object:Gem::Version
|
103
|
-
version: '
|
89
|
+
version: '13.0'
|
104
90
|
type: :development
|
105
91
|
prerelease: false
|
106
92
|
version_requirements: !ruby/object:Gem::Requirement
|
107
93
|
requirements:
|
108
94
|
- - "~>"
|
109
95
|
- !ruby/object:Gem::Version
|
110
|
-
version: '
|
96
|
+
version: '13.0'
|
111
97
|
- !ruby/object:Gem::Dependency
|
112
98
|
name: rspec
|
113
99
|
requirement: !ruby/object:Gem::Requirement
|
@@ -126,30 +112,42 @@ dependencies:
|
|
126
112
|
name: activesupport
|
127
113
|
requirement: !ruby/object:Gem::Requirement
|
128
114
|
requirements:
|
129
|
-
- - "
|
115
|
+
- - ">="
|
130
116
|
- !ruby/object:Gem::Version
|
131
117
|
version: '5.2'
|
118
|
+
- - "<"
|
119
|
+
- !ruby/object:Gem::Version
|
120
|
+
version: '7.0'
|
132
121
|
type: :runtime
|
133
122
|
prerelease: false
|
134
123
|
version_requirements: !ruby/object:Gem::Requirement
|
135
124
|
requirements:
|
136
|
-
- - "
|
125
|
+
- - ">="
|
137
126
|
- !ruby/object:Gem::Version
|
138
127
|
version: '5.2'
|
128
|
+
- - "<"
|
129
|
+
- !ruby/object:Gem::Version
|
130
|
+
version: '7.0'
|
139
131
|
- !ruby/object:Gem::Dependency
|
140
132
|
name: activerecord
|
141
133
|
requirement: !ruby/object:Gem::Requirement
|
142
134
|
requirements:
|
143
|
-
- - "
|
135
|
+
- - ">="
|
144
136
|
- !ruby/object:Gem::Version
|
145
137
|
version: '5.2'
|
138
|
+
- - "<"
|
139
|
+
- !ruby/object:Gem::Version
|
140
|
+
version: '7.0'
|
146
141
|
type: :runtime
|
147
142
|
prerelease: false
|
148
143
|
version_requirements: !ruby/object:Gem::Requirement
|
149
144
|
requirements:
|
150
|
-
- - "
|
145
|
+
- - ">="
|
151
146
|
- !ruby/object:Gem::Version
|
152
147
|
version: '5.2'
|
148
|
+
- - "<"
|
149
|
+
- !ruby/object:Gem::Version
|
150
|
+
version: '7.0'
|
153
151
|
- !ruby/object:Gem::Dependency
|
154
152
|
name: pg
|
155
153
|
requirement: !ruby/object:Gem::Requirement
|
@@ -164,20 +162,6 @@ dependencies:
|
|
164
162
|
- - ">="
|
165
163
|
- !ruby/object:Gem::Version
|
166
164
|
version: '1.1'
|
167
|
-
- !ruby/object:Gem::Dependency
|
168
|
-
name: oj
|
169
|
-
requirement: !ruby/object:Gem::Requirement
|
170
|
-
requirements:
|
171
|
-
- - "~>"
|
172
|
-
- !ruby/object:Gem::Version
|
173
|
-
version: '3.6'
|
174
|
-
type: :runtime
|
175
|
-
prerelease: false
|
176
|
-
version_requirements: !ruby/object:Gem::Requirement
|
177
|
-
requirements:
|
178
|
-
- - "~>"
|
179
|
-
- !ruby/object:Gem::Version
|
180
|
-
version: '3.6'
|
181
165
|
description: serializes rails models from postgres (9.5+)
|
182
166
|
email:
|
183
167
|
- matthewjf@gmail.com
|
@@ -236,8 +220,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
236
220
|
- !ruby/object:Gem::Version
|
237
221
|
version: '0'
|
238
222
|
requirements: []
|
239
|
-
|
240
|
-
rubygems_version: 2.7.6
|
223
|
+
rubygems_version: 3.1.2
|
241
224
|
signing_key:
|
242
225
|
specification_version: 4
|
243
226
|
summary: serializes rails models from postgres (9.5+)
|