panko_serializer 0.7.4 → 0.7.7
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 +2 -2
- data/.github/workflows/ruby.yml +10 -7
- data/Gemfile +3 -12
- data/docs/docs/introduction.md +1 -1
- data/docs/docs/performance.md +6 -6
- data/docs/package-lock.json +16058 -3702
- data/docs/package.json +1 -1
- data/ext/panko_serializer/attributes_writer/attributes_writer.c +3 -5
- data/ext/panko_serializer/attributes_writer/attributes_writer.h +1 -1
- data/ext/panko_serializer/attributes_writer/type_cast/type_cast.c +16 -0
- data/ext/panko_serializer/panko_serializer.c +9 -2
- 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 +1 -1
- data/lib/panko/serializer.rb +10 -2
- data/lib/panko/serializer_resolver.rb +29 -15
- data/lib/panko/version.rb +1 -1
- data/panko_serializer.gemspec +2 -1
- metadata +26 -6
data/docs/package.json
CHANGED
@@ -2,7 +2,6 @@
|
|
2
2
|
|
3
3
|
static bool types_initialized = false;
|
4
4
|
static VALUE ar_base_type = Qundef;
|
5
|
-
static VALUE hash_type = Qundef;
|
6
5
|
|
7
6
|
VALUE init_types(VALUE v) {
|
8
7
|
if (types_initialized == true) {
|
@@ -15,8 +14,7 @@ VALUE init_types(VALUE v) {
|
|
15
14
|
rb_const_get_at(rb_cObject, rb_intern("ActiveRecord"));
|
16
15
|
|
17
16
|
ar_base_type = rb_const_get_at(ar_type, rb_intern("Base"));
|
18
|
-
|
19
|
-
hash_type = rb_const_get_at(rb_cObject, rb_intern("Hash"));
|
17
|
+
rb_global_variable(&ar_base_type);
|
20
18
|
|
21
19
|
return Qundef;
|
22
20
|
}
|
@@ -35,7 +33,7 @@ AttributesWriter create_attributes_writer(VALUE object) {
|
|
35
33
|
.write_attributes = active_record_attributes_writer};
|
36
34
|
}
|
37
35
|
|
38
|
-
if (
|
36
|
+
if (!RB_SPECIAL_CONST_P(object) && BUILTIN_TYPE(object) == T_HASH) {
|
39
37
|
return (AttributesWriter){.object_type = Hash,
|
40
38
|
.write_attributes = hash_attributes_writer};
|
41
39
|
}
|
@@ -50,7 +48,7 @@ void empty_write_attributes(VALUE obj, VALUE attributes, EachAttributeFunc func,
|
|
50
48
|
VALUE writer) {}
|
51
49
|
|
52
50
|
AttributesWriter create_empty_attributes_writer() {
|
53
|
-
return (AttributesWriter){.object_type =
|
51
|
+
return (AttributesWriter){.object_type = UnknownObjectType,
|
54
52
|
.write_attributes = empty_write_attributes};
|
55
53
|
}
|
56
54
|
|
@@ -7,7 +7,7 @@
|
|
7
7
|
#include "plain.h"
|
8
8
|
#include "hash.h"
|
9
9
|
|
10
|
-
enum ObjectType {
|
10
|
+
enum ObjectType { UnknownObjectType = 0, ActiveRecord = 1, Plain = 2, Hash = 3 };
|
11
11
|
|
12
12
|
typedef struct _AttributesWriter {
|
13
13
|
enum ObjectType object_type;
|
@@ -362,4 +362,20 @@ void panko_init_type_cast(VALUE mPanko) {
|
|
362
362
|
rb_define_singleton_method(mPanko, "_type_cast", public_type_cast, -1);
|
363
363
|
|
364
364
|
panko_init_time(mPanko);
|
365
|
+
|
366
|
+
rb_global_variable(&oj_type);
|
367
|
+
rb_global_variable(&oj_parseerror_type);
|
368
|
+
rb_global_variable(&ar_string_type);
|
369
|
+
rb_global_variable(&ar_text_type);
|
370
|
+
rb_global_variable(&ar_float_type);
|
371
|
+
rb_global_variable(&ar_integer_type);
|
372
|
+
rb_global_variable(&ar_boolean_type);
|
373
|
+
rb_global_variable(&ar_date_time_type);
|
374
|
+
rb_global_variable(&ar_time_zone_converter);
|
375
|
+
rb_global_variable(&ar_json_type);
|
376
|
+
rb_global_variable(&ar_pg_integer_type);
|
377
|
+
rb_global_variable(&ar_pg_float_type);
|
378
|
+
rb_global_variable(&ar_pg_uuid_type);
|
379
|
+
rb_global_variable(&ar_pg_json_type);
|
380
|
+
rb_global_variable(&ar_pg_date_time_type);
|
365
381
|
}
|
@@ -13,6 +13,8 @@ static ID to_a_id;
|
|
13
13
|
static ID object_id;
|
14
14
|
static ID serialization_context_id;
|
15
15
|
|
16
|
+
static VALUE SKIP = Qundef;
|
17
|
+
|
16
18
|
void write_value(VALUE str_writer, VALUE key, VALUE value, VALUE isJson) {
|
17
19
|
if(isJson == Qtrue) {
|
18
20
|
rb_funcall(str_writer, push_json_id, 2, value, key);
|
@@ -40,8 +42,9 @@ void serialize_method_fields(VALUE object, VALUE str_writer,
|
|
40
42
|
Attribute attribute = PANKO_ATTRIBUTE_READ(raw_attribute);
|
41
43
|
|
42
44
|
volatile VALUE result = rb_funcall(serializer, attribute->name_id, 0);
|
43
|
-
|
44
|
-
|
45
|
+
if (result != SKIP) {
|
46
|
+
write_value(str_writer, attribute->name_str, result, Qfalse);
|
47
|
+
}
|
45
48
|
}
|
46
49
|
|
47
50
|
rb_ivar_set(serializer, object_id, Qnil);
|
@@ -167,6 +170,10 @@ void Init_panko_serializer() {
|
|
167
170
|
rb_define_singleton_method(mPanko, "serialize_objects", serialize_objects_api,
|
168
171
|
3);
|
169
172
|
|
173
|
+
VALUE mPankoSerializer = rb_const_get(mPanko, rb_intern("Serializer"));
|
174
|
+
SKIP = rb_const_get(mPankoSerializer, rb_intern("SKIP"));
|
175
|
+
rb_global_variable(&SKIP);
|
176
|
+
|
170
177
|
panko_init_serialization_descriptor(mPanko);
|
171
178
|
init_attributes_writer(mPanko);
|
172
179
|
panko_init_type_cast(mPanko);
|
@@ -77,6 +77,7 @@ VALUE association_decriptor_aset(VALUE self, VALUE descriptor) {
|
|
77
77
|
|
78
78
|
void panko_init_association(VALUE mPanko) {
|
79
79
|
cAssociation = rb_define_class_under(mPanko, "Association", rb_cObject);
|
80
|
+
rb_global_variable(&cAssociation);
|
80
81
|
|
81
82
|
rb_define_module_function(cAssociation, "new", association_new, -1);
|
82
83
|
|
@@ -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
|
|
@@ -49,7 +49,7 @@ SerializationDescriptor sd_read(VALUE descriptor) {
|
|
49
49
|
}
|
50
50
|
|
51
51
|
void sd_set_writer(SerializationDescriptor sd, VALUE object) {
|
52
|
-
if (sd->attributes_writer.object_type !=
|
52
|
+
if (sd->attributes_writer.object_type != UnknownObjectType) {
|
53
53
|
return;
|
54
54
|
}
|
55
55
|
|
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,10 @@ module Panko
|
|
73
75
|
|
74
76
|
def has_one(name, options = {})
|
75
77
|
serializer_const = options[:serializer]
|
76
|
-
|
78
|
+
if serializer_const.kind_of?(String)
|
79
|
+
serializer_const = Panko::SerializerResolver.resolve(serializer_const, self)
|
80
|
+
end
|
81
|
+
serializer_const ||= Panko::SerializerResolver.resolve(name.to_s, self)
|
77
82
|
|
78
83
|
raise "Can't find serializer for #{self.name}.#{name} has_one relationship." if serializer_const.nil?
|
79
84
|
|
@@ -86,7 +91,10 @@ module Panko
|
|
86
91
|
|
87
92
|
def has_many(name, options = {})
|
88
93
|
serializer_const = options[:serializer] || options[:each_serializer]
|
89
|
-
|
94
|
+
if serializer_const.kind_of?(String)
|
95
|
+
serializer_const = Panko::SerializerResolver.resolve(serializer_const, self)
|
96
|
+
end
|
97
|
+
serializer_const ||= Panko::SerializerResolver.resolve(name.to_s, self)
|
90
98
|
|
91
99
|
raise "Can't find serializer for #{self.name}.#{name} has_many relationship." if serializer_const.nil?
|
92
100
|
|
@@ -1,25 +1,39 @@
|
|
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 ||= safe_serializer_get(name)
|
17
|
+
serializer_const
|
18
|
+
end
|
13
19
|
|
14
|
-
|
20
|
+
private
|
15
21
|
|
16
|
-
|
17
|
-
|
18
|
-
|
22
|
+
if Module.method_defined?(:module_parent_name)
|
23
|
+
def namespace_for(from)
|
24
|
+
from.module_parent_name
|
25
|
+
end
|
26
|
+
else
|
27
|
+
def namespace_for(from)
|
28
|
+
from.parent_name
|
29
|
+
end
|
30
|
+
end
|
19
31
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
32
|
+
def safe_serializer_get(name)
|
33
|
+
const = Object.const_get(name)
|
34
|
+
const < Panko::Serializer ? const : nil
|
35
|
+
rescue NameError
|
36
|
+
nil
|
37
|
+
end
|
24
38
|
end
|
25
39
|
end
|
data/lib/panko/version.rb
CHANGED
data/panko_serializer.gemspec
CHANGED
metadata
CHANGED
@@ -1,29 +1,49 @@
|
|
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.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yosi Attias
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-06-04 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:
|
46
|
+
version: '0'
|
27
47
|
description:
|
28
48
|
email:
|
29
49
|
- yosy101@gmail.com
|