panko_serializer 0.7.2 → 0.7.6
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/.github/workflows/docs.yml +39 -0
- data/.github/workflows/ruby.yml +48 -0
- data/.gitignore +2 -1
- data/Gemfile +5 -14
- data/README.md +7 -7
- data/benchmarks/bm_panko_json.rb +5 -1
- data/benchmarks/setup.rb +3 -1
- data/benchmarks/type_casts/bm_panko.rb +2 -2
- data/docs/.DS_Store +0 -0
- data/docs/README.md +195 -8
- data/docs/core/Footer.js +81 -0
- data/docs/{associations.md → docs/associations.md} +7 -3
- data/docs/{attributes.md → docs/attributes.md} +8 -4
- data/docs/{design-choices.md → docs/design-choices.md} +6 -2
- data/docs/{getting-started.md → docs/getting-started.md} +5 -1
- data/docs/docs/introduction.md +13 -0
- data/docs/{performance.md → docs/performance.md} +11 -7
- data/docs/{response-bag.md → docs/response-bag.md} +24 -1
- data/docs/i18n/en.json +50 -0
- data/docs/package-lock.json +9673 -0
- data/docs/package.json +14 -0
- data/docs/sidebars.json +15 -0
- data/docs/siteConfig.js +80 -0
- data/docs/static/.DS_Store +0 -0
- data/docs/static/css/custom.css +51 -0
- data/docs/static/img/favicon.ico +0 -0
- data/docs/static/img/oss_logo.png +0 -0
- data/docs/static/img/undraw_code_review.svg +1 -0
- data/docs/static/img/undraw_monitor.svg +1 -0
- data/docs/static/img/undraw_note_list.svg +1 -0
- data/docs/static/img/undraw_online.svg +1 -0
- data/docs/static/img/undraw_open_source.svg +1 -0
- data/docs/static/img/undraw_operating_system.svg +1 -0
- data/docs/static/img/undraw_react.svg +1 -0
- data/docs/static/img/undraw_tweetstorm.svg +1 -0
- data/docs/static/img/undraw_youtube_tutorial.svg +1 -0
- data/docs/static/index.html +14 -0
- data/ext/panko_serializer/attributes_writer/active_record.c +58 -16
- data/ext/panko_serializer/attributes_writer/attributes_writer.c +8 -7
- data/ext/panko_serializer/attributes_writer/common.h +1 -1
- data/ext/panko_serializer/attributes_writer/hash.c +2 -4
- data/ext/panko_serializer/attributes_writer/plain.c +2 -3
- data/ext/panko_serializer/attributes_writer/type_cast/type_cast.c +70 -21
- data/ext/panko_serializer/attributes_writer/type_cast/type_cast.h +1 -2
- data/ext/panko_serializer/panko_serializer.c +23 -8
- data/ext/panko_serializer/serialization_descriptor/association.c +1 -0
- data/ext/panko_serializer/serialization_descriptor/attribute.c +1 -0
- data/ext/panko_serializer/serialization_descriptor/serialization_descriptor.c +7 -10
- data/lib/panko/association.rb +1 -1
- data/lib/panko/object_writer.rb +8 -0
- data/lib/panko/response.rb +5 -4
- data/lib/panko/serializer.rb +4 -2
- data/lib/panko/serializer_resolver.rb +28 -15
- data/lib/panko/version.rb +1 -1
- data/panko_serializer.gemspec +8 -7
- metadata +67 -25
- data/.travis.yml +0 -37
- data/docs/docpress.json +0 -4
@@ -85,6 +85,7 @@ void panko_init_attribute(VALUE mPanko) {
|
|
85
85
|
attribute_aliases_id = rb_intern("attribute_aliases");
|
86
86
|
|
87
87
|
cAttribute = rb_define_class_under(mPanko, "Attribute", rb_cObject);
|
88
|
+
rb_global_variable(&cAttribute);
|
88
89
|
|
89
90
|
rb_define_module_function(cAttribute, "new", attribute_new, -1);
|
90
91
|
|
@@ -1,7 +1,5 @@
|
|
1
1
|
#include "serialization_descriptor.h"
|
2
2
|
|
3
|
-
VALUE cSerializationDescriptor;
|
4
|
-
|
5
3
|
static ID object_id;
|
6
4
|
static ID sc_id;
|
7
5
|
|
@@ -10,8 +8,8 @@ static void sd_free(SerializationDescriptor sd) {
|
|
10
8
|
return;
|
11
9
|
}
|
12
10
|
|
13
|
-
sd->serializer_type = Qnil;
|
14
11
|
sd->serializer = Qnil;
|
12
|
+
sd->serializer_type = Qnil;
|
15
13
|
sd->attributes = Qnil;
|
16
14
|
sd->method_fields = Qnil;
|
17
15
|
sd->has_one_associations = Qnil;
|
@@ -21,8 +19,8 @@ static void sd_free(SerializationDescriptor sd) {
|
|
21
19
|
}
|
22
20
|
|
23
21
|
void sd_mark(SerializationDescriptor data) {
|
24
|
-
rb_gc_mark(data->serializer_type);
|
25
22
|
rb_gc_mark(data->serializer);
|
23
|
+
rb_gc_mark(data->serializer_type);
|
26
24
|
rb_gc_mark(data->attributes);
|
27
25
|
rb_gc_mark(data->method_fields);
|
28
26
|
rb_gc_mark(data->has_one_associations);
|
@@ -30,7 +28,7 @@ void sd_mark(SerializationDescriptor data) {
|
|
30
28
|
rb_gc_mark(data->aliases);
|
31
29
|
}
|
32
30
|
|
33
|
-
static VALUE
|
31
|
+
static VALUE sd_alloc(VALUE klass) {
|
34
32
|
SerializationDescriptor sd = ALLOC(struct _SerializationDescriptor);
|
35
33
|
|
36
34
|
sd->serializer = Qnil;
|
@@ -43,7 +41,7 @@ static VALUE sd_new(int argc, VALUE* argv, VALUE self) {
|
|
43
41
|
|
44
42
|
sd->attributes_writer = create_empty_attributes_writer();
|
45
43
|
|
46
|
-
return Data_Wrap_Struct(
|
44
|
+
return Data_Wrap_Struct(klass, sd_mark, sd_free, sd);
|
47
45
|
}
|
48
46
|
|
49
47
|
SerializationDescriptor sd_read(VALUE descriptor) {
|
@@ -122,7 +120,7 @@ VALUE sd_type_set(VALUE self, VALUE type) {
|
|
122
120
|
return Qnil;
|
123
121
|
}
|
124
122
|
|
125
|
-
VALUE sd_type_aref(VALUE self
|
123
|
+
VALUE sd_type_aref(VALUE self) {
|
126
124
|
SerializationDescriptor sd = (SerializationDescriptor)DATA_PTR(self);
|
127
125
|
return sd->serializer_type;
|
128
126
|
}
|
@@ -142,11 +140,10 @@ void panko_init_serialization_descriptor(VALUE mPanko) {
|
|
142
140
|
object_id = rb_intern("@object");
|
143
141
|
sc_id = rb_intern("@sc");
|
144
142
|
|
145
|
-
cSerializationDescriptor =
|
143
|
+
VALUE cSerializationDescriptor =
|
146
144
|
rb_define_class_under(mPanko, "SerializationDescriptor", rb_cObject);
|
147
145
|
|
148
|
-
|
149
|
-
|
146
|
+
rb_define_alloc_func(cSerializationDescriptor, sd_alloc);
|
150
147
|
rb_define_method(cSerializationDescriptor, "serializer=", sd_serializer_set,
|
151
148
|
1);
|
152
149
|
rb_define_method(cSerializationDescriptor, "serializer", sd_serializer_ref,
|
data/lib/panko/association.rb
CHANGED
data/lib/panko/object_writer.rb
CHANGED
@@ -33,6 +33,14 @@ class Panko::ObjectWriter
|
|
33
33
|
@values.last[key] = value.as_json
|
34
34
|
end
|
35
35
|
|
36
|
+
def push_json(value, key = nil)
|
37
|
+
if value.is_a?(String)
|
38
|
+
value = Oj.load(value) rescue nil
|
39
|
+
end
|
40
|
+
|
41
|
+
push_value(value, key)
|
42
|
+
end
|
43
|
+
|
36
44
|
def pop
|
37
45
|
result = @values.pop
|
38
46
|
|
data/lib/panko/response.rb
CHANGED
@@ -22,12 +22,13 @@ module Panko
|
|
22
22
|
Panko::JsonValue.from(value)
|
23
23
|
end
|
24
24
|
|
25
|
-
def self.array_serializer(data, serializer)
|
26
|
-
|
25
|
+
def self.array_serializer(data, serializer, options = {})
|
26
|
+
merged_options = options.merge(each_serializer: serializer)
|
27
|
+
Panko::ArraySerializer.new(data, merged_options)
|
27
28
|
end
|
28
29
|
|
29
|
-
def self.serializer(data, serializer)
|
30
|
-
json serializer.new.serialize_to_json(data)
|
30
|
+
def self.serializer(data, serializer, options = {})
|
31
|
+
json serializer.new(options).serialize_to_json(data)
|
31
32
|
end
|
32
33
|
end
|
33
34
|
|
data/lib/panko/serializer.rb
CHANGED
@@ -32,6 +32,8 @@ end
|
|
32
32
|
|
33
33
|
module Panko
|
34
34
|
class Serializer
|
35
|
+
SKIP = Object.new.freeze
|
36
|
+
|
35
37
|
class << self
|
36
38
|
def inherited(base)
|
37
39
|
if _descriptor.nil?
|
@@ -73,7 +75,7 @@ module Panko
|
|
73
75
|
|
74
76
|
def has_one(name, options = {})
|
75
77
|
serializer_const = options[:serializer]
|
76
|
-
serializer_const = Panko::SerializerResolver.resolve(name.to_s) if serializer_const.nil?
|
78
|
+
serializer_const = Panko::SerializerResolver.resolve(name.to_s, self) if serializer_const.nil?
|
77
79
|
|
78
80
|
raise "Can't find serializer for #{self.name}.#{name} has_one relationship." if serializer_const.nil?
|
79
81
|
|
@@ -86,7 +88,7 @@ module Panko
|
|
86
88
|
|
87
89
|
def has_many(name, options = {})
|
88
90
|
serializer_const = options[:serializer] || options[:each_serializer]
|
89
|
-
serializer_const = Panko::SerializerResolver.resolve(name.to_s) if serializer_const.nil?
|
91
|
+
serializer_const = Panko::SerializerResolver.resolve(name.to_s, self) if serializer_const.nil?
|
90
92
|
|
91
93
|
raise "Can't find serializer for #{self.name}.#{name} has_many relationship." if serializer_const.nil?
|
92
94
|
|
@@ -1,25 +1,38 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'active_support/core_ext/string/inflections'
|
4
|
+
require 'active_support/core_ext/module/introspection'
|
5
|
+
|
3
6
|
class Panko::SerializerResolver
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
+
class << self
|
8
|
+
def resolve(name, from)
|
9
|
+
serializer_const = nil
|
7
10
|
|
8
|
-
|
9
|
-
|
11
|
+
if namespace = namespace_for(from)
|
12
|
+
serializer_const = safe_serializer_get("#{namespace}::#{name.singularize.camelize}Serializer")
|
13
|
+
end
|
10
14
|
|
11
|
-
|
12
|
-
|
15
|
+
serializer_const ||= safe_serializer_get("#{name.singularize.camelize}Serializer")
|
16
|
+
serializer_const
|
17
|
+
end
|
13
18
|
|
14
|
-
|
19
|
+
private
|
15
20
|
|
16
|
-
|
17
|
-
|
18
|
-
|
21
|
+
if Module.method_defined?(:module_parent_name)
|
22
|
+
def namespace_for(from)
|
23
|
+
from.module_parent_name
|
24
|
+
end
|
25
|
+
else
|
26
|
+
def namespace_for(from)
|
27
|
+
from.parent_name
|
28
|
+
end
|
29
|
+
end
|
19
30
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
31
|
+
def safe_serializer_get(name)
|
32
|
+
const = Object.const_get(name)
|
33
|
+
const < Panko::Serializer ? const : nil
|
34
|
+
rescue NameError
|
35
|
+
nil
|
36
|
+
end
|
24
37
|
end
|
25
38
|
end
|
data/lib/panko/version.rb
CHANGED
data/panko_serializer.gemspec
CHANGED
@@ -11,17 +11,17 @@ Gem::Specification.new do |spec|
|
|
11
11
|
spec.email = ["yosy101@gmail.com"]
|
12
12
|
|
13
13
|
spec.summary = "High Performance JSON Serialization for ActiveRecord & Ruby Objects"
|
14
|
-
spec.homepage = "https://
|
14
|
+
spec.homepage = "https://panko.dev"
|
15
15
|
spec.license = "MIT"
|
16
16
|
|
17
17
|
spec.metadata = {
|
18
|
-
"bug_tracker_uri" => "https://github.com/
|
19
|
-
"source_code_uri" => "https://github.com/
|
20
|
-
"documentation_uri" => "https://
|
21
|
-
"changelog_uri" => "https://github.com/
|
18
|
+
"bug_tracker_uri" => "https://github.com/panko-serializer/panko_serializer/issues",
|
19
|
+
"source_code_uri" => "https://github.com/panko-serializer/panko_serializer",
|
20
|
+
"documentation_uri" => "https://panko-serializer.github.io/panko_serializer/",
|
21
|
+
"changelog_uri" => "https://github.com/panko-serializer/panko_serializer/releases"
|
22
22
|
}
|
23
23
|
|
24
|
-
spec.required_ruby_version = ">= 2.
|
24
|
+
spec.required_ruby_version = ">= 2.5.0"
|
25
25
|
|
26
26
|
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
27
27
|
f.match(%r{^(test|spec|features)/})
|
@@ -30,5 +30,6 @@ Gem::Specification.new do |spec|
|
|
30
30
|
|
31
31
|
spec.extensions << "ext/panko_serializer/extconf.rb"
|
32
32
|
|
33
|
-
spec.add_dependency "oj",
|
33
|
+
spec.add_dependency "oj", '> 3.11.0', '< 4.0.0'
|
34
|
+
spec.add_dependency "activesupport"
|
34
35
|
end
|
metadata
CHANGED
@@ -1,30 +1,50 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: panko_serializer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.7.
|
4
|
+
version: 0.7.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yosi Attias
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-09-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: oj
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 3.
|
19
|
+
version: 3.11.0
|
20
|
+
- - "<"
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 4.0.0
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - ">"
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 3.11.0
|
30
|
+
- - "<"
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 4.0.0
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: activesupport
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0'
|
20
40
|
type: :runtime
|
21
41
|
prerelease: false
|
22
42
|
version_requirements: !ruby/object:Gem::Requirement
|
23
43
|
requirements:
|
24
|
-
- - "
|
44
|
+
- - ">="
|
25
45
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
27
|
-
description:
|
46
|
+
version: '0'
|
47
|
+
description:
|
28
48
|
email:
|
29
49
|
- yosy101@gmail.com
|
30
50
|
executables: []
|
@@ -33,10 +53,11 @@ extensions:
|
|
33
53
|
extra_rdoc_files: []
|
34
54
|
files:
|
35
55
|
- ".clang-format"
|
56
|
+
- ".github/workflows/docs.yml"
|
57
|
+
- ".github/workflows/ruby.yml"
|
36
58
|
- ".gitignore"
|
37
59
|
- ".rspec"
|
38
60
|
- ".rubocop.yml"
|
39
|
-
- ".travis.yml"
|
40
61
|
- Gemfile
|
41
62
|
- LICENSE.txt
|
42
63
|
- README.md
|
@@ -59,14 +80,35 @@ files:
|
|
59
80
|
- benchmarks/type_casts/bm_active_record.rb
|
60
81
|
- benchmarks/type_casts/bm_panko.rb
|
61
82
|
- benchmarks/type_casts/support.rb
|
83
|
+
- docs/.DS_Store
|
62
84
|
- docs/README.md
|
63
|
-
- docs/
|
64
|
-
- docs/
|
65
|
-
- docs/
|
66
|
-
- docs/
|
67
|
-
- docs/getting-started.md
|
68
|
-
- docs/
|
69
|
-
- docs/
|
85
|
+
- docs/core/Footer.js
|
86
|
+
- docs/docs/associations.md
|
87
|
+
- docs/docs/attributes.md
|
88
|
+
- docs/docs/design-choices.md
|
89
|
+
- docs/docs/getting-started.md
|
90
|
+
- docs/docs/introduction.md
|
91
|
+
- docs/docs/performance.md
|
92
|
+
- docs/docs/response-bag.md
|
93
|
+
- docs/i18n/en.json
|
94
|
+
- docs/package-lock.json
|
95
|
+
- docs/package.json
|
96
|
+
- docs/sidebars.json
|
97
|
+
- docs/siteConfig.js
|
98
|
+
- docs/static/.DS_Store
|
99
|
+
- docs/static/css/custom.css
|
100
|
+
- docs/static/img/favicon.ico
|
101
|
+
- docs/static/img/oss_logo.png
|
102
|
+
- docs/static/img/undraw_code_review.svg
|
103
|
+
- docs/static/img/undraw_monitor.svg
|
104
|
+
- docs/static/img/undraw_note_list.svg
|
105
|
+
- docs/static/img/undraw_online.svg
|
106
|
+
- docs/static/img/undraw_open_source.svg
|
107
|
+
- docs/static/img/undraw_operating_system.svg
|
108
|
+
- docs/static/img/undraw_react.svg
|
109
|
+
- docs/static/img/undraw_tweetstorm.svg
|
110
|
+
- docs/static/img/undraw_youtube_tutorial.svg
|
111
|
+
- docs/static/index.html
|
70
112
|
- ext/panko_serializer/attributes_writer/active_record.c
|
71
113
|
- ext/panko_serializer/attributes_writer/active_record.h
|
72
114
|
- ext/panko_serializer/attributes_writer/attributes_writer.c
|
@@ -102,15 +144,15 @@ files:
|
|
102
144
|
- lib/panko/version.rb
|
103
145
|
- lib/panko_serializer.rb
|
104
146
|
- panko_serializer.gemspec
|
105
|
-
homepage: https://
|
147
|
+
homepage: https://panko.dev
|
106
148
|
licenses:
|
107
149
|
- MIT
|
108
150
|
metadata:
|
109
|
-
bug_tracker_uri: https://github.com/
|
110
|
-
source_code_uri: https://github.com/
|
111
|
-
documentation_uri: https://
|
112
|
-
changelog_uri: https://github.com/
|
113
|
-
post_install_message:
|
151
|
+
bug_tracker_uri: https://github.com/panko-serializer/panko_serializer/issues
|
152
|
+
source_code_uri: https://github.com/panko-serializer/panko_serializer
|
153
|
+
documentation_uri: https://panko-serializer.github.io/panko_serializer/
|
154
|
+
changelog_uri: https://github.com/panko-serializer/panko_serializer/releases
|
155
|
+
post_install_message:
|
114
156
|
rdoc_options: []
|
115
157
|
require_paths:
|
116
158
|
- lib
|
@@ -118,15 +160,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
118
160
|
requirements:
|
119
161
|
- - ">="
|
120
162
|
- !ruby/object:Gem::Version
|
121
|
-
version: 2.
|
163
|
+
version: 2.5.0
|
122
164
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
123
165
|
requirements:
|
124
166
|
- - ">="
|
125
167
|
- !ruby/object:Gem::Version
|
126
168
|
version: '0'
|
127
169
|
requirements: []
|
128
|
-
rubygems_version: 3.
|
129
|
-
signing_key:
|
170
|
+
rubygems_version: 3.2.20
|
171
|
+
signing_key:
|
130
172
|
specification_version: 4
|
131
173
|
summary: High Performance JSON Serialization for ActiveRecord & Ruby Objects
|
132
174
|
test_files: []
|
data/.travis.yml
DELETED
@@ -1,37 +0,0 @@
|
|
1
|
-
sudo: false
|
2
|
-
cache: bundler
|
3
|
-
language: ruby
|
4
|
-
rvm:
|
5
|
-
- 2.5.7
|
6
|
-
- 2.6.5
|
7
|
-
- 2.7.0
|
8
|
-
- ruby-head
|
9
|
-
|
10
|
-
env:
|
11
|
-
global:
|
12
|
-
- GIT_NAME: Travis CI
|
13
|
-
- GIT_EMAIL: nobody@nobody.org
|
14
|
-
|
15
|
-
matrix:
|
16
|
-
- "RAILS_VERSION=4.2.0"
|
17
|
-
- "RAILS_VERSION=5.2.0"
|
18
|
-
- "RAILS_VERSION=6.0.0"
|
19
|
-
|
20
|
-
install: bundle install --path=vendor/bundle --retry=3
|
21
|
-
|
22
|
-
before_install:
|
23
|
-
- gem install bundler
|
24
|
-
- nvm install 9
|
25
|
-
|
26
|
-
after_success:
|
27
|
-
- npm install docpress && $(npm bin)/docpress build
|
28
|
-
- if [ -n "$TRAVIS_TAG" -a "$TRAVIS_PULL_REQUEST" = "false" ]; then npm install git-update-ghpages && $(npm bin)/git-update-ghpages yosiat/panko_serializer _docpress; fi
|
29
|
-
- bundle exec rake benchmarks
|
30
|
-
|
31
|
-
matrix:
|
32
|
-
exclude:
|
33
|
-
- rvm: 2.7.0
|
34
|
-
env: RAILS_VERSION=4.2.0
|
35
|
-
allow_failures:
|
36
|
-
- rvm: ruby-head
|
37
|
-
fast_finish: true
|
data/docs/docpress.json
DELETED