panko_serializer 0.5.9 → 0.5.10

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 63ba1589249e7119add78bbd81491fd03a58cc76e0ad9d78598a2d7e39190421
4
- data.tar.gz: 1fff975d250c4c05de70a84e680f41caf7e1bee10f2884bfbbe0504d1137f33a
3
+ metadata.gz: 7ec2a5cbfc062d6b8e272f038638645e3289b94dc9aa730f2317082d1ff2d9c4
4
+ data.tar.gz: e2d04c62d3b1fcf2f292170181e3a4f689367af7d3cc53719bbbcfc6a7eea9af
5
5
  SHA512:
6
- metadata.gz: 8823f02c307fa4baf1346f0ab89e6eb8c2b415b8739a8e5ee0f4d8ceb30b010fa34002958d8197852468736cdb9257435fabcc03ae64c001d000343a58a223dd
7
- data.tar.gz: e7eb68e825b8483d203a603ca54ee475ebd08fdbec32633408bab40365f03b90de017374d0a15a96e25476bfc1ff06b322a1042edbe17a2d948811327c44ae61
6
+ metadata.gz: 80ec461198ad3a7fd1db51a692686b1a90874444a1f6c2c9cde22aef40cf5a79b597804d6ba6aa77b5f7f8e765e5e2dd5b95401b9817b3a8dd5136a1e849fa36
7
+ data.tar.gz: 7637de2f896f9c6a6b788da226fda929ca28f944eaa1b2b0a4f00f3dd95a771350b6fe0975459502669dadbccc565008708a38263c4baa71f892c95bd8531242
data/.travis.yml CHANGED
@@ -2,8 +2,9 @@ sudo: false
2
2
  cache: bundler
3
3
  language: ruby
4
4
  rvm:
5
- - 2.5.3
6
- - 2.6.0
5
+ - 2.3.8
6
+ - 2.5.5
7
+ - 2.6.3
7
8
 
8
9
  env:
9
10
  global:
@@ -25,3 +26,8 @@ env:
25
26
  matrix:
26
27
  - "RAILS_VERSION=4.2.0"
27
28
  - "RAILS_VERSION=5.2.0"
29
+ - "RAILS_VERSION=6.0.0.beta3"
30
+
31
+ matrix:
32
+ allow_failures:
33
+ - "RAILS_VERSION=6.0.0.beta3"
data/Gemfile CHANGED
@@ -11,8 +11,13 @@ gem "activemodel", rails_version
11
11
  gem "activerecord", rails_version, group: :test
12
12
 
13
13
  group :benchmarks do
14
- gem "sqlite3"
15
- gem "pg", "0.21"
14
+ gem "sqlite3", "~> 1.3.6"
15
+
16
+ if raw_rails_version.include? "4.2"
17
+ gem "pg", "~> 0.15"
18
+ else
19
+ gem "pg", ">= 0.18", "< 2.0"
20
+ end
16
21
 
17
22
  gem "memory_profiler"
18
23
  gem "ruby-prof"
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Panko
2
2
 
3
- [![Build Status](https://api.travis-ci.com/yosiat/panko_serializer.svg?branch=master)](https://travis-ci.org/yosiat/panko_serializer)
3
+ [![Build Status](https://api.travis-ci.com/yosiat/panko_serializer.svg?branch=master)](https://travis-ci.com/yosiat/panko_serializer)
4
4
 
5
5
  Panko is library which is inspired by ActiveModelSerializers 0.9 for serializing ActiveRecord/Ruby objects to JSON strings, fast.
6
6
 
data/Rakefile CHANGED
@@ -37,8 +37,7 @@ def run_process(cmd)
37
37
  lines << line
38
38
  end
39
39
  rescue Errno::EIO
40
- puts "Errno:EIO error, but this probably just means " +
41
- "that the process has finished giving output - #{cmd}"
40
+ # ignore this
42
41
  end
43
42
  end
44
43
 
@@ -56,12 +55,10 @@ def run_benchmarks(files, items_count: 2_300)
56
55
  rows = lines.map do |line|
57
56
  begin
58
57
  row = JSON.parse(line)
58
+ row.values
59
59
  rescue JSON::ParserError
60
- puts "> Failed parsing json"
61
- puts lines.join
62
- exit
60
+ puts "> [ERROR] Failed running #{benchmark_file} - #{lines.join}"
63
61
  end
64
- row.values
65
62
  end
66
63
 
67
64
  puts "\n\n"
@@ -17,13 +17,13 @@ VALUE init_types(VALUE v) {
17
17
  return Qundef;
18
18
  }
19
19
 
20
- AttributesWriter create_attributes_writer(VALUE subject) {
20
+ AttributesWriter create_attributes_writer(VALUE object) {
21
21
  // If ActiveRecord::Base can't be found it will throw error
22
22
  int isErrored;
23
23
  rb_protect(init_types, Qnil, &isErrored);
24
24
 
25
25
  if (ar_base_type != Qundef &&
26
- rb_obj_is_kind_of(subject, ar_base_type) == Qtrue) {
26
+ rb_obj_is_kind_of(object, ar_base_type) == Qtrue) {
27
27
  return (AttributesWriter){
28
28
  .object_type = ActiveRecord,
29
29
  .write_attributes = active_record_attributes_writer};
@@ -11,16 +11,14 @@ enum ObjectType { Unknown = 0, ActiveRecord = 1, Plain = 2 };
11
11
  typedef struct _AttributesWriter {
12
12
  enum ObjectType object_type;
13
13
 
14
- void (*write_attributes)(VALUE object,
15
- VALUE attributes,
16
- EachAttributeFunc func,
17
- VALUE context);
14
+ void (*write_attributes)(VALUE object, VALUE attributes,
15
+ EachAttributeFunc func, VALUE context);
18
16
  } AttributesWriter;
19
17
 
20
18
  /**
21
- * Infers the attributes writer from the subject type
19
+ * Infers the attributes writer from the object type
22
20
  */
23
- AttributesWriter create_attributes_writer(VALUE subject);
21
+ AttributesWriter create_attributes_writer(VALUE object);
24
22
 
25
23
  /**
26
24
  * Creates empty writer
@@ -74,3 +74,9 @@ static struct _TypeCast type_casts[] = {
74
74
 
75
75
  extern VALUE type_cast(VALUE type_metadata, VALUE value);
76
76
  void panko_init_type_cast(VALUE mPanko);
77
+
78
+ // Introduced in ruby 2.4
79
+ #ifndef RB_INTEGER_TYPE_P
80
+ # define RB_INTEGER_TYPE_P(obj) (RB_FIXNUM_P(obj) || RB_TYPE_P(obj, T_BIGNUM))
81
+ #endif
82
+
@@ -16,7 +16,7 @@ void write_value(VALUE str_writer, VALUE key, VALUE value) {
16
16
  rb_funcall(str_writer, push_value_id, 2, value, key);
17
17
  }
18
18
 
19
- void serialize_method_fields(VALUE subject, VALUE str_writer,
19
+ void serialize_method_fields(VALUE object, VALUE str_writer,
20
20
  SerializationDescriptor descriptor) {
21
21
  if (RARRAY_LEN(descriptor->method_fields) == 0) {
22
22
  return;
@@ -28,7 +28,7 @@ void serialize_method_fields(VALUE subject, VALUE str_writer,
28
28
  method_fields = descriptor->method_fields;
29
29
 
30
30
  serializer = descriptor->serializer;
31
- rb_ivar_set(serializer, object_id, subject);
31
+ rb_ivar_set(serializer, object_id, object);
32
32
 
33
33
  for (i = 0; i < RARRAY_LEN(method_fields); i++) {
34
34
  volatile VALUE raw_attribute = RARRAY_AREF(method_fields, i);
@@ -42,65 +42,65 @@ void serialize_method_fields(VALUE subject, VALUE str_writer,
42
42
  rb_ivar_set(serializer, object_id, Qnil);
43
43
  }
44
44
 
45
- void serialize_fields(VALUE subject, VALUE str_writer,
45
+ void serialize_fields(VALUE object, VALUE str_writer,
46
46
  SerializationDescriptor descriptor) {
47
- descriptor->attributes_writer.write_attributes(
48
- subject, descriptor->attributes, write_value, str_writer);
47
+ descriptor->attributes_writer.write_attributes(object, descriptor->attributes,
48
+ write_value, str_writer);
49
49
 
50
- serialize_method_fields(subject, str_writer, descriptor);
50
+ serialize_method_fields(object, str_writer, descriptor);
51
51
  }
52
52
 
53
- void serialize_has_one_associations(VALUE subject, VALUE str_writer,
53
+ void serialize_has_one_associations(VALUE object, VALUE str_writer,
54
54
  VALUE associations) {
55
55
  long i;
56
56
  for (i = 0; i < RARRAY_LEN(associations); i++) {
57
57
  volatile VALUE association_el = RARRAY_AREF(associations, i);
58
58
  Association association = association_read(association_el);
59
59
 
60
- volatile VALUE value = rb_funcall(subject, association->name_id, 0);
60
+ volatile VALUE value = rb_funcall(object, association->name_id, 0);
61
61
 
62
62
  if (NIL_P(value)) {
63
63
  write_value(str_writer, association->name_str, value);
64
64
  } else {
65
- serialize_subject(association->name_str, value, str_writer,
66
- association->descriptor);
65
+ serialize_object(association->name_str, value, str_writer,
66
+ association->descriptor);
67
67
  }
68
68
  }
69
69
  }
70
70
 
71
- void serialize_has_many_associations(VALUE subject, VALUE str_writer,
71
+ void serialize_has_many_associations(VALUE object, VALUE str_writer,
72
72
  VALUE associations) {
73
73
  long i;
74
74
  for (i = 0; i < RARRAY_LEN(associations); i++) {
75
75
  volatile VALUE association_el = RARRAY_AREF(associations, i);
76
76
  Association association = association_read(association_el);
77
77
 
78
- volatile VALUE value = rb_funcall(subject, association->name_id, 0);
78
+ volatile VALUE value = rb_funcall(object, association->name_id, 0);
79
79
 
80
80
  if (NIL_P(value)) {
81
81
  write_value(str_writer, association->name_str, value);
82
82
  } else {
83
- serialize_subjects(association->name_str, value, str_writer,
84
- association->descriptor);
83
+ serialize_objects(association->name_str, value, str_writer,
84
+ association->descriptor);
85
85
  }
86
86
  }
87
87
  }
88
88
 
89
- VALUE serialize_subject(VALUE key, VALUE subject, VALUE str_writer,
90
- SerializationDescriptor descriptor) {
91
- sd_set_writer(descriptor, subject);
89
+ VALUE serialize_object(VALUE key, VALUE object, VALUE str_writer,
90
+ SerializationDescriptor descriptor) {
91
+ sd_set_writer(descriptor, object);
92
92
 
93
93
  rb_funcall(str_writer, push_object_id, 1, key);
94
94
 
95
- serialize_fields(subject, str_writer, descriptor);
95
+ serialize_fields(object, str_writer, descriptor);
96
96
 
97
97
  if (RARRAY_LEN(descriptor->has_one_associations) > 0) {
98
- serialize_has_one_associations(subject, str_writer,
98
+ serialize_has_one_associations(object, str_writer,
99
99
  descriptor->has_one_associations);
100
100
  }
101
101
 
102
102
  if (RARRAY_LEN(descriptor->has_many_associations) > 0) {
103
- serialize_has_many_associations(subject, str_writer,
103
+ serialize_has_many_associations(object, str_writer,
104
104
  descriptor->has_many_associations);
105
105
  }
106
106
 
@@ -109,19 +109,19 @@ VALUE serialize_subject(VALUE key, VALUE subject, VALUE str_writer,
109
109
  return Qnil;
110
110
  }
111
111
 
112
- VALUE serialize_subjects(VALUE key, VALUE subjects, VALUE str_writer,
113
- SerializationDescriptor descriptor) {
112
+ VALUE serialize_objects(VALUE key, VALUE objects, VALUE str_writer,
113
+ SerializationDescriptor descriptor) {
114
114
  long i;
115
115
 
116
116
  rb_funcall(str_writer, push_array_id, 1, key);
117
117
 
118
- if (!RB_TYPE_P(subjects, T_ARRAY)) {
119
- subjects = rb_funcall(subjects, to_a_id, 0);
118
+ if (!RB_TYPE_P(objects, T_ARRAY)) {
119
+ objects = rb_funcall(objects, to_a_id, 0);
120
120
  }
121
121
 
122
- for (i = 0; i < RARRAY_LEN(subjects); i++) {
123
- volatile VALUE subject = RARRAY_AREF(subjects, i);
124
- serialize_subject(Qnil, subject, str_writer, descriptor);
122
+ for (i = 0; i < RARRAY_LEN(objects); i++) {
123
+ volatile VALUE object = RARRAY_AREF(objects, i);
124
+ serialize_object(Qnil, object, str_writer, descriptor);
125
125
  }
126
126
 
127
127
  rb_funcall(str_writer, pop_id, 0);
@@ -129,15 +129,15 @@ VALUE serialize_subjects(VALUE key, VALUE subjects, VALUE str_writer,
129
129
  return Qnil;
130
130
  }
131
131
 
132
- VALUE serialize_subject_api(VALUE klass, VALUE subject, VALUE str_writer,
133
- VALUE descriptor) {
132
+ VALUE serialize_object_api(VALUE klass, VALUE object, VALUE str_writer,
133
+ VALUE descriptor) {
134
134
  SerializationDescriptor sd = sd_read(descriptor);
135
- return serialize_subject(Qnil, subject, str_writer, sd);
135
+ return serialize_object(Qnil, object, str_writer, sd);
136
136
  }
137
137
 
138
- VALUE serialize_subjects_api(VALUE klass, VALUE subjects, VALUE str_writer,
139
- VALUE descriptor) {
140
- serialize_subjects(Qnil, subjects, str_writer, sd_read(descriptor));
138
+ VALUE serialize_objects_api(VALUE klass, VALUE objects, VALUE str_writer,
139
+ VALUE descriptor) {
140
+ serialize_objects(Qnil, objects, str_writer, sd_read(descriptor));
141
141
 
142
142
  return Qnil;
143
143
  }
@@ -153,11 +153,11 @@ void Init_panko_serializer() {
153
153
 
154
154
  VALUE mPanko = rb_define_module("Panko");
155
155
 
156
- rb_define_singleton_method(mPanko, "serialize_subject", serialize_subject_api,
156
+ rb_define_singleton_method(mPanko, "serialize_object", serialize_object_api,
157
157
  3);
158
158
 
159
- rb_define_singleton_method(mPanko, "serialize_subjects",
160
- serialize_subjects_api, 3);
159
+ rb_define_singleton_method(mPanko, "serialize_objects", serialize_objects_api,
160
+ 3);
161
161
 
162
162
  panko_init_serialization_descriptor(mPanko);
163
163
  init_attributes_writer(mPanko);
@@ -5,12 +5,8 @@
5
5
  #include "serialization_descriptor/attribute.h"
6
6
  #include "serialization_descriptor/serialization_descriptor.h"
7
7
 
8
- VALUE serialize_subject(VALUE key,
9
- VALUE subject,
10
- VALUE str_writer,
11
- SerializationDescriptor descriptor);
8
+ VALUE serialize_object(VALUE key, VALUE object, VALUE str_writer,
9
+ SerializationDescriptor descriptor);
12
10
 
13
- VALUE serialize_subjects(VALUE key,
14
- VALUE subjects,
15
- VALUE str_writer,
16
- SerializationDescriptor descriptor);
11
+ VALUE serialize_objects(VALUE key, VALUE objects, VALUE str_writer,
12
+ SerializationDescriptor descriptor);
@@ -50,12 +50,12 @@ SerializationDescriptor sd_read(VALUE descriptor) {
50
50
  return (SerializationDescriptor)DATA_PTR(descriptor);
51
51
  }
52
52
 
53
- void sd_set_writer(SerializationDescriptor sd, VALUE subject) {
53
+ void sd_set_writer(SerializationDescriptor sd, VALUE object) {
54
54
  if (sd->attributes_writer.object_type != Unknown) {
55
55
  return;
56
56
  }
57
57
 
58
- sd->attributes_writer = create_attributes_writer(subject);
58
+ sd->attributes_writer = create_attributes_writer(object);
59
59
  }
60
60
 
61
61
  VALUE sd_serializer_set(VALUE self, VALUE serializer) {
@@ -25,6 +25,6 @@ SerializationDescriptor sd_read(VALUE descriptor);
25
25
 
26
26
  void sd_mark(SerializationDescriptor data);
27
27
 
28
- void sd_set_writer(SerializationDescriptor sd, VALUE subject);
28
+ void sd_set_writer(SerializationDescriptor sd, VALUE object);
29
29
 
30
30
  void panko_init_serialization_descriptor(VALUE mPanko);
@@ -2,10 +2,10 @@
2
2
 
3
3
  module Panko
4
4
  class ArraySerializer
5
- attr_accessor :subjects
5
+ attr_accessor :objects
6
6
 
7
- def initialize(subjects, options = {})
8
- @subjects = subjects
7
+ def initialize(objects, options = {})
8
+ @objects = objects
9
9
  @each_serializer = options[:each_serializer]
10
10
 
11
11
  if @each_serializer.nil?
@@ -27,20 +27,20 @@ Please pass valid each_serializer to ArraySerializer, for example:
27
27
  end
28
28
 
29
29
  def to_json
30
- serialize_to_json @subjects
30
+ serialize_to_json @objects
31
31
  end
32
32
 
33
- def serialize(subjects)
34
- Oj.load(serialize_to_json(subjects))
33
+ def serialize(objects)
34
+ Oj.load(serialize_to_json(objects))
35
35
  end
36
36
 
37
37
  def to_a
38
- Oj.load(serialize_to_json(@subjects))
38
+ Oj.load(serialize_to_json(@objects))
39
39
  end
40
40
 
41
- def serialize_to_json(subjects)
41
+ def serialize_to_json(objects)
42
42
  writer = Oj::StringWriter.new(mode: :rails)
43
- Panko.serialize_subjects(subjects.to_a, writer, @descriptor)
43
+ Panko.serialize_objects(objects.to_a, writer, @descriptor)
44
44
  @descriptor.set_serialization_context(nil) unless @serialization_context.is_a?(EmptySerializerContext)
45
45
  writer.to_s
46
46
  end
@@ -120,7 +120,7 @@ module Panko
120
120
 
121
121
  def serialize_to_json(object)
122
122
  writer = Oj::StringWriter.new(mode: :rails)
123
- Panko.serialize_subject(object, writer, @descriptor)
123
+ Panko.serialize_object(object, writer, @descriptor)
124
124
  @descriptor.set_serialization_context(nil) unless @serialization_context.is_a?(EmptySerializerContext)
125
125
  writer.to_s
126
126
  end
data/lib/panko/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Panko
4
- VERSION = "0.5.9"
4
+ VERSION = "0.5.10"
5
5
  end
@@ -21,7 +21,7 @@ Gem::Specification.new do |spec|
21
21
  "changelog_uri" => "https://github.com/yosiat/panko_serializer/releases"
22
22
  }
23
23
 
24
- spec.required_ruby_version = ">= 2.0"
24
+ spec.required_ruby_version = ">= 2.3.7"
25
25
 
26
26
  spec.files = `git ls-files -z`.split("\x0").reject do |f|
27
27
  f.match(%r{^(test|spec|features)/})
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.5.9
4
+ version: 0.5.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yosi Attias
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-01-05 00:00:00.000000000 Z
11
+ date: 2019-04-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: oj
@@ -113,14 +113,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
113
113
  requirements:
114
114
  - - ">="
115
115
  - !ruby/object:Gem::Version
116
- version: '2.0'
116
+ version: 2.3.7
117
117
  required_rubygems_version: !ruby/object:Gem::Requirement
118
118
  requirements:
119
119
  - - ">="
120
120
  - !ruby/object:Gem::Version
121
121
  version: '0'
122
122
  requirements: []
123
- rubygems_version: 3.0.1
123
+ rubygems_version: 3.0.3
124
124
  signing_key:
125
125
  specification_version: 4
126
126
  summary: High Performance JSON Serialization for ActiveRecord & Ruby Objects