panko_serializer 0.7.7 → 0.8.0

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.
Files changed (54) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/lint.yml +40 -0
  3. data/.github/workflows/ruby.yml +35 -39
  4. data/.standard.yml +4 -0
  5. data/Gemfile +4 -3
  6. data/README.md +1 -1
  7. data/Rakefile +32 -33
  8. data/benchmarks/allocs.rb +1 -1
  9. data/benchmarks/app.rb +1 -1
  10. data/benchmarks/benchmarking_support.rb +3 -3
  11. data/benchmarks/bm_ams_0_10.rb +2 -5
  12. data/benchmarks/bm_object_writer.rb +1 -0
  13. data/benchmarks/bm_panko_json.rb +1 -1
  14. data/benchmarks/bm_panko_object.rb +1 -2
  15. data/benchmarks/bm_plain_object.rb +7 -7
  16. data/benchmarks/bm_serialization_descriptor.rb +5 -5
  17. data/benchmarks/bm_serializer_resolver.rb +4 -3
  18. data/benchmarks/bm_to_object.rb +2 -10
  19. data/benchmarks/profile.rb +5 -7
  20. data/benchmarks/sanity.rb +2 -10
  21. data/benchmarks/setup.rb +2 -2
  22. data/benchmarks/type_casts/bm_active_record.rb +6 -8
  23. data/benchmarks/type_casts/bm_panko.rb +11 -11
  24. data/benchmarks/type_casts/support.rb +8 -3
  25. data/docs/docs/introduction.md +1 -1
  26. data/docs/docs/performance.md +6 -6
  27. data/docs/package-lock.json +399 -330
  28. data/ext/panko_serializer/attributes_writer/active_record.c +6 -6
  29. data/ext/panko_serializer/attributes_writer/active_record.h +1 -2
  30. data/ext/panko_serializer/attributes_writer/attributes_writer.c +4 -6
  31. data/ext/panko_serializer/attributes_writer/attributes_writer.h +7 -2
  32. data/ext/panko_serializer/attributes_writer/common.h +2 -1
  33. data/ext/panko_serializer/attributes_writer/hash.c +3 -2
  34. data/ext/panko_serializer/attributes_writer/hash.h +2 -4
  35. data/ext/panko_serializer/attributes_writer/plain.c +2 -1
  36. data/ext/panko_serializer/attributes_writer/plain.h +2 -4
  37. data/ext/panko_serializer/attributes_writer/type_cast/type_cast.c +10 -10
  38. data/ext/panko_serializer/attributes_writer/type_cast/type_cast.h +4 -4
  39. data/ext/panko_serializer/common.h +0 -2
  40. data/ext/panko_serializer/panko_serializer.c +8 -9
  41. data/ext/panko_serializer/serialization_descriptor/association.c +3 -1
  42. data/ext/panko_serializer/serialization_descriptor/association.h +1 -1
  43. data/ext/panko_serializer/serialization_descriptor/attribute.c +3 -1
  44. data/ext/panko_serializer/serialization_descriptor/attribute.h +2 -2
  45. data/ext/panko_serializer/serialization_descriptor/serialization_descriptor.h +1 -1
  46. data/lib/panko/attribute.rb +5 -5
  47. data/lib/panko/object_writer.rb +5 -1
  48. data/lib/panko/response.rb +3 -3
  49. data/lib/panko/serialization_descriptor.rb +2 -2
  50. data/lib/panko/serializer.rb +3 -3
  51. data/lib/panko/serializer_resolver.rb +6 -4
  52. data/lib/panko/version.rb +1 -1
  53. data/panko_serializer.gemspec +8 -8
  54. metadata +5 -3
@@ -56,7 +56,7 @@ struct attributes init_context(VALUE obj) {
56
56
  if (RB_TYPE_P(attributes_container, T_HASH)) {
57
57
  attributes_ctx.attributes_hash = attributes_container;
58
58
  } else {
59
- if(is_lazy_attributes_set_defined == false) {
59
+ if (is_lazy_attributes_set_defined == false) {
60
60
  volatile VALUE delegate_hash =
61
61
  rb_ivar_get(attributes_container, delegate_hash_id);
62
62
 
@@ -84,13 +84,13 @@ struct attributes init_context(VALUE obj) {
84
84
  return attributes_ctx;
85
85
  }
86
86
 
87
- VALUE read_attribute(struct attributes attributes_ctx, Attribute attribute, VALUE* isJson) {
87
+ VALUE read_attribute(struct attributes attributes_ctx, Attribute attribute,
88
+ volatile VALUE* isJson) {
88
89
  volatile VALUE member, value;
89
90
 
90
91
  member = attribute->name_str;
91
92
  value = Qnil;
92
93
 
93
-
94
94
  if (!NIL_P(attributes_ctx.attributes_hash)) {
95
95
  volatile VALUE attribute_metadata =
96
96
  rb_hash_aref(attributes_ctx.attributes_hash, member);
@@ -108,7 +108,6 @@ VALUE read_attribute(struct attributes attributes_ctx, Attribute attribute, VALU
108
108
  value = rb_hash_aref(attributes_ctx.values, member);
109
109
  }
110
110
 
111
-
112
111
  if (NIL_P(attribute->type) && !NIL_P(value)) {
113
112
  if (attributes_ctx.tryToReadFromAdditionalTypes == true) {
114
113
  attribute->type = rb_hash_aref(attributes_ctx.additional_types, member);
@@ -137,13 +136,14 @@ VALUE detect_active_model_changes(VALUE v) {
137
136
  rb_const_get_at(rb_cObject, rb_intern("ActiveModel"));
138
137
 
139
138
  is_lazy_attributes_set_defined =
140
- rb_const_defined(active_model_type, rb_intern("LazyAttributeSet")) > 0;
139
+ rb_const_defined(active_model_type, rb_intern("LazyAttributeSet")) > 0;
141
140
 
142
141
  return Qundef;
143
142
  }
144
143
 
145
144
  void active_record_attributes_writer(VALUE obj, VALUE attributes,
146
- EachAttributeFunc write_value, VALUE writer) {
145
+ EachAttributeFunc write_value,
146
+ VALUE writer) {
147
147
  if (type_detection_ran == false) {
148
148
  // If ActiveModel can't be found it will throw error
149
149
  int isErrored;
@@ -8,8 +8,7 @@
8
8
  #include "serialization_descriptor/attribute.h"
9
9
  #include "type_cast/type_cast.h"
10
10
 
11
- extern void active_record_attributes_writer(VALUE object,
12
- VALUE attributes,
11
+ extern void active_record_attributes_writer(VALUE object, VALUE attributes,
13
12
  EachAttributeFunc func,
14
13
  VALUE writer);
15
14
 
@@ -24,18 +24,16 @@ AttributesWriter create_attributes_writer(VALUE object) {
24
24
  int isErrored;
25
25
  rb_protect(init_types, Qnil, &isErrored);
26
26
 
27
-
28
27
  if (ar_base_type != Qundef &&
29
28
  rb_obj_is_kind_of(object, ar_base_type) == Qtrue) {
30
-
31
- return (AttributesWriter){
32
- .object_type = ActiveRecord,
33
- .write_attributes = active_record_attributes_writer};
29
+ return (AttributesWriter){
30
+ .object_type = ActiveRecord,
31
+ .write_attributes = active_record_attributes_writer};
34
32
  }
35
33
 
36
34
  if (!RB_SPECIAL_CONST_P(object) && BUILTIN_TYPE(object) == T_HASH) {
37
35
  return (AttributesWriter){.object_type = Hash,
38
- .write_attributes = hash_attributes_writer};
36
+ .write_attributes = hash_attributes_writer};
39
37
  }
40
38
 
41
39
  return (AttributesWriter){.object_type = Plain,
@@ -4,10 +4,15 @@
4
4
 
5
5
  #include "active_record.h"
6
6
  #include "common.h"
7
- #include "plain.h"
8
7
  #include "hash.h"
8
+ #include "plain.h"
9
9
 
10
- enum ObjectType { UnknownObjectType = 0, ActiveRecord = 1, Plain = 2, Hash = 3 };
10
+ enum ObjectType {
11
+ UnknownObjectType = 0,
12
+ ActiveRecord = 1,
13
+ Plain = 2,
14
+ Hash = 3
15
+ };
11
16
 
12
17
  typedef struct _AttributesWriter {
13
18
  enum ObjectType object_type;
@@ -3,6 +3,7 @@
3
3
  #include "../serialization_descriptor/attribute.h"
4
4
  #include "ruby.h"
5
5
 
6
- typedef void (*EachAttributeFunc)(VALUE writer, VALUE name, VALUE value, VALUE isJson);
6
+ typedef void (*EachAttributeFunc)(VALUE writer, VALUE name, VALUE value,
7
+ VALUE isJson);
7
8
 
8
9
  VALUE attr_name_for_serialization(Attribute attribute);
@@ -1,12 +1,13 @@
1
1
  #include "hash.h"
2
2
 
3
3
  void hash_attributes_writer(VALUE obj, VALUE attributes,
4
- EachAttributeFunc write_value, VALUE writer) {
4
+ EachAttributeFunc write_value, VALUE writer) {
5
5
  long i;
6
6
  for (i = 0; i < RARRAY_LEN(attributes); i++) {
7
7
  volatile VALUE raw_attribute = RARRAY_AREF(attributes, i);
8
8
  Attribute attribute = attribute_read(raw_attribute);
9
9
 
10
- write_value(writer, attr_name_for_serialization(attribute), rb_hash_aref(obj, attribute->name_str), Qfalse);
10
+ write_value(writer, attr_name_for_serialization(attribute),
11
+ rb_hash_aref(obj, attribute->name_str), Qfalse);
11
12
  }
12
13
  }
@@ -3,7 +3,5 @@
3
3
  #include "common.h"
4
4
  #include "ruby.h"
5
5
 
6
- void hash_attributes_writer(VALUE obj,
7
- VALUE attributes,
8
- EachAttributeFunc func,
9
- VALUE writer);
6
+ void hash_attributes_writer(VALUE obj, VALUE attributes, EachAttributeFunc func,
7
+ VALUE writer);
@@ -7,6 +7,7 @@ void plain_attributes_writer(VALUE obj, VALUE attributes,
7
7
  volatile VALUE raw_attribute = RARRAY_AREF(attributes, i);
8
8
  Attribute attribute = attribute_read(raw_attribute);
9
9
 
10
- write_value(writer, attr_name_for_serialization(attribute), rb_funcall(obj, attribute->name_id, 0), Qfalse);
10
+ write_value(writer, attr_name_for_serialization(attribute),
11
+ rb_funcall(obj, attribute->name_id, 0), Qfalse);
11
12
  }
12
13
  }
@@ -3,7 +3,5 @@
3
3
  #include "common.h"
4
4
  #include "ruby.h"
5
5
 
6
- void plain_attributes_writer(VALUE obj,
7
- VALUE attributes,
8
- EachAttributeFunc func,
9
- VALUE writer);
6
+ void plain_attributes_writer(VALUE obj, VALUE attributes,
7
+ EachAttributeFunc func, VALUE writer);
@@ -1,4 +1,5 @@
1
1
  #include "type_cast.h"
2
+
2
3
  #include "time_conversion.h"
3
4
 
4
5
  ID deserialize_from_db_id = 0;
@@ -212,7 +213,6 @@ bool is_json_type(VALUE type_klass) {
212
213
  (ar_json_type != Qundef && type_klass == ar_json_type));
213
214
  }
214
215
 
215
-
216
216
  bool is_boolean_type(VALUE type_klass) { return type_klass == ar_boolean_type; }
217
217
 
218
218
  VALUE cast_boolean_type(VALUE value) {
@@ -276,26 +276,27 @@ VALUE cast_date_time_type(VALUE value) {
276
276
 
277
277
  VALUE rescue_func() { return Qfalse; }
278
278
 
279
- VALUE parse_json(VALUE value) { return rb_funcall(oj_type, oj_sc_parse_id, 2, rb_cObject, value); }
279
+ VALUE parse_json(VALUE value) {
280
+ return rb_funcall(oj_type, oj_sc_parse_id, 2, rb_cObject, value);
281
+ }
280
282
 
281
283
  VALUE is_json_value(VALUE value) {
282
284
  if (!RB_TYPE_P(value, T_STRING)) {
283
285
  return value;
284
286
  }
285
287
 
286
-
287
- if(RSTRING_LEN(value) == 0) {
288
+ if (RSTRING_LEN(value) == 0) {
288
289
  return Qfalse;
289
290
  }
290
291
 
291
292
  volatile VALUE result =
292
293
  rb_rescue2(parse_json, value, rescue_func, Qundef, oj_parseerror_type, 0);
293
294
 
294
- if(NIL_P(result)) {
295
+ if (NIL_P(result)) {
295
296
  return Qtrue;
296
297
  }
297
298
 
298
- if(result == Qfalse) {
299
+ if (result == Qfalse) {
299
300
  return Qfalse;
300
301
  }
301
302
 
@@ -303,7 +304,7 @@ VALUE is_json_value(VALUE value) {
303
304
  return Qfalse;
304
305
  }
305
306
 
306
- VALUE type_cast(VALUE type_metadata, VALUE value, VALUE* isJson) {
307
+ VALUE type_cast(VALUE type_metadata, VALUE value, volatile VALUE* isJson) {
307
308
  if (value == Qnil || value == Qundef) {
308
309
  return value;
309
310
  }
@@ -323,8 +324,8 @@ VALUE type_cast(VALUE type_metadata, VALUE value, VALUE* isJson) {
323
324
  }
324
325
  }
325
326
 
326
- if(is_json_type(type_klass)) {
327
- if(is_json_value(value) == Qfalse) {
327
+ if (is_json_type(type_klass)) {
328
+ if (is_json_value(value) == Qfalse) {
328
329
  return Qnil;
329
330
  }
330
331
  *isJson = Qtrue;
@@ -357,7 +358,6 @@ void panko_init_type_cast(VALUE mPanko) {
357
358
  oj_parseerror_type = rb_const_get_at(oj_type, rb_intern("ParseError"));
358
359
  oj_sc_parse_id = rb_intern("sc_parse");
359
360
 
360
-
361
361
  // TODO: pass 3 arguments here
362
362
  rb_define_singleton_method(mPanko, "_type_cast", public_type_cast, -1);
363
363
 
@@ -33,7 +33,7 @@ typedef VALUE (*TypeCastFunc)(VALUE value);
33
33
  typedef struct _TypeCast {
34
34
  TypeMatchFunc canCast;
35
35
  TypeCastFunc typeCast;
36
- } * TypeCast;
36
+ }* TypeCast;
37
37
 
38
38
  // ActiveRecord::Type::String
39
39
  // ActiveRecord::Type::Text
@@ -71,11 +71,11 @@ static struct _TypeCast type_casts[] = {
71
71
 
72
72
  {NULL, NULL}};
73
73
 
74
- extern VALUE type_cast(VALUE type_metadata, VALUE value, VALUE* isJson);
74
+ extern VALUE type_cast(VALUE type_metadata, VALUE value,
75
+ volatile VALUE* isJson);
75
76
  void panko_init_type_cast(VALUE mPanko);
76
77
 
77
78
  // Introduced in ruby 2.4
78
79
  #ifndef RB_INTEGER_TYPE_P
79
- # define RB_INTEGER_TYPE_P(obj) (RB_FIXNUM_P(obj) || RB_TYPE_P(obj, T_BIGNUM))
80
+ #define RB_INTEGER_TYPE_P(obj) (RB_FIXNUM_P(obj) || RB_TYPE_P(obj, T_BIGNUM))
80
81
  #endif
81
-
@@ -2,10 +2,8 @@
2
2
 
3
3
  #include <ruby.h>
4
4
 
5
-
6
5
  #define PANKO_SAFE_HASH_SIZE(hash) \
7
6
  (hash == Qnil || hash == Qundef) ? 0 : RHASH_SIZE(hash)
8
7
 
9
8
  #define PANKO_EMPTY_HASH(hash) \
10
9
  (hash == Qnil || hash == Qundef) ? 1 : (RHASH_SIZE(hash) == 0)
11
-
@@ -1,7 +1,7 @@
1
- #include <ruby.h>
2
-
3
1
  #include "panko_serializer.h"
4
2
 
3
+ #include <ruby.h>
4
+
5
5
  static ID push_value_id;
6
6
  static ID push_array_id;
7
7
  static ID push_object_id;
@@ -16,7 +16,7 @@ static ID serialization_context_id;
16
16
  static VALUE SKIP = Qundef;
17
17
 
18
18
  void write_value(VALUE str_writer, VALUE key, VALUE value, VALUE isJson) {
19
- if(isJson == Qtrue) {
19
+ if (isJson == Qtrue) {
20
20
  rb_funcall(str_writer, push_json_id, 2, value, key);
21
21
  } else {
22
22
  rb_funcall(str_writer, push_value_id, 2, value, key);
@@ -29,7 +29,7 @@ void serialize_method_fields(VALUE object, VALUE str_writer,
29
29
  return;
30
30
  }
31
31
 
32
- volatile VALUE method_fields, serializer;
32
+ volatile VALUE method_fields, serializer, key;
33
33
  long i;
34
34
 
35
35
  method_fields = descriptor->method_fields;
@@ -43,7 +43,8 @@ void serialize_method_fields(VALUE object, VALUE str_writer,
43
43
 
44
44
  volatile VALUE result = rb_funcall(serializer, attribute->name_id, 0);
45
45
  if (result != SKIP) {
46
- write_value(str_writer, attribute->name_str, result, Qfalse);
46
+ key = attr_name_for_serialization(attribute);
47
+ write_value(str_writer, key, result, Qfalse);
47
48
  }
48
49
  }
49
50
 
@@ -52,10 +53,8 @@ void serialize_method_fields(VALUE object, VALUE str_writer,
52
53
 
53
54
  void serialize_fields(VALUE object, VALUE str_writer,
54
55
  SerializationDescriptor descriptor) {
55
- descriptor->attributes_writer.write_attributes(object,
56
- descriptor->attributes,
57
- write_value,
58
- str_writer);
56
+ descriptor->attributes_writer.write_attributes(object, descriptor->attributes,
57
+ write_value, str_writer);
59
58
 
60
59
  serialize_method_fields(object, str_writer, descriptor);
61
60
  }
@@ -31,11 +31,12 @@ void association_mark(Association data) {
31
31
  }
32
32
 
33
33
  static VALUE association_new(int argc, VALUE* argv, VALUE self) {
34
- Association association = ALLOC(struct _Association);
34
+ Association association;
35
35
 
36
36
  Check_Type(argv[0], T_SYMBOL);
37
37
  Check_Type(argv[1], T_STRING);
38
38
 
39
+ association = ALLOC(struct _Association);
39
40
  association->name_sym = argv[0];
40
41
  association->name_str = argv[1];
41
42
  association->rb_descriptor = argv[2];
@@ -77,6 +78,7 @@ VALUE association_decriptor_aset(VALUE self, VALUE descriptor) {
77
78
 
78
79
  void panko_init_association(VALUE mPanko) {
79
80
  cAssociation = rb_define_class_under(mPanko, "Association", rb_cObject);
81
+ rb_undef_alloc_func(cAssociation);
80
82
  rb_global_variable(&cAssociation);
81
83
 
82
84
  rb_define_module_function(cAssociation, "new", association_new, -1);
@@ -12,7 +12,7 @@ typedef struct _Association {
12
12
 
13
13
  VALUE rb_descriptor;
14
14
  SerializationDescriptor descriptor;
15
- } * Association;
15
+ }* Association;
16
16
 
17
17
  Association association_read(VALUE association);
18
18
  void panko_init_association(VALUE mPanko);
@@ -26,13 +26,14 @@ void attribute_mark(Attribute data) {
26
26
  }
27
27
 
28
28
  static VALUE attribute_new(int argc, VALUE* argv, VALUE self) {
29
- Attribute attribute = ALLOC(struct _Attribute);
29
+ Attribute attribute;
30
30
 
31
31
  Check_Type(argv[0], T_STRING);
32
32
  if (argv[1] != Qnil) {
33
33
  Check_Type(argv[1], T_STRING);
34
34
  }
35
35
 
36
+ attribute = ALLOC(struct _Attribute);
36
37
  attribute->name_str = argv[0];
37
38
  attribute->name_id = rb_intern_str(attribute->name_str);
38
39
  attribute->alias_name = argv[1];
@@ -85,6 +86,7 @@ void panko_init_attribute(VALUE mPanko) {
85
86
  attribute_aliases_id = rb_intern("attribute_aliases");
86
87
 
87
88
  cAttribute = rb_define_class_under(mPanko, "Attribute", rb_cObject);
89
+ rb_undef_alloc_func(cAttribute);
88
90
  rb_global_variable(&cAttribute);
89
91
 
90
92
  rb_define_module_function(cAttribute, "new", attribute_new, -1);
@@ -16,12 +16,12 @@ typedef struct _Attribute {
16
16
  */
17
17
  VALUE type;
18
18
  VALUE record_class;
19
- } * Attribute;
19
+ }* Attribute;
20
20
 
21
21
  Attribute attribute_read(VALUE attribute);
22
22
  void attribute_try_invalidate(Attribute attribute, VALUE new_record_class);
23
23
  void panko_init_attribute(VALUE mPanko);
24
24
 
25
- #define PANKO_ATTRIBUTE_READ(attribute) (Attribute)DATA_PTR(attribute)
25
+ #define PANKO_ATTRIBUTE_READ(attribute) (Attribute) DATA_PTR(attribute)
26
26
 
27
27
  #endif
@@ -19,7 +19,7 @@ typedef struct _SerializationDescriptor {
19
19
  VALUE has_many_associations;
20
20
 
21
21
  AttributesWriter attributes_writer;
22
- } * SerializationDescriptor;
22
+ }* SerializationDescriptor;
23
23
 
24
24
  SerializationDescriptor sd_read(VALUE descriptor);
25
25
 
@@ -7,9 +7,9 @@ module Panko
7
7
  Attribute.new(name.to_s, alias_name)
8
8
  end
9
9
 
10
- def ==(attr)
11
- return name.to_sym == attr if attr.is_a? Symbol
12
- return name == attr.name && alias_name == attr.alias_name if attr.is_a? Panko::Attribute
10
+ def ==(other)
11
+ return name.to_sym == other if other.is_a? Symbol
12
+ return name == other.name && alias_name == other.alias_name if other.is_a? Panko::Attribute
13
13
 
14
14
  super
15
15
  end
@@ -18,8 +18,8 @@ module Panko
18
18
  name.to_sym.hash
19
19
  end
20
20
 
21
- def eql?(attr)
22
- self.==(attr)
21
+ def eql?(other)
22
+ self.==(other)
23
23
  end
24
24
 
25
25
  def inspect
@@ -35,7 +35,11 @@ class Panko::ObjectWriter
35
35
 
36
36
  def push_json(value, key = nil)
37
37
  if value.is_a?(String)
38
- value = Oj.load(value) rescue nil
38
+ value = begin
39
+ Oj.load(value)
40
+ rescue
41
+ nil
42
+ end
39
43
  end
40
44
 
41
45
  push_value(value, key)
@@ -75,9 +75,9 @@ module Panko
75
75
 
76
76
  def write_value(writer, value, key = nil)
77
77
  if value.is_a?(Panko::ArraySerializer) ||
78
- value.is_a?(Panko::Serializer) ||
79
- value.is_a?(Panko::Response) ||
80
- value.is_a?(Panko::JsonValue)
78
+ value.is_a?(Panko::Serializer) ||
79
+ value.is_a?(Panko::Response) ||
80
+ value.is_a?(Panko::JsonValue)
81
81
  writer.push_json(value.to_json, key)
82
82
  else
83
83
  writer.push_value(value, key)
@@ -74,7 +74,7 @@ module Panko
74
74
  unless has_many_associations.empty?
75
75
  self.has_many_associations = apply_association_filters(
76
76
  has_many_associations,
77
- { attributes: attributes_only_filters, associations: associations_only_filters },
77
+ {attributes: attributes_only_filters, associations: associations_only_filters},
78
78
  attributes: attributes_except_filters, associations: associations_except_filters
79
79
  )
80
80
  end
@@ -82,7 +82,7 @@ module Panko
82
82
  unless has_one_associations.empty?
83
83
  self.has_one_associations = apply_association_filters(
84
84
  has_one_associations,
85
- { attributes: attributes_only_filters, associations: associations_only_filters },
85
+ {attributes: attributes_only_filters, associations: associations_only_filters},
86
86
  attributes: attributes_except_filters, associations: associations_except_filters
87
87
  )
88
88
  end
@@ -70,12 +70,12 @@ module Panko
70
70
  return if @_descriptor.nil?
71
71
 
72
72
  deleted_attr = @_descriptor.attributes.delete(method)
73
- @_descriptor.method_fields << Attribute.create(method) unless deleted_attr.nil?
73
+ @_descriptor.method_fields << Attribute.create(deleted_attr.name, alias_name: deleted_attr.alias_name) unless deleted_attr.nil?
74
74
  end
75
75
 
76
76
  def has_one(name, options = {})
77
77
  serializer_const = options[:serializer]
78
- if serializer_const.kind_of?(String)
78
+ if serializer_const.is_a?(String)
79
79
  serializer_const = Panko::SerializerResolver.resolve(serializer_const, self)
80
80
  end
81
81
  serializer_const ||= Panko::SerializerResolver.resolve(name.to_s, self)
@@ -91,7 +91,7 @@ module Panko
91
91
 
92
92
  def has_many(name, options = {})
93
93
  serializer_const = options[:serializer] || options[:each_serializer]
94
- if serializer_const.kind_of?(String)
94
+ if serializer_const.is_a?(String)
95
95
  serializer_const = Panko::SerializerResolver.resolve(serializer_const, self)
96
96
  end
97
97
  serializer_const ||= Panko::SerializerResolver.resolve(name.to_s, self)
@@ -1,14 +1,16 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'active_support/core_ext/string/inflections'
4
- require 'active_support/core_ext/module/introspection'
3
+ require "active_support/core_ext/string/inflections"
4
+ require "active_support/core_ext/module/introspection"
5
5
 
6
6
  class Panko::SerializerResolver
7
7
  class << self
8
8
  def resolve(name, from)
9
9
  serializer_const = nil
10
10
 
11
- if namespace = namespace_for(from)
11
+ namespace = namespace_for(from)
12
+
13
+ if namespace.present?
12
14
  serializer_const = safe_serializer_get("#{namespace}::#{name.singularize.camelize}Serializer")
13
15
  end
14
16
 
@@ -31,7 +33,7 @@ class Panko::SerializerResolver
31
33
 
32
34
  def safe_serializer_get(name)
33
35
  const = Object.const_get(name)
34
- const < Panko::Serializer ? const : nil
36
+ (const < Panko::Serializer) ? const : nil
35
37
  rescue NameError
36
38
  nil
37
39
  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.7.7"
4
+ VERSION = "0.8.0"
5
5
  end
@@ -5,14 +5,14 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
5
  require "panko/version"
6
6
 
7
7
  Gem::Specification.new do |spec|
8
- spec.name = "panko_serializer"
9
- spec.version = Panko::VERSION
10
- spec.authors = ["Yosi Attias"]
11
- spec.email = ["yosy101@gmail.com"]
8
+ spec.name = "panko_serializer"
9
+ spec.version = Panko::VERSION
10
+ spec.authors = ["Yosi Attias"]
11
+ spec.email = ["yosy101@gmail.com"]
12
12
 
13
- spec.summary = "High Performance JSON Serialization for ActiveRecord & Ruby Objects"
14
- spec.homepage = "https://panko.dev"
15
- spec.license = "MIT"
13
+ spec.summary = "High Performance JSON Serialization for ActiveRecord & Ruby Objects"
14
+ spec.homepage = "https://panko.dev"
15
+ spec.license = "MIT"
16
16
 
17
17
  spec.metadata = {
18
18
  "bug_tracker_uri" => "https://github.com/panko-serializer/panko_serializer/issues",
@@ -30,6 +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", '> 3.11.0', '< 4.0.0'
33
+ spec.add_dependency "oj", "> 3.11.0", "< 4.0.0"
34
34
  spec.add_dependency "activesupport"
35
35
  end
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.7.7
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yosi Attias
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-06-04 00:00:00.000000000 Z
11
+ date: 2023-06-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: oj
@@ -54,10 +54,12 @@ extra_rdoc_files: []
54
54
  files:
55
55
  - ".clang-format"
56
56
  - ".github/workflows/docs.yml"
57
+ - ".github/workflows/lint.yml"
57
58
  - ".github/workflows/ruby.yml"
58
59
  - ".gitignore"
59
60
  - ".rspec"
60
61
  - ".rubocop.yml"
62
+ - ".standard.yml"
61
63
  - Gemfile
62
64
  - LICENSE.txt
63
65
  - README.md
@@ -167,7 +169,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
167
169
  - !ruby/object:Gem::Version
168
170
  version: '0'
169
171
  requirements: []
170
- rubygems_version: 3.1.4
172
+ rubygems_version: 3.4.6
171
173
  signing_key:
172
174
  specification_version: 4
173
175
  summary: High Performance JSON Serialization for ActiveRecord & Ruby Objects