panko_serializer 0.8.4 → 1.0.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.
- checksums.yaml +4 -4
- data/README.md +8 -6
- data/lib/panko/array_serializer.rb +55 -16
- data/lib/panko/code_gen/active_record/access_classifier.rb +65 -0
- data/lib/panko/code_gen/active_record/define_attribute_methods.rb +13 -0
- data/lib/panko/code_gen/code_builder.rb +32 -0
- data/lib/panko/code_gen/compile_cache.rb +28 -0
- data/lib/panko/code_gen/compiler.rb +56 -0
- data/lib/panko/code_gen/config.rb +79 -0
- data/lib/panko/code_gen/datetime_format.rb +38 -0
- data/lib/panko/code_gen/descriptor.rb +136 -0
- data/lib/panko/code_gen/descriptor_builder.rb +166 -0
- data/lib/panko/code_gen/dump.rb +52 -0
- data/lib/panko/code_gen/errors.rb +21 -0
- data/lib/panko/code_gen/filter.rb +29 -0
- data/lib/panko/code_gen/filter_adapter.rb +44 -0
- data/lib/panko/code_gen/filters/indexed.rb +62 -0
- data/lib/panko/code_gen/filters/none.rb +19 -0
- data/lib/panko/code_gen/generator.rb +23 -0
- data/lib/panko/code_gen/generators/banner.rb +27 -0
- data/lib/panko/code_gen/generators/class_emitter.rb +120 -0
- data/lib/panko/code_gen/generators/cycle_membership.rb +53 -0
- data/lib/panko/code_gen/generators/descriptor_walk.rb +22 -0
- data/lib/panko/code_gen/generators/fanout.rb +60 -0
- data/lib/panko/code_gen/generators/field_index.rb +31 -0
- data/lib/panko/code_gen/generators/field_walk.rb +38 -0
- data/lib/panko/code_gen/generators/generated_names.rb +73 -0
- data/lib/panko/code_gen/generators/hash_sink.rb +217 -0
- data/lib/panko/code_gen/generators/json_sink.rb +290 -0
- data/lib/panko/code_gen/generators/record_access/generic.rb +92 -0
- data/lib/panko/code_gen/generators/record_access/specialized.rb +90 -0
- data/lib/panko/code_gen/generators/release.rb +60 -0
- data/lib/panko/code_gen/generators/sink.rb +80 -0
- data/lib/panko/code_gen/instance_pool.rb +27 -0
- data/lib/panko/code_gen/runtime.rb +27 -0
- data/lib/panko/code_gen/serializer_cache.rb +242 -0
- data/lib/panko/code_gen/validators/callable_arity.rb +42 -0
- data/lib/panko/code_gen/validators/name_uniqueness.rb +44 -0
- data/lib/panko/code_gen/validators/source_resolution.rb +48 -0
- data/lib/panko/code_gen/validators/validator.rb +19 -0
- data/lib/panko/code_gen/writers_pool.rb +51 -0
- data/lib/panko/code_gen.rb +82 -0
- data/lib/panko/compile_all.rb +80 -0
- data/lib/panko/compile_all_result.rb +21 -0
- data/lib/panko/config.rb +71 -0
- data/lib/panko/descriptor.rb +93 -0
- data/lib/panko/response.rb +40 -8
- data/lib/panko/serializer.rb +175 -91
- data/lib/panko/serializer_resolver.rb +2 -8
- data/lib/panko/version.rb +1 -1
- data/lib/panko_serializer.rb +3 -5
- metadata +49 -99
- data/.clang-format +0 -3
- data/.github/dependabot.yml +0 -6
- data/.github/workflows/database_matrix.yml +0 -85
- data/.github/workflows/docs.yml +0 -39
- data/.github/workflows/lint.yml +0 -30
- data/.github/workflows/tests.yml +0 -34
- data/.gitignore +0 -20
- data/.rspec +0 -2
- data/.rubocop.yml +0 -37
- data/Appraisals +0 -28
- data/Gemfile +0 -37
- data/Rakefile +0 -93
- data/benchmarks/BENCHMARKS.md +0 -48
- data/benchmarks/allocs.rb +0 -23
- data/benchmarks/app.rb +0 -11
- data/benchmarks/benchmarking_support.rb +0 -44
- data/benchmarks/bm_ams_0_10.rb +0 -43
- data/benchmarks/bm_object_writer.rb +0 -65
- data/benchmarks/bm_panko_json.rb +0 -60
- data/benchmarks/bm_panko_object.rb +0 -46
- data/benchmarks/bm_plain_object.rb +0 -99
- data/benchmarks/bm_serialization_descriptor.rb +0 -76
- data/benchmarks/bm_serializer_resolver.rb +0 -22
- data/benchmarks/bm_to_object.rb +0 -81
- data/benchmarks/profile.rb +0 -86
- data/benchmarks/sanity.rb +0 -83
- data/benchmarks/setup.rb +0 -56
- data/benchmarks/type_casts/bm_active_record.rb +0 -58
- data/benchmarks/type_casts/bm_panko.rb +0 -65
- data/benchmarks/type_casts/support.rb +0 -27
- data/docs/docs/associations.md +0 -107
- data/docs/docs/attributes.md +0 -150
- data/docs/docs/design-choices.md +0 -127
- data/docs/docs/getting-started.md +0 -70
- data/docs/docs/introduction.md +0 -13
- data/docs/docs/performance.md +0 -32
- data/docs/docs/response-bag.md +0 -83
- data/docs/docusaurus.config.js +0 -86
- data/docs/package-lock.json +0 -17872
- data/docs/package.json +0 -18
- data/docs/sidebars.json +0 -15
- data/docs/src/css/customTheme.css +0 -9
- data/docs/static/.DS_Store +0 -0
- data/docs/static/CNAME +0 -1
- data/docs/static/css/custom.css +0 -51
- data/docs/static/img/favicon.ico +0 -0
- data/docs/static/img/oss_logo.png +0 -0
- data/docs/static/img/undraw_code_review.svg +0 -1
- data/docs/static/img/undraw_monitor.svg +0 -1
- data/docs/static/img/undraw_note_list.svg +0 -1
- data/docs/static/img/undraw_online.svg +0 -1
- data/docs/static/img/undraw_open_source.svg +0 -1
- data/docs/static/img/undraw_operating_system.svg +0 -1
- data/docs/static/img/undraw_react.svg +0 -1
- data/docs/static/img/undraw_tweetstorm.svg +0 -1
- data/docs/static/img/undraw_youtube_tutorial.svg +0 -1
- data/docs/static/index.html +0 -14
- data/ext/panko_serializer/attributes_writer/active_record.c +0 -181
- data/ext/panko_serializer/attributes_writer/active_record.h +0 -17
- data/ext/panko_serializer/attributes_writer/attributes_writer.c +0 -55
- data/ext/panko_serializer/attributes_writer/attributes_writer.h +0 -35
- data/ext/panko_serializer/attributes_writer/common.c +0 -10
- data/ext/panko_serializer/attributes_writer/common.h +0 -9
- data/ext/panko_serializer/attributes_writer/hash.c +0 -13
- data/ext/panko_serializer/attributes_writer/hash.h +0 -7
- data/ext/panko_serializer/attributes_writer/plain.c +0 -13
- data/ext/panko_serializer/attributes_writer/plain.h +0 -7
- data/ext/panko_serializer/attributes_writer/type_cast/time_conversion.c +0 -156
- data/ext/panko_serializer/attributes_writer/type_cast/time_conversion.h +0 -10
- data/ext/panko_serializer/attributes_writer/type_cast/type_cast.c +0 -398
- data/ext/panko_serializer/attributes_writer/type_cast/type_cast.h +0 -81
- data/ext/panko_serializer/common.h +0 -9
- data/ext/panko_serializer/extconf.rb +0 -28
- data/ext/panko_serializer/panko_serializer.c +0 -181
- data/ext/panko_serializer/panko_serializer.h +0 -12
- data/ext/panko_serializer/serialization_descriptor/association.c +0 -90
- data/ext/panko_serializer/serialization_descriptor/association.h +0 -20
- data/ext/panko_serializer/serialization_descriptor/attribute.c +0 -96
- data/ext/panko_serializer/serialization_descriptor/attribute.h +0 -27
- data/ext/panko_serializer/serialization_descriptor/serialization_descriptor.c +0 -177
- data/ext/panko_serializer/serialization_descriptor/serialization_descriptor.h +0 -30
- data/gemfiles/7.2.0.gemfile +0 -41
- data/gemfiles/7.2.0.gemfile.lock +0 -221
- data/gemfiles/8.0.0.gemfile +0 -41
- data/gemfiles/8.0.0.gemfile.lock +0 -239
- data/gemfiles/8.1.0.gemfile +0 -41
- data/gemfiles/8.1.0.gemfile.lock +0 -248
- data/lib/panko/association.rb +0 -17
- data/lib/panko/attribute.rb +0 -29
- data/lib/panko/object_writer.rb +0 -68
- data/lib/panko/serialization_descriptor.rb +0 -180
- data/panko_serializer.gemspec +0 -36
|
@@ -1,180 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module Panko
|
|
4
|
-
class SerializationDescriptor
|
|
5
|
-
#
|
|
6
|
-
# Creates new description and apply the options
|
|
7
|
-
# on the new descriptor
|
|
8
|
-
#
|
|
9
|
-
def self.build(serializer, options = {}, serialization_context = nil)
|
|
10
|
-
backend = Panko::SerializationDescriptor.duplicate(serializer._descriptor)
|
|
11
|
-
|
|
12
|
-
options.merge! serializer.filters_for(options[:context], options[:scope]) if serializer.respond_to? :filters_for
|
|
13
|
-
|
|
14
|
-
backend.apply_filters(options)
|
|
15
|
-
|
|
16
|
-
backend.set_serialization_context(serialization_context)
|
|
17
|
-
|
|
18
|
-
backend
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
#
|
|
22
|
-
# Create new descriptor with same properties
|
|
23
|
-
# useful when you want to apply filters
|
|
24
|
-
#
|
|
25
|
-
def self.duplicate(descriptor)
|
|
26
|
-
backend = Panko::SerializationDescriptor.new
|
|
27
|
-
|
|
28
|
-
backend.type = descriptor.type
|
|
29
|
-
|
|
30
|
-
backend.attributes = descriptor.attributes.dup
|
|
31
|
-
|
|
32
|
-
backend.method_fields = descriptor.method_fields.dup
|
|
33
|
-
backend.serializer = descriptor.type.new(_skip_init: true) unless backend.method_fields.empty?
|
|
34
|
-
|
|
35
|
-
backend.has_many_associations = descriptor.has_many_associations.map(&:duplicate)
|
|
36
|
-
backend.has_one_associations = descriptor.has_one_associations.map(&:duplicate)
|
|
37
|
-
|
|
38
|
-
backend
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
def set_serialization_context(context)
|
|
42
|
-
serializer.serialization_context = context if !method_fields.empty? && !serializer.nil?
|
|
43
|
-
|
|
44
|
-
has_many_associations.each do |assoc|
|
|
45
|
-
assoc.descriptor.set_serialization_context context
|
|
46
|
-
end
|
|
47
|
-
|
|
48
|
-
has_one_associations.each do |assoc|
|
|
49
|
-
assoc.descriptor.set_serialization_context context
|
|
50
|
-
end
|
|
51
|
-
end
|
|
52
|
-
|
|
53
|
-
#
|
|
54
|
-
# Applies attributes and association filters
|
|
55
|
-
#
|
|
56
|
-
def apply_filters(options)
|
|
57
|
-
return unless options.key?(:only) || options.key?(:except)
|
|
58
|
-
|
|
59
|
-
attributes_only_filters, associations_only_filters = resolve_filters(options, :only)
|
|
60
|
-
attributes_except_filters, associations_except_filters = resolve_filters(options, :except)
|
|
61
|
-
|
|
62
|
-
self.attributes = apply_attribute_filters(
|
|
63
|
-
attributes,
|
|
64
|
-
attributes_only_filters,
|
|
65
|
-
attributes_except_filters
|
|
66
|
-
)
|
|
67
|
-
|
|
68
|
-
self.method_fields = apply_attribute_filters(
|
|
69
|
-
method_fields,
|
|
70
|
-
attributes_only_filters,
|
|
71
|
-
attributes_except_filters
|
|
72
|
-
)
|
|
73
|
-
|
|
74
|
-
unless has_many_associations.empty?
|
|
75
|
-
self.has_many_associations = apply_association_filters(
|
|
76
|
-
has_many_associations,
|
|
77
|
-
{attributes: attributes_only_filters, associations: associations_only_filters},
|
|
78
|
-
attributes: attributes_except_filters, associations: associations_except_filters
|
|
79
|
-
)
|
|
80
|
-
end
|
|
81
|
-
|
|
82
|
-
unless has_one_associations.empty?
|
|
83
|
-
self.has_one_associations = apply_association_filters(
|
|
84
|
-
has_one_associations,
|
|
85
|
-
{attributes: attributes_only_filters, associations: associations_only_filters},
|
|
86
|
-
attributes: attributes_except_filters, associations: associations_except_filters
|
|
87
|
-
)
|
|
88
|
-
end
|
|
89
|
-
end
|
|
90
|
-
|
|
91
|
-
def apply_association_filters(associations, only_filters, except_filters)
|
|
92
|
-
attributes_only_filters = only_filters[:attributes] || []
|
|
93
|
-
unless attributes_only_filters.empty?
|
|
94
|
-
associations.select! do |association|
|
|
95
|
-
attributes_only_filters.include?(association.name_sym)
|
|
96
|
-
end
|
|
97
|
-
end
|
|
98
|
-
|
|
99
|
-
attributes_except_filters = except_filters[:attributes] || []
|
|
100
|
-
unless attributes_except_filters.empty?
|
|
101
|
-
associations.reject! do |association|
|
|
102
|
-
attributes_except_filters.include?(association.name_sym)
|
|
103
|
-
end
|
|
104
|
-
end
|
|
105
|
-
|
|
106
|
-
associations_only_filters = only_filters[:associations]
|
|
107
|
-
associations_except_filters = except_filters[:associations]
|
|
108
|
-
|
|
109
|
-
return associations if associations_only_filters.empty? && associations_except_filters.empty?
|
|
110
|
-
|
|
111
|
-
associations.map do |association|
|
|
112
|
-
name = association.name_sym
|
|
113
|
-
descriptor = association.descriptor
|
|
114
|
-
|
|
115
|
-
only_filter = associations_only_filters[name]
|
|
116
|
-
except_filter = associations_except_filters[name]
|
|
117
|
-
|
|
118
|
-
filters = {}
|
|
119
|
-
filters[:only] = only_filter unless only_filter.nil?
|
|
120
|
-
filters[:except] = except_filter unless except_filter.nil?
|
|
121
|
-
|
|
122
|
-
unless filters.empty?
|
|
123
|
-
next Panko::Association.new(
|
|
124
|
-
name,
|
|
125
|
-
association.name_str,
|
|
126
|
-
Panko::SerializationDescriptor.build(descriptor.type, filters)
|
|
127
|
-
)
|
|
128
|
-
end
|
|
129
|
-
|
|
130
|
-
association
|
|
131
|
-
end
|
|
132
|
-
end
|
|
133
|
-
|
|
134
|
-
def resolve_filters(options, filter)
|
|
135
|
-
filters = options.fetch(filter, {})
|
|
136
|
-
return filters, {} if filters.is_a? Array
|
|
137
|
-
|
|
138
|
-
# hash filters looks like this
|
|
139
|
-
# { instance: [:a], foo: [:b] }
|
|
140
|
-
# which mean, for the current instance use `[:a]` as filter
|
|
141
|
-
# and for association named `foo` use `[:b]`
|
|
142
|
-
|
|
143
|
-
return [], {} if filters.empty?
|
|
144
|
-
|
|
145
|
-
attributes_filters = filters.fetch(:instance, [])
|
|
146
|
-
association_filters = filters.except(:instance)
|
|
147
|
-
|
|
148
|
-
[attributes_filters, association_filters]
|
|
149
|
-
end
|
|
150
|
-
|
|
151
|
-
def apply_fields_filters(fields, only, except)
|
|
152
|
-
return fields & only unless only.empty?
|
|
153
|
-
return fields - except unless except.empty?
|
|
154
|
-
|
|
155
|
-
fields
|
|
156
|
-
end
|
|
157
|
-
|
|
158
|
-
def apply_attribute_filters(attributes, only, except)
|
|
159
|
-
unless only.empty?
|
|
160
|
-
attributes = attributes.select do |attribute|
|
|
161
|
-
name_to_check = attribute.name
|
|
162
|
-
name_to_check = attribute.alias_name unless attribute.alias_name.nil?
|
|
163
|
-
|
|
164
|
-
only.include?(name_to_check.to_sym)
|
|
165
|
-
end
|
|
166
|
-
end
|
|
167
|
-
|
|
168
|
-
unless except.empty?
|
|
169
|
-
attributes = attributes.reject do |attribute|
|
|
170
|
-
name_to_check = attribute.name
|
|
171
|
-
name_to_check = attribute.alias_name unless attribute.alias_name.nil?
|
|
172
|
-
|
|
173
|
-
except.include?(name_to_check.to_sym)
|
|
174
|
-
end
|
|
175
|
-
end
|
|
176
|
-
|
|
177
|
-
attributes
|
|
178
|
-
end
|
|
179
|
-
end
|
|
180
|
-
end
|
data/panko_serializer.gemspec
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
lib = File.expand_path("lib", __dir__)
|
|
4
|
-
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
5
|
-
require "panko/version"
|
|
6
|
-
|
|
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"]
|
|
12
|
-
|
|
13
|
-
spec.summary = "High Performance JSON Serialization for ActiveRecord & Ruby Objects"
|
|
14
|
-
spec.homepage = "https://panko.dev"
|
|
15
|
-
spec.license = "MIT"
|
|
16
|
-
|
|
17
|
-
spec.metadata = {
|
|
18
|
-
"bug_tracker_uri" => "https://github.com/yosiat/panko_serializer/issues",
|
|
19
|
-
"source_code_uri" => "https://github.com/yosiat/panko_serializer",
|
|
20
|
-
"documentation_uri" => "https://panko.dev",
|
|
21
|
-
"changelog_uri" => "https://github.com/yosiat/panko_serializer/releases"
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
spec.required_ruby_version = ">= 3.1.0"
|
|
25
|
-
|
|
26
|
-
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
|
27
|
-
f.match(%r{^(test|spec|features)/})
|
|
28
|
-
end
|
|
29
|
-
spec.require_paths = ["lib"]
|
|
30
|
-
|
|
31
|
-
spec.extensions << "ext/panko_serializer/extconf.rb"
|
|
32
|
-
|
|
33
|
-
spec.add_dependency "oj", "> 3.11.0", "< 4.0.0"
|
|
34
|
-
spec.add_dependency "activesupport"
|
|
35
|
-
spec.add_development_dependency "appraisal"
|
|
36
|
-
end
|