panko_serializer 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -1
- data/benchmarks/type_casts/support.rb +1 -1
- data/ext/panko_serializer/attributes_iterator.c +30 -5
- data/ext/panko_serializer/attributes_iterator.h +1 -1
- data/ext/panko_serializer/panko_serializer.c +1 -2
- data/ext/panko_serializer/time_conversion.c +1 -2
- data/lib/panko/serialization_descriptor.rb +1 -0
- data/lib/panko/serializer.rb +5 -10
- data/lib/panko/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ba52569ddbbd4f0de8ea0cd554f7df5fdf78340e
|
4
|
+
data.tar.gz: ae21f470b06c1576077e2f56211fb00b36c91118
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9acdd06de3e6268bbacdcdc97e897357534253728cbac9f8311682ccd5c468abccce8d89226cb7d1c7b811c67ff4a103951b5030128fdf0865f0dfd62823e43f
|
7
|
+
data.tar.gz: a4aa910864f1aa16ac0a57f4004a8b9698f06233e2ad83c8193d2b7fb22cbd26a17871248e34c2e84fe78e888456392c375ef8c73e4cec0ba00faf8d1885a00c
|
data/README.md
CHANGED
@@ -1,8 +1,9 @@
|
|
1
1
|
# Panko
|
2
2
|
|
3
|
-
[![Build Status](https://travis-ci.org/yosiat/
|
3
|
+
[![Build Status](https://travis-ci.org/yosiat/panko_serializer.svg?branch=master)](https://travis-ci.org/yosiat/panko_serializer)
|
4
4
|
|
5
5
|
|
6
6
|
## License
|
7
7
|
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
8
8
|
|
9
|
+
|
@@ -7,7 +7,7 @@ require "pg"
|
|
7
7
|
|
8
8
|
|
9
9
|
require_relative "../benchmarking_support"
|
10
|
-
require_relative "../../lib/panko/
|
10
|
+
require_relative "../../lib/panko/panko_serializer"
|
11
11
|
|
12
12
|
def assert(type_name, from, to)
|
13
13
|
raise "#{type_name} - #{from.class} is not equals to #{to.class}" unless from.to_json == to.to_json
|
@@ -3,6 +3,10 @@
|
|
3
3
|
static ID attributes_id = 0;
|
4
4
|
static ID types_id = 0;
|
5
5
|
static ID values_id = 0;
|
6
|
+
static ID delegate_hash_id = 0;
|
7
|
+
|
8
|
+
static ID value_before_type_cast_id = 0;
|
9
|
+
static ID type_id = 0;
|
6
10
|
|
7
11
|
VALUE read_attributes(VALUE obj) {
|
8
12
|
return rb_ivar_get(obj, attributes_id);
|
@@ -30,24 +34,42 @@ void panko_read_types_and_value(VALUE attributes_hash,
|
|
30
34
|
}
|
31
35
|
|
32
36
|
VALUE panko_each_attribute(VALUE obj,
|
33
|
-
SerializationDescriptor descriptor,
|
34
37
|
VALUE attributes,
|
35
38
|
EachAttributeFunc func,
|
36
39
|
VALUE context) {
|
37
40
|
VALUE attributes_hash = panko_read_lazy_attributes_hash(obj);
|
38
|
-
if(attributes_hash == Qnil) {
|
41
|
+
if (attributes_hash == Qnil) {
|
39
42
|
return Qnil;
|
40
43
|
}
|
41
44
|
|
45
|
+
VALUE delegate_hash = rb_ivar_get(attributes_hash, delegate_hash_id);
|
46
|
+
bool tryToReadFromDelegateHash = RHASH_SIZE(delegate_hash) > 0;
|
47
|
+
|
42
48
|
VALUE types, values;
|
43
49
|
panko_read_types_and_value(attributes_hash, &types, &values);
|
44
50
|
|
45
51
|
int i;
|
46
52
|
for (i = 0; i < RARRAY_LEN(attributes); i++) {
|
47
|
-
VALUE member =
|
53
|
+
VALUE member = RARRAY_AREF(attributes, i);
|
54
|
+
|
55
|
+
VALUE value = Qundef;
|
56
|
+
VALUE type_metadata = Qnil;
|
57
|
+
|
58
|
+
// First try to read from delegate hash,
|
59
|
+
// If the object was create in memory `User.new(name: "Yosi")`
|
60
|
+
// it won't exist in types/values
|
61
|
+
if (tryToReadFromDelegateHash) {
|
62
|
+
VALUE attribute_metadata = rb_hash_aref(delegate_hash, member);
|
63
|
+
if (attribute_metadata != Qnil) {
|
64
|
+
value = rb_ivar_get(attribute_metadata, value_before_type_cast_id);
|
65
|
+
type_metadata = rb_ivar_get(attribute_metadata, type_id);
|
66
|
+
}
|
67
|
+
}
|
48
68
|
|
49
|
-
|
50
|
-
|
69
|
+
if (value == Qundef) {
|
70
|
+
value = rb_hash_aref(values, member);
|
71
|
+
type_metadata = rb_hash_aref(types, member);
|
72
|
+
}
|
51
73
|
|
52
74
|
func(obj, member, value, type_metadata, context);
|
53
75
|
}
|
@@ -57,6 +79,9 @@ VALUE panko_each_attribute(VALUE obj,
|
|
57
79
|
|
58
80
|
void panko_init_attributes_iterator(VALUE mPanko) {
|
59
81
|
attributes_id = rb_intern("@attributes");
|
82
|
+
delegate_hash_id = rb_intern("@delegate_hash");
|
60
83
|
values_id = rb_intern("@values");
|
61
84
|
types_id = rb_intern("@types");
|
85
|
+
type_id = rb_intern("@type");
|
86
|
+
value_before_type_cast_id = rb_intern("@value_before_type_cast");
|
62
87
|
}
|
@@ -1,4 +1,5 @@
|
|
1
1
|
#include <ruby.h>
|
2
|
+
#include <stdbool.h>
|
2
3
|
|
3
4
|
#include "serialization_descriptor.h"
|
4
5
|
|
@@ -9,7 +10,6 @@ typedef void (*EachAttributeFunc)(VALUE object,
|
|
9
10
|
VALUE context);
|
10
11
|
|
11
12
|
extern VALUE panko_each_attribute(VALUE object,
|
12
|
-
SerializationDescriptor descriptor,
|
13
13
|
VALUE attributes,
|
14
14
|
EachAttributeFunc func,
|
15
15
|
VALUE context);
|
@@ -53,8 +53,7 @@ void serialize_fields(VALUE subject,
|
|
53
53
|
VALUE str_writer,
|
54
54
|
SerializationDescriptor descriptor,
|
55
55
|
VALUE context) {
|
56
|
-
panko_each_attribute(subject, descriptor
|
57
|
-
panko_attributes_iter, str_writer);
|
56
|
+
panko_each_attribute(subject, descriptor->fields, panko_attributes_iter, str_writer);
|
58
57
|
|
59
58
|
serialize_method_fields(subject, str_writer, descriptor, context);
|
60
59
|
}
|
data/lib/panko/serializer.rb
CHANGED
@@ -34,23 +34,18 @@ module Panko
|
|
34
34
|
def initialize(options = {})
|
35
35
|
@descriptor = Panko::CACHE.fetch(self.class, options)
|
36
36
|
|
37
|
-
@context = options
|
38
|
-
@object = nil
|
37
|
+
@context = options[:context]
|
39
38
|
end
|
40
39
|
|
41
40
|
attr_reader :object, :context
|
42
|
-
attr_writer :object
|
43
41
|
|
44
|
-
def serialize(object
|
45
|
-
Oj.load(serialize_to_json(object
|
42
|
+
def serialize(object)
|
43
|
+
Oj.load(serialize_to_json(object))
|
46
44
|
end
|
47
45
|
|
48
|
-
def serialize_to_json(object
|
49
|
-
|
50
|
-
|
51
|
-
writer ||= Oj::StringWriter.new(mode: :rails)
|
46
|
+
def serialize_to_json(object)
|
47
|
+
writer = Oj::StringWriter.new(mode: :rails)
|
52
48
|
Panko::serialize_subject(object, writer, @descriptor, @context)
|
53
|
-
|
54
49
|
writer.to_s
|
55
50
|
end
|
56
51
|
end
|
data/lib/panko/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: panko_serializer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yosi Attias
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-08-
|
11
|
+
date: 2017-08-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|