Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Oj Serializers 2.0 #9

Merged
merged 30 commits into from
Mar 27, 2023
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
0dced46
feat: new hash-based zero indirection implementation, faster than str…
ElMassimo Mar 17, 2023
a18e6ac
feat: `serialize` shortcut, `sort_attributes_by`, and `identifier`
ElMassimo Mar 17, 2023
0c7f719
feat: add built-in support to transform keys (camelize / camel_case)
ElMassimo Mar 17, 2023
d25b46c
chore: fix test
ElMassimo Mar 17, 2023
b420c2b
chore: run rubocop
ElMassimo Mar 17, 2023
d37a8af
chore: require support files
ElMassimo Mar 17, 2023
257b511
chore: fix gemfiles
ElMassimo Mar 17, 2023
173645b
perf: optimize performance of string writer, now it's in the lead again
ElMassimo Mar 17, 2023
94cc663
chore: avoid bind_object to squeeze more performance
ElMassimo Mar 17, 2023
7321e64
chore: avoid calling `instance` inside a loop
ElMassimo Mar 20, 2023
33b1a12
chore: fix test gemfiles
ElMassimo Mar 20, 2023
a1d6389
chore: improve dev-time checks
ElMassimo Mar 20, 2023
02a0637
chore: fix rubocop
ElMassimo Mar 20, 2023
516c503
chore: fix edge gemfile
ElMassimo Mar 20, 2023
e94694c
chore: fix memory usage benchmark
ElMassimo Mar 20, 2023
8543f23
chore: rubocop [skip ci]
ElMassimo Mar 20, 2023
71dc3b0
chore: mention the purpose
ElMassimo Mar 20, 2023
6b81d5f
release: 2.0.0-alpha.1
ElMassimo Mar 20, 2023
7e7cf5e
feat: allow `attributes` to take a hash of aliases
ElMassimo Mar 25, 2023
b366276
chore: add benchmarks for alba and panko_serializer
ElMassimo Mar 25, 2023
77223b0
chore: fix rubocop
ElMassimo Mar 27, 2023
e6b2e16
chore: add alba and panko to memory usage benchmark
ElMassimo Mar 27, 2023
6fd2c97
chore: add `belongs_to` alias for `has_one`
ElMassimo Mar 27, 2023
23edee8
feat: enable caching for hash-based rendering
ElMassimo Mar 27, 2023
102d30e
chore: document benchmarks
ElMassimo Mar 27, 2023
59bb312
feat: has_one and has_many can take a block, mongo_attributes can def…
ElMassimo Mar 27, 2023
f726658
feat: allow 'attribute' to take in a block
ElMassimo Mar 27, 2023
8a481f7
chore: improve readme
ElMassimo Mar 27, 2023
a50d922
chore: fix rubocop
ElMassimo Mar 27, 2023
90882b2
chore: prepare release
ElMassimo Mar 27, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 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,7 @@ Metrics/ClassLength:

Naming/PredicateName:
Enabled: false
Style/Alias:
Enabled: false
AllCops:
NewCops: enable
20 changes: 19 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,27 @@

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 'actionpack'
gem 'active_model_serializers', '~> 0.8'
gem 'activerecord'
gem 'benchmark-ips'
gem 'benchmark-memory'
gem 'blueprinter', '~> 0.8'
gem 'memory_profiler'
gem 'mongoid'
gem 'pry-byebug', '~> 3.9'
gem 'railties'
gem 'rake', '~> 13.0'
gem 'rspec-rails', '~> 4.0'
gem 'simplecov', '< 0.18'
gem 'sqlite3'
end
42 changes: 24 additions & 18 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,11 @@ GEM
minitest (~> 5.1)
tzinfo (~> 1.1)
zeitwerk (~> 2.2, >= 2.2.2)
ast (2.4.1)
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)
Expand Down Expand Up @@ -69,8 +72,8 @@ GEM
nokogiri (1.14.2-x86_64-linux)
racc (~> 1.4)
oj (3.14.2)
parallel (1.19.2)
parser (2.7.1.4)
parallel (1.22.1)
parser (3.2.1.1)
ast (~> 2.4.1)
pry (0.13.1)
coderay (~> 1.1)
Expand All @@ -93,10 +96,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,18 +117,19 @@ 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)
Expand All @@ -136,23 +140,25 @@ GEM
thread_safe (0.3.6)
tzinfo (1.2.7)
thread_safe (~> 0.1)
unicode-display_width (1.7.0)
unicode-display_width (2.4.2)
zeitwerk (2.4.1)

PLATFORMS
arm64-darwin-21
x86_64-linux

DEPENDENCIES
actionpack (>= 4.0)
actionpack
active_model_serializers (~> 0.8)
activerecord
benchmark-ips
benchmark-memory
blueprinter (~> 0.8)
memory_profiler
mongoid
oj_serializers!
pry-byebug (~> 3.9)
railties (>= 4.0)
railties
rake (~> 13.0)
rspec-rails (~> 4.0)
rubocop
Expand Down
10 changes: 5 additions & 5 deletions MIGRATION_GUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,16 +96,16 @@ class AlbumSerializer < Oj::Serializer

has_many :songs, serializer: SongSerializer

attribute \
serialize if: -> { album.released? }
def release
album.release_date.strftime('%B %d, %Y')
end, if: -> { album.released? }
end
end
```

The shorthand syntax for serializer attributes might not be very palatable at
first, but having the entire definition in one place makes it a lot easier to
follow, specially in large serializers.
The shorthand syntax for serializer attributes might seem odd at first, but it
makes it a lot easier to differentiate helper methods from attributes,
especially in large serializers.

## Migrate gradually, one at a time

Expand Down
Loading