json_serialize 2.2.1 → 2.2.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 +7 -0
- data/README.md +44 -0
- data/json_serialize.gemspec +17 -7
- data/lib/json_serialize.rb +25 -26
- metadata +68 -47
- data/README.textile +0 -33
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 4ca9bfc2e027de8c3a67c6284ff34b1d56ce1b9ed86cb051ee5d6cbc722d1c9e
|
|
4
|
+
data.tar.gz: 23910e6ab92e3203bf55c7147ee273d5aaabea4360ca347e08a479fa8bfc55a9
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 632219ef6d0021e31ab0eb078aeca71f6f20c1abd43f45919b9375f9f8eb3766a4815cde6aef827534b305bfbb0c09514a9e9924e27c7cc0793374c039313a06
|
|
7
|
+
data.tar.gz: f659b50c1800608a2ff6e2a01845666a1a99d12b45942be68ff9afa9edd951a5ef2ab2a94a8a5117f61f147d508aa71dbdea527b05e0d431d8500f7684c999e8
|
data/README.md
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
> ⚠️ **DEPRECATED:** `json_serialize` is no longer maintained. Modern Rails has
|
|
2
|
+
> native JSON serialization (`serialize :col, JSON` and JSONB columns) that
|
|
3
|
+
> covers the same use cases. The final release is v2.2.3.
|
|
4
|
+
|
|
5
|
+
json_serialize
|
|
6
|
+
==============
|
|
7
|
+
|
|
8
|
+
**JSON serialization in ActiveRecord**
|
|
9
|
+
|
|
10
|
+
| | |
|
|
11
|
+
|:------------|:--------------------------------|
|
|
12
|
+
| **Author** | Tim Morgan |
|
|
13
|
+
| **Version** | 2.2.2 (May 15, 2013) |
|
|
14
|
+
| **License** | Released under the MIT license. |
|
|
15
|
+
|
|
16
|
+
About
|
|
17
|
+
-----
|
|
18
|
+
|
|
19
|
+
`json_serialize` gives you the ability to JSON-encode data into ActiveRecord
|
|
20
|
+
model fields. JSON is a more compact but less robust serialization than YAML.
|
|
21
|
+
Only hashes, arrays, and primitives can be reliably encoded to database fields;
|
|
22
|
+
other types may not decode properly or at all.
|
|
23
|
+
|
|
24
|
+
Installation and Usage
|
|
25
|
+
----------------------
|
|
26
|
+
|
|
27
|
+
Firstly, add the gem to your Rails project's `Gemfile`:
|
|
28
|
+
|
|
29
|
+
```` ruby
|
|
30
|
+
gem 'json_serialize'
|
|
31
|
+
````
|
|
32
|
+
|
|
33
|
+
Then, include into your model the `JsonSerialize` module, and call the
|
|
34
|
+
`json_serialize` method to indicate which fields should be serialized:
|
|
35
|
+
|
|
36
|
+
```` ruby
|
|
37
|
+
class MyModel < ActiveRecord::Base
|
|
38
|
+
include JsonSerialize
|
|
39
|
+
json_serialize :favorites, :preferences
|
|
40
|
+
end
|
|
41
|
+
````
|
|
42
|
+
|
|
43
|
+
More information can be found at the {JsonSerialize::ClassMethods#json_serialize}
|
|
44
|
+
method documentation.
|
data/json_serialize.gemspec
CHANGED
|
@@ -2,33 +2,43 @@
|
|
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
|
3
3
|
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
|
4
4
|
# -*- encoding: utf-8 -*-
|
|
5
|
+
# stub: json_serialize 2.2.3 ruby lib
|
|
5
6
|
|
|
6
7
|
Gem::Specification.new do |s|
|
|
7
8
|
s.name = "json_serialize"
|
|
8
|
-
s.version = "2.2.
|
|
9
|
+
s.version = "2.2.3"
|
|
9
10
|
|
|
10
11
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
|
11
12
|
s.authors = ["Tim Morgan"]
|
|
12
|
-
s.date = "
|
|
13
|
+
s.date = "2013-12-08"
|
|
13
14
|
s.description = "Adds to ActiveRecord the ability to JSON-serialize certain fields."
|
|
14
15
|
s.email = "git@timothymorgan.info"
|
|
15
16
|
s.extra_rdoc_files = [
|
|
16
17
|
"LICENSE",
|
|
17
|
-
"README.
|
|
18
|
+
"README.md"
|
|
18
19
|
]
|
|
19
20
|
s.files = [
|
|
20
21
|
"LICENSE",
|
|
21
|
-
"README.
|
|
22
|
+
"README.md",
|
|
22
23
|
"json_serialize.gemspec",
|
|
23
24
|
"lib/json_serialize.rb"
|
|
24
25
|
]
|
|
25
26
|
s.homepage = "http://github.com/riscfuture/json_serialize"
|
|
26
27
|
s.require_paths = ["lib"]
|
|
27
|
-
s.rubygems_version = "1.
|
|
28
|
-
s.summary = "Adds JSON serialization to ActiveRecord models"
|
|
28
|
+
s.rubygems_version = "2.1.11"
|
|
29
|
+
s.summary = "[DEPRECATED] Adds JSON serialization to ActiveRecord models"
|
|
30
|
+
s.post_install_message = <<~MSG
|
|
31
|
+
|
|
32
|
+
⚠️ DEPRECATED: json_serialize is no longer maintained.
|
|
33
|
+
|
|
34
|
+
No longer maintained. Modern Rails has native JSON serialization (`serialize :col, JSON` and JSONB columns) that covers the same use cases.
|
|
35
|
+
|
|
36
|
+
This is the final release. No further updates are planned.
|
|
37
|
+
|
|
38
|
+
MSG
|
|
29
39
|
|
|
30
40
|
if s.respond_to? :specification_version then
|
|
31
|
-
s.specification_version =
|
|
41
|
+
s.specification_version = 4
|
|
32
42
|
|
|
33
43
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
|
34
44
|
s.add_runtime_dependency(%q<activerecord>, [">= 3.0"])
|
data/lib/json_serialize.rb
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# Adds the {#json_serialize} method to
|
|
1
|
+
# Adds the {ClassMethods#json_serialize} method to `ActiveRecord` objects.
|
|
2
2
|
#
|
|
3
3
|
# @example Basic usage
|
|
4
4
|
# class MyModel < ActiveRecord::Base
|
|
@@ -16,15 +16,15 @@ module JsonSerialize
|
|
|
16
16
|
# @param [Symbol] field The database field to JSON-serialize.
|
|
17
17
|
# @param [Hash<Symbol, Object>] fields_with_default_values A map of
|
|
18
18
|
# additional fields to JSON-serialize, with the default value that
|
|
19
|
-
# should be given if the field is
|
|
19
|
+
# should be given if the field is `NULL`.
|
|
20
20
|
|
|
21
21
|
def json_serialize(*fields)
|
|
22
|
-
fields_with_defaults = fields.extract_options!
|
|
22
|
+
@fields_with_defaults = fields.extract_options!
|
|
23
23
|
fields.each do |field|
|
|
24
|
-
fields_with_defaults[field] = nil
|
|
24
|
+
@fields_with_defaults[field] = nil
|
|
25
25
|
end
|
|
26
26
|
|
|
27
|
-
fields_with_defaults.each do |field, default_value|
|
|
27
|
+
@fields_with_defaults.each do |field, default_value|
|
|
28
28
|
define_method field do
|
|
29
29
|
if instance_variable_defined?(field_ivar(field)) then
|
|
30
30
|
instance_variable_get field_ivar(field)
|
|
@@ -36,7 +36,7 @@ module JsonSerialize
|
|
|
36
36
|
decoded
|
|
37
37
|
end
|
|
38
38
|
end
|
|
39
|
-
|
|
39
|
+
|
|
40
40
|
define_method :"#{field}=" do |value|
|
|
41
41
|
write_attribute field, (value.nil? ? nil : ActiveSupport::JSON.encode(value))
|
|
42
42
|
instance_variable_set field_ivar(field), value
|
|
@@ -44,36 +44,35 @@ module JsonSerialize
|
|
|
44
44
|
end
|
|
45
45
|
|
|
46
46
|
define_method :serialize_json_values do
|
|
47
|
-
fields_with_defaults.keys.each do |field|
|
|
47
|
+
self.class.instance_variable_get(:@fields_with_defaults).keys.each do |field|
|
|
48
48
|
if instance_variable_defined?(field_ivar(field)) then
|
|
49
49
|
send :"#{field}=", instance_variable_get(field_ivar(field))
|
|
50
50
|
end
|
|
51
51
|
end
|
|
52
52
|
end
|
|
53
|
-
|
|
54
|
-
define_method :reload_with_refresh_json_ivars do |*args|
|
|
55
|
-
res = reload_without_refresh_json_ivars *args
|
|
56
|
-
fields_with_defaults.keys.each { |field| remove_instance_variable field_ivar(field) if instance_variable_defined?(field_ivar(field)) }
|
|
57
|
-
res
|
|
58
|
-
end
|
|
59
|
-
|
|
60
|
-
define_method :update_with_refresh_json_ivars do |*args|
|
|
61
|
-
res = update_without_refresh_json_ivars(*args)
|
|
62
|
-
fields_with_defaults.keys.each { |field| remove_instance_variable field_ivar(field) if instance_variable_defined?(field_ivar(field)) }
|
|
63
|
-
res
|
|
64
|
-
end
|
|
65
|
-
|
|
53
|
+
|
|
66
54
|
before_validation :serialize_json_values
|
|
67
|
-
|
|
68
|
-
alias_method_chain :update, :refresh_json_ivars
|
|
55
|
+
prepend WithRefreshJSONIvars
|
|
69
56
|
end
|
|
70
57
|
end
|
|
71
58
|
|
|
72
|
-
module
|
|
73
|
-
|
|
59
|
+
module WithRefreshJSONIvars
|
|
60
|
+
def reload(*args)
|
|
61
|
+
result = super
|
|
62
|
+
self.class.instance_variable_get(:@fields_with_defaults).keys.each { |field| remove_instance_variable field_ivar(field) if instance_variable_defined?(field_ivar(field)) }
|
|
63
|
+
result
|
|
64
|
+
end
|
|
74
65
|
|
|
75
|
-
def
|
|
76
|
-
|
|
66
|
+
def update
|
|
67
|
+
result = super
|
|
68
|
+
self.class.instance_variable_defined(:@fields_with_defaults).keys.each { |field| remove_instance_variable field_ivar(field) if instance_variable_defined?(field_ivar(field)) }
|
|
69
|
+
result
|
|
77
70
|
end
|
|
78
71
|
end
|
|
72
|
+
|
|
73
|
+
private
|
|
74
|
+
|
|
75
|
+
def field_ivar(name)
|
|
76
|
+
:"@_deserialized_#{name}"
|
|
77
|
+
end
|
|
79
78
|
end
|
metadata
CHANGED
|
@@ -1,130 +1,151 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: json_serialize
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 2.2.
|
|
5
|
-
prerelease:
|
|
4
|
+
version: 2.2.3
|
|
6
5
|
platform: ruby
|
|
7
6
|
authors:
|
|
8
7
|
- Tim Morgan
|
|
9
|
-
autorequire:
|
|
10
8
|
bindir: bin
|
|
11
9
|
cert_chain: []
|
|
12
|
-
date:
|
|
10
|
+
date: 2013-12-08 00:00:00.000000000 Z
|
|
13
11
|
dependencies:
|
|
14
12
|
- !ruby/object:Gem::Dependency
|
|
15
13
|
name: activerecord
|
|
16
|
-
requirement:
|
|
17
|
-
none: false
|
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
|
18
15
|
requirements:
|
|
19
|
-
- -
|
|
16
|
+
- - ">="
|
|
20
17
|
- !ruby/object:Gem::Version
|
|
21
18
|
version: '3.0'
|
|
22
19
|
type: :runtime
|
|
23
20
|
prerelease: false
|
|
24
|
-
version_requirements:
|
|
21
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
22
|
+
requirements:
|
|
23
|
+
- - ">="
|
|
24
|
+
- !ruby/object:Gem::Version
|
|
25
|
+
version: '3.0'
|
|
25
26
|
- !ruby/object:Gem::Dependency
|
|
26
27
|
name: activesupport
|
|
27
|
-
requirement:
|
|
28
|
-
none: false
|
|
28
|
+
requirement: !ruby/object:Gem::Requirement
|
|
29
29
|
requirements:
|
|
30
|
-
- -
|
|
30
|
+
- - ">="
|
|
31
31
|
- !ruby/object:Gem::Version
|
|
32
32
|
version: '3.0'
|
|
33
33
|
type: :runtime
|
|
34
34
|
prerelease: false
|
|
35
|
-
version_requirements:
|
|
35
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
36
|
+
requirements:
|
|
37
|
+
- - ">="
|
|
38
|
+
- !ruby/object:Gem::Version
|
|
39
|
+
version: '3.0'
|
|
36
40
|
- !ruby/object:Gem::Dependency
|
|
37
41
|
name: jeweler
|
|
38
|
-
requirement:
|
|
39
|
-
none: false
|
|
42
|
+
requirement: !ruby/object:Gem::Requirement
|
|
40
43
|
requirements:
|
|
41
|
-
- -
|
|
44
|
+
- - ">="
|
|
42
45
|
- !ruby/object:Gem::Version
|
|
43
46
|
version: '0'
|
|
44
47
|
type: :development
|
|
45
48
|
prerelease: false
|
|
46
|
-
version_requirements:
|
|
49
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
50
|
+
requirements:
|
|
51
|
+
- - ">="
|
|
52
|
+
- !ruby/object:Gem::Version
|
|
53
|
+
version: '0'
|
|
47
54
|
- !ruby/object:Gem::Dependency
|
|
48
55
|
name: yard
|
|
49
|
-
requirement:
|
|
50
|
-
none: false
|
|
56
|
+
requirement: !ruby/object:Gem::Requirement
|
|
51
57
|
requirements:
|
|
52
|
-
- -
|
|
58
|
+
- - ">="
|
|
53
59
|
- !ruby/object:Gem::Version
|
|
54
60
|
version: '0'
|
|
55
61
|
type: :development
|
|
56
62
|
prerelease: false
|
|
57
|
-
version_requirements:
|
|
63
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
64
|
+
requirements:
|
|
65
|
+
- - ">="
|
|
66
|
+
- !ruby/object:Gem::Version
|
|
67
|
+
version: '0'
|
|
58
68
|
- !ruby/object:Gem::Dependency
|
|
59
69
|
name: RedCloth
|
|
60
|
-
requirement:
|
|
61
|
-
none: false
|
|
70
|
+
requirement: !ruby/object:Gem::Requirement
|
|
62
71
|
requirements:
|
|
63
|
-
- -
|
|
72
|
+
- - ">="
|
|
64
73
|
- !ruby/object:Gem::Version
|
|
65
74
|
version: '0'
|
|
66
75
|
type: :development
|
|
67
76
|
prerelease: false
|
|
68
|
-
version_requirements:
|
|
77
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
78
|
+
requirements:
|
|
79
|
+
- - ">="
|
|
80
|
+
- !ruby/object:Gem::Version
|
|
81
|
+
version: '0'
|
|
69
82
|
- !ruby/object:Gem::Dependency
|
|
70
83
|
name: rspec
|
|
71
|
-
requirement:
|
|
72
|
-
none: false
|
|
84
|
+
requirement: !ruby/object:Gem::Requirement
|
|
73
85
|
requirements:
|
|
74
|
-
- -
|
|
86
|
+
- - ">="
|
|
75
87
|
- !ruby/object:Gem::Version
|
|
76
88
|
version: '0'
|
|
77
89
|
type: :development
|
|
78
90
|
prerelease: false
|
|
79
|
-
version_requirements:
|
|
91
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
92
|
+
requirements:
|
|
93
|
+
- - ">="
|
|
94
|
+
- !ruby/object:Gem::Version
|
|
95
|
+
version: '0'
|
|
80
96
|
- !ruby/object:Gem::Dependency
|
|
81
97
|
name: sqlite3
|
|
82
|
-
requirement:
|
|
83
|
-
none: false
|
|
98
|
+
requirement: !ruby/object:Gem::Requirement
|
|
84
99
|
requirements:
|
|
85
|
-
- -
|
|
100
|
+
- - ">="
|
|
86
101
|
- !ruby/object:Gem::Version
|
|
87
102
|
version: '0'
|
|
88
103
|
type: :development
|
|
89
104
|
prerelease: false
|
|
90
|
-
version_requirements:
|
|
105
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
106
|
+
requirements:
|
|
107
|
+
- - ">="
|
|
108
|
+
- !ruby/object:Gem::Version
|
|
109
|
+
version: '0'
|
|
91
110
|
description: Adds to ActiveRecord the ability to JSON-serialize certain fields.
|
|
92
111
|
email: git@timothymorgan.info
|
|
93
112
|
executables: []
|
|
94
113
|
extensions: []
|
|
95
114
|
extra_rdoc_files:
|
|
96
115
|
- LICENSE
|
|
97
|
-
- README.
|
|
116
|
+
- README.md
|
|
98
117
|
files:
|
|
99
118
|
- LICENSE
|
|
100
|
-
- README.
|
|
119
|
+
- README.md
|
|
101
120
|
- json_serialize.gemspec
|
|
102
121
|
- lib/json_serialize.rb
|
|
103
122
|
homepage: http://github.com/riscfuture/json_serialize
|
|
104
123
|
licenses: []
|
|
105
|
-
|
|
124
|
+
metadata: {}
|
|
125
|
+
post_install_message: |2+
|
|
126
|
+
|
|
127
|
+
⚠️ DEPRECATED: json_serialize is no longer maintained.
|
|
128
|
+
|
|
129
|
+
No longer maintained. Modern Rails has native JSON serialization (`serialize :col, JSON` and JSONB columns) that covers the same use cases.
|
|
130
|
+
|
|
131
|
+
This is the final release. No further updates are planned.
|
|
132
|
+
|
|
106
133
|
rdoc_options: []
|
|
107
134
|
require_paths:
|
|
108
135
|
- lib
|
|
109
136
|
required_ruby_version: !ruby/object:Gem::Requirement
|
|
110
|
-
none: false
|
|
111
137
|
requirements:
|
|
112
|
-
- -
|
|
138
|
+
- - ">="
|
|
113
139
|
- !ruby/object:Gem::Version
|
|
114
140
|
version: '0'
|
|
115
|
-
segments:
|
|
116
|
-
- 0
|
|
117
|
-
hash: -684680556138569707
|
|
118
141
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
119
|
-
none: false
|
|
120
142
|
requirements:
|
|
121
|
-
- -
|
|
143
|
+
- - ">="
|
|
122
144
|
- !ruby/object:Gem::Version
|
|
123
145
|
version: '0'
|
|
124
146
|
requirements: []
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
specification_version: 3
|
|
129
|
-
summary: Adds JSON serialization to ActiveRecord models
|
|
147
|
+
rubygems_version: 4.0.11
|
|
148
|
+
specification_version: 4
|
|
149
|
+
summary: "[DEPRECATED] Adds JSON serialization to ActiveRecord models"
|
|
130
150
|
test_files: []
|
|
151
|
+
...
|
data/README.textile
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
h1. json_serialize -- JSON serialization in ActiveRecord
|
|
2
|
-
|
|
3
|
-
| *Author* | Tim Morgan |
|
|
4
|
-
| *Version* | 2.2.1 (Jan 11, 2012) |
|
|
5
|
-
| *License* | Released under the MIT license. |
|
|
6
|
-
|
|
7
|
-
h2. About
|
|
8
|
-
|
|
9
|
-
@json_serialize@ gives you the ability to JSON-encode data into ActiveRecord
|
|
10
|
-
model fields. JSON is a more compact but less robust serialization than YAML.
|
|
11
|
-
Only hashes, arrays, and primitives can be reliably encoded to database fields;
|
|
12
|
-
other types may not decode properly or at all.
|
|
13
|
-
|
|
14
|
-
h2. Installation and Usage
|
|
15
|
-
|
|
16
|
-
Firstly, add the gem to your Rails project's @Gemfile@:
|
|
17
|
-
|
|
18
|
-
<pre><code>
|
|
19
|
-
gem 'json_serialize'
|
|
20
|
-
</code></pre>
|
|
21
|
-
|
|
22
|
-
Then, include into your model the @JsonSerialize@ module, and call the
|
|
23
|
-
@json_serialize@ method to indicate which fields should be serialized:
|
|
24
|
-
|
|
25
|
-
<pre><code>
|
|
26
|
-
class MyModel < ActiveRecord::Base
|
|
27
|
-
include JsonSerialize
|
|
28
|
-
json_serialize :favorites, :preferences
|
|
29
|
-
end
|
|
30
|
-
</code></pre>
|
|
31
|
-
|
|
32
|
-
More information can be found at the {JsonSerialize#json_serialize} method
|
|
33
|
-
documentation.
|