Skip to content

Commit

Permalink
feat: Oj Serializers 2.0 (#9)
Browse files Browse the repository at this point in the history
### Features ✨

- Improved performance (20% to 40% faster than v1)
- Added `render_as_hash` to efficiently build a Hash from the serializer
- `transform_keys :camelize`: a built-in setting to convert keys, in a way that does not affect runtime performance
- `sort_keys_by :name`: allows to sort the response alphabetically, without affecting runtime performance
- `render` shortcut, unifying `one` and `many`
- `attribute` as an easier approach to define serializer attributes

### Breaking Changes

Since returning a `Hash` is more convenient than returning a `Oj::StringWriter`, and performance is comparable, `default_format :hash` is now the default.

The previous APIs will still be available as `one_as_json` and `many_as_json`, as well as `default_format :json` to make the library work like in version 1.
  • Loading branch information
ElMassimo authored Mar 27, 2023
1 parent 39ef42a commit 5c38f8f
Show file tree
Hide file tree
Showing 44 changed files with 1,527 additions and 589 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
/pkg/
/spec/reports/
/tmp/
/benchmark/flamegraphs/
/gemfiles/*.lock

# rspec failure tracking
.rspec_status
20 changes: 20 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,21 @@ Layout/AccessModifierIndentation:
Layout/CaseIndentation:
EnforcedStyle: 'end'

Layout/EndAlignment:
Enabled: false

Layout/IndentationWidth:
Enabled: false

Layout/ElseAlignment:
Enabled: false

Naming/MethodParameterName:
Enabled: false

Style/GuardClause:
Enabled: false

# Disabled to allow the outdented comment style
Layout/CommentIndentation:
Enabled: false
Expand All @@ -59,3 +74,8 @@ Metrics/ClassLength:

Naming/PredicateName:
Enabled: false
Style/Alias:
Enabled: false
AllCops:
NewCops: enable
SuggestExtensions: false
17 changes: 17 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
## [Oj Serializers 2.0.0 (2023-03-27)](https://github.com/ElMassimo/oj_serializers/pull/9)

### Features ✨

- Improved performance (20% to 40% faster than v1)
- Added `render_as_hash` to efficiently build a Hash from the serializer
- `transform_keys :camelize`: a built-in setting to convert keys, in a way that does not affect runtime performance
- `sort_keys_by :name`: allows to sort the response alphabetically, without affecting runtime performance
- `render` shortcut, unifying `one` and `many`
- `attribute` as an easier approach to define serializer attributes

### Breaking Changes

Since returning a `Hash` is more convenient than returning a `Oj::StringWriter`, and performance is comparable, `default_format :hash` is now the default.

The previous APIs will still be available as `one_as_json` and `many_as_json`, as well as `default_format :json` to make the library work like in version 1.

## Oj Serializers 1.0.2 (2023-03-01) ##

* [fix: avoid freezing `ALLOWED_INSTANCE_VARIABLES`](https://github.com/ElMassimo/oj_serializers/commit/ade0302)
Expand Down
21 changes: 20 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,28 @@

source 'https://rubygems.org'

# Specify your gem's dependencies in oj_serializers.gemspec
git_source(:github) { |repo| "https://github.com/#{repo}.git" }

gemspec

group :development do
gem 'rubocop'
end

group :development, :test do
gem 'active_model_serializers', '~> 0.8'
gem 'alba'
gem 'benchmark-ips'
gem 'benchmark-memory'
gem 'blueprinter', '~> 0.8'
gem 'memory_profiler'
gem 'mongoid'
gem 'panko_serializer'
gem 'pry-byebug', '~> 3.9'
gem 'rails' unless ENV['NO_RAILS']
gem 'rake', '~> 13.0'
gem 'rspec-rails', '~> 4.0'
gem 'simplecov', '< 0.18'
gem 'singed'
gem 'sqlite3'
end
137 changes: 117 additions & 20 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,19 +1,42 @@
PATH
remote: .
specs:
oj_serializers (1.0.2)
oj_serializers (2.0.0)
oj (>= 3.14.0)

GEM
remote: https://rubygems.org/
specs:
actioncable (6.0.3.4)
actionpack (= 6.0.3.4)
nio4r (~> 2.0)
websocket-driver (>= 0.6.1)
actionmailbox (6.0.3.4)
actionpack (= 6.0.3.4)
activejob (= 6.0.3.4)
activerecord (= 6.0.3.4)
activestorage (= 6.0.3.4)
activesupport (= 6.0.3.4)
mail (>= 2.7.1)
actionmailer (6.0.3.4)
actionpack (= 6.0.3.4)
actionview (= 6.0.3.4)
activejob (= 6.0.3.4)
mail (~> 2.5, >= 2.5.4)
rails-dom-testing (~> 2.0)
actionpack (6.0.3.4)
actionview (= 6.0.3.4)
activesupport (= 6.0.3.4)
rack (~> 2.0, >= 2.0.8)
rack-test (>= 0.6.3)
rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.0, >= 1.2.0)
actiontext (6.0.3.4)
actionpack (= 6.0.3.4)
activerecord (= 6.0.3.4)
activestorage (= 6.0.3.4)
activesupport (= 6.0.3.4)
nokogiri (>= 1.8.5)
actionview (6.0.3.4)
activesupport (= 6.0.3.4)
builder (~> 3.1)
Expand All @@ -25,52 +48,92 @@ GEM
activemodel (>= 4.1, < 6.1)
case_transform (>= 0.2)
jsonapi-renderer (>= 0.1.1.beta1, < 0.3)
activejob (6.0.3.4)
activesupport (= 6.0.3.4)
globalid (>= 0.3.6)
activemodel (6.0.3.4)
activesupport (= 6.0.3.4)
activerecord (6.0.3.4)
activemodel (= 6.0.3.4)
activesupport (= 6.0.3.4)
activestorage (6.0.3.4)
actionpack (= 6.0.3.4)
activejob (= 6.0.3.4)
activerecord (= 6.0.3.4)
marcel (~> 0.3.1)
activesupport (6.0.3.4)
concurrent-ruby (~> 1.0, >= 1.0.2)
i18n (>= 0.7, < 2)
minitest (~> 5.1)
tzinfo (~> 1.1)
zeitwerk (~> 2.2, >= 2.2.2)
ast (2.4.1)
alba (2.2.0)
ast (2.4.2)
benchmark-ips (2.8.3)
benchmark-memory (0.1.2)
memory_profiler (~> 0.9)
blueprinter (0.25.3)
bson (4.11.1)
builder (3.2.4)
byebug (11.1.3)
case_transform (0.2)
activesupport
coderay (1.1.3)
colorize (0.8.1)
concurrent-ruby (1.1.7)
crass (1.0.6)
date (3.3.3)
diff-lcs (1.4.4)
docile (1.3.2)
erubi (1.9.0)
globalid (1.1.0)
activesupport (>= 5.0)
i18n (1.8.5)
concurrent-ruby (~> 1.0)
json (2.3.1)
jsonapi-renderer (0.2.2)
loofah (2.7.0)
crass (~> 1.0.2)
nokogiri (>= 1.5.9)
mail (2.8.1)
mini_mime (>= 0.1.1)
net-imap
net-pop
net-smtp
marcel (0.3.3)
mimemagic (~> 0.3.2)
memory_profiler (0.9.14)
method_source (1.0.0)
mimemagic (0.3.10)
nokogiri (~> 1)
rake
mini_mime (1.1.2)
minitest (5.18.0)
mongo (2.13.1)
bson (>= 4.8.2, < 5.0.0)
mongoid (7.1.4)
activemodel (>= 5.1, < 6.1)
mongo (>= 2.7.0, < 3.0.0)
net-imap (0.3.4)
date
net-protocol
net-pop (0.1.2)
net-protocol
net-protocol (0.2.1)
timeout
net-smtp (0.3.3)
net-protocol
nio4r (2.5.8)
nokogiri (1.14.2-arm64-darwin)
racc (~> 1.4)
nokogiri (1.14.2-x86_64-linux)
racc (~> 1.4)
oj (3.14.2)
parallel (1.19.2)
parser (2.7.1.4)
panko_serializer (0.7.9)
activesupport
oj (> 3.11.0, < 4.0.0)
parallel (1.22.1)
parser (3.2.1.1)
ast (~> 2.4.1)
pry (0.13.1)
coderay (~> 1.1)
Expand All @@ -82,6 +145,21 @@ GEM
rack (2.2.3)
rack-test (1.1.0)
rack (>= 1.0, < 3)
rails (6.0.3.4)
actioncable (= 6.0.3.4)
actionmailbox (= 6.0.3.4)
actionmailer (= 6.0.3.4)
actionpack (= 6.0.3.4)
actiontext (= 6.0.3.4)
actionview (= 6.0.3.4)
activejob (= 6.0.3.4)
activemodel (= 6.0.3.4)
activerecord (= 6.0.3.4)
activestorage (= 6.0.3.4)
activesupport (= 6.0.3.4)
bundler (>= 1.3.0)
railties (= 6.0.3.4)
sprockets-rails (>= 2.0.0)
rails-dom-testing (2.0.3)
activesupport (>= 4.2.0)
nokogiri (>= 1.6)
Expand All @@ -93,10 +171,10 @@ GEM
method_source
rake (>= 0.8.7)
thor (>= 0.20.3, < 2.0)
rainbow (3.0.0)
rainbow (3.1.1)
rake (13.0.6)
regexp_parser (1.7.1)
rexml (3.2.4)
regexp_parser (2.7.0)
rexml (3.2.5)
rspec-core (3.9.3)
rspec-support (~> 3.9.3)
rspec-expectations (3.9.3)
Expand All @@ -114,49 +192,68 @@ GEM
rspec-mocks (~> 3.9)
rspec-support (~> 3.9)
rspec-support (3.9.4)
rubocop (0.86.0)
rubocop (1.48.1)
json (~> 2.3)
parallel (~> 1.10)
parser (>= 2.7.0.1)
parser (>= 3.2.0.0)
rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 1.7)
rexml
rubocop-ast (>= 0.0.3, < 1.0)
regexp_parser (>= 1.8, < 3.0)
rexml (>= 3.2.5, < 4.0)
rubocop-ast (>= 1.26.0, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 1.4.0, < 2.0)
rubocop-ast (0.1.0)
parser (>= 2.7.0.1)
ruby-progressbar (1.10.1)
unicode-display_width (>= 2.4.0, < 3.0)
rubocop-ast (1.27.0)
parser (>= 3.2.1.0)
ruby-progressbar (1.13.0)
simplecov (0.17.1)
docile (~> 1.1)
json (>= 1.8, < 3)
simplecov-html (~> 0.10.0)
simplecov-html (0.10.2)
singed (0.1.1)
colorize
stackprof
sprockets (4.1.1)
concurrent-ruby (~> 1.0)
rack (> 1, < 3)
sprockets-rails (3.4.2)
actionpack (>= 5.2)
activesupport (>= 5.2)
sprockets (>= 3.0.0)
sqlite3 (1.4.2)
stackprof (0.2.24)
thor (1.0.1)
thread_safe (0.3.6)
timeout (0.3.2)
tzinfo (1.2.7)
thread_safe (~> 0.1)
unicode-display_width (1.7.0)
unicode-display_width (2.4.2)
websocket-driver (0.7.5)
websocket-extensions (>= 0.1.0)
websocket-extensions (0.1.5)
zeitwerk (2.4.1)

PLATFORMS
arm64-darwin-21
x86_64-linux

DEPENDENCIES
actionpack (>= 4.0)
active_model_serializers (~> 0.8)
activerecord
alba
benchmark-ips
benchmark-memory
blueprinter (~> 0.8)
memory_profiler
mongoid
oj_serializers!
panko_serializer
pry-byebug (~> 3.9)
railties (>= 4.0)
rails
rake (~> 13.0)
rspec-rails (~> 4.0)
rubocop
simplecov (< 0.18)
singed
sqlite3

BUNDLED WITH
Expand Down
Loading

0 comments on commit 5c38f8f

Please sign in to comment.