panko_serializer 0.7.4 → 0.7.5

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1cbaf86b0b95041f6f3387c8d82cc8ef1fa272549e50b5d3fdac2d13989f1a29
4
- data.tar.gz: 41496c877bee39fa9fe7f136469ea260c1c60feeb25c6f95930b8c13a9055b3c
3
+ metadata.gz: e0377ad83b60ba60530ba87694837b265bfe3890806afeac84544c336351ff06
4
+ data.tar.gz: adbb80b08811b8b240e4af98214834e8876a11a267db58c8dad9accb90e3bee6
5
5
  SHA512:
6
- metadata.gz: 2c30cbbde27a0ff4cead7b0763c1a76d0d179053e7d913ac81594eedb50defee858792d0893e19a42bd5b5ea71e6c5e4ed2cc3371a2d48d1dce4d53737a4d584
7
- data.tar.gz: 0dd1443b07977c1eea6457016f4db43d88fcf857ea607bf9064b72485e4f7d78e0ffcf39fe1f9b83456c0477da3988ee6a392730bfe84565d266816484e01589
6
+ metadata.gz: e55156ac125c66c98f9099ddf2d37427e3dc81048bd0d94d97b98055ff2df0272ba65196b41d0410bcea271879593d6ad37c7ea39d6ecea48629438af75e55d1
7
+ data.tar.gz: a2a71b526addc0593bd6f33edf07cda15dfd46fe11f00342fe5b8bfbc13e0648c78da598d010e741c9fc03cd4543bcafea6d0c3a3fc8c35cd68a2188848860be
@@ -26,7 +26,7 @@ jobs:
26
26
  run: npm install
27
27
 
28
28
  - name: Install SSH Client 🔑
29
- uses: webfactory/ssh-agent@v0.2.0
29
+ uses: webfactory/ssh-agent@v0.4.1
30
30
  with:
31
31
  ssh-private-key: ${{ secrets.DEPLOY_KEY }}
32
32
 
@@ -9,8 +9,11 @@ jobs:
9
9
  strategy:
10
10
  fail-fast: false
11
11
  matrix:
12
- ruby: [ '2.5', '2.6', '2.7']
13
- rails: ['5.2.0', '6.0.0', '6.1.0rc1']
12
+ ruby: [ '2.5', '2.6', '2.7', '3.0']
13
+ rails: ['5.2.0', '6.0.0', '6.1.0']
14
+ exclude:
15
+ - ruby: '3.0'
16
+ rails: '5.2.0'
14
17
 
15
18
  steps:
16
19
  - uses: actions/checkout@v2
@@ -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 (rb_obj_is_kind_of(object, hash_type) == Qtrue) {
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
  }
@@ -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
- write_value(str_writer, attribute->name_str, result, Qfalse);
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
 
@@ -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
- def self.resolve(name)
5
- serializer_name = "#{name.singularize.camelize}Serializer"
6
- serializer_const = safe_const_get(serializer_name)
7
+ class << self
8
+ def resolve(name, from)
9
+ serializer_const = nil
7
10
 
8
- return nil if serializer_const.nil?
9
- return nil unless is_serializer(serializer_const)
11
+ if namespace = namespace_for(from)
12
+ serializer_const = safe_serializer_get("#{namespace}::#{name.singularize.camelize}Serializer")
13
+ end
10
14
 
11
- serializer_const
12
- end
15
+ serializer_const ||= safe_serializer_get("#{name.singularize.camelize}Serializer")
16
+ serializer_const
17
+ end
13
18
 
14
- private
19
+ private
15
20
 
16
- def self.is_serializer(const)
17
- const < Panko::Serializer
18
- end
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
- def self.safe_const_get(name)
21
- Object.const_get(name)
22
- rescue NameError
23
- nil
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Panko
4
- VERSION = "0.7.4"
4
+ VERSION = "0.7.5"
5
5
  end
@@ -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", "~> 3.10.0"
33
+ spec.add_dependency "oj", "~> 3.11.0"
34
+ spec.add_dependency "activesupport"
34
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.4
4
+ version: 0.7.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yosi Attias
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-11-21 00:00:00.000000000 Z
11
+ date: 2021-02-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: oj
@@ -16,14 +16,28 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 3.10.0
19
+ version: 3.11.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 3.10.0
26
+ version: 3.11.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: activesupport
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
27
41
  description:
28
42
  email:
29
43
  - yosy101@gmail.com