pg_serializable 1.4.0 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +14 -1
- data/lib/pg_serializable/version.rb +1 -1
- data/lib/pg_serializable.rb +9 -4
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 63d160c9c9813d6cd0cfb694af1d3f3b16f542cad5d0ced046d6b12ba52f4857
|
4
|
+
data.tar.gz: 1d1d71c4935b37e899f2e13514df90aa468f9d29c69b398cf4fe710cf94a3c68
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1b8307eecd420d164389ca4e04556c131e2e13d478023b0d38e70ae68498306559659a8370ea59234719d9e931c3a19a95c6ace42f2c686c99bcf5535b298bbf
|
7
|
+
data.tar.gz: 75d931172e41d8fb860744d4582df3b18f1aa6c868bcd5d8167ff38c720b814533e92824dc28ae7b25d493df19e5a378ce730a16cec5270f0fe6bb7cd8c2ccd3
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
# PgSerializable
|
2
2
|
[![codecov](https://codecov.io/gh/matthewjf/pg_serializable/branch/master/graph/badge.svg)](https://codecov.io/gh/matthewjf/pg_serializable)
|
3
3
|
[![Maintainability](https://api.codeclimate.com/v1/badges/f3450fdd21d38e2a2fe6/maintainability)](https://codeclimate.com/github/matthewjf/pg_serializable/maintainability)
|
4
|
+
[![Gem Version](https://badge.fury.io/rb/pg_serializable.svg)](https://badge.fury.io/rb/pg_serializable)
|
4
5
|
|
5
6
|
## Description
|
6
7
|
|
7
8
|
Serialize json directly from postgres (9.4+).
|
8
9
|
|
9
|
-
##
|
10
|
+
## Motivation
|
10
11
|
Models:
|
11
12
|
```ruby
|
12
13
|
class Product < ApplicationRecord
|
@@ -103,6 +104,18 @@ Or install it yourself as:
|
|
103
104
|
|
104
105
|
$ gem install pg_serializable
|
105
106
|
|
107
|
+
## Configuration
|
108
|
+
|
109
|
+
To ensure traits are valid during rails initialization instead of when accessed:
|
110
|
+
```ruby
|
111
|
+
# config/initializers/pg_serializable.rb
|
112
|
+
PgSerializable.validate_traits!
|
113
|
+
```
|
114
|
+
|
115
|
+
## Migrating from version 1 to 2
|
116
|
+
|
117
|
+
Trait validations were occasionally running before the class's traits were loaded when there are complex dependencies. These were moved out of the class definition. To maintain existing behavior, add `PgSerializable.validate_traits!` to an initializer. See [configuration](#Configuration).
|
118
|
+
|
106
119
|
## Usage
|
107
120
|
|
108
121
|
In your model:
|
data/lib/pg_serializable.rb
CHANGED
@@ -21,6 +21,15 @@ end
|
|
21
21
|
module PgSerializable
|
22
22
|
extend ActiveSupport::Concern
|
23
23
|
|
24
|
+
def self.validate_traits!
|
25
|
+
ActiveRecord::Base.descendants.each do |klass|
|
26
|
+
begin
|
27
|
+
klass.validate_traits!
|
28
|
+
rescue NoMethodError, ActiveRecord::NoDatabaseError
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
24
33
|
included do
|
25
34
|
include Visitable
|
26
35
|
|
@@ -36,10 +45,6 @@ module PgSerializable
|
|
36
45
|
|
37
46
|
def serializable(&blk)
|
38
47
|
trait_manager.instance_eval &blk
|
39
|
-
begin
|
40
|
-
validate_traits!
|
41
|
-
rescue ActiveRecord::NoDatabaseError
|
42
|
-
end
|
43
48
|
end
|
44
49
|
|
45
50
|
def trait_manager
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pg_serializable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- matthewjf
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-07-
|
11
|
+
date: 2019-07-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|