alba 3.3.0 → 3.3.2
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/.rubocop.yml +4 -0
- data/CHANGELOG.md +12 -0
- data/Gemfile +1 -1
- data/README.md +1 -1
- data/alba.gemspec +2 -0
- data/benchmark/Gemfile +24 -0
- data/lib/alba/railtie.rb +2 -2
- data/lib/alba/version.rb +1 -1
- data/lib/alba.rb +1 -1
- metadata +18 -5
- data/.github/workflows/perf.yml +0 -16
- data/script/perf_check.rb +0 -107
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 61d5619d6222aee091fc2401da8a274a2d8aa5beebf3d8626f2bc82c6c24e89f
|
4
|
+
data.tar.gz: c6368081ef1701ec0d7444c9e544071d03ab5ae706fc344c9d52b027833efa4b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d303cd41e825e8c9bbdfd9213d9e76b99969b348e1943ebee1deb2d9ee469338dcfcab5e5fb3661915f602e1e9bed532ac96add4a387e843e1e74f356e4aae1b
|
7
|
+
data.tar.gz: 73cc7d1b8236c33c4f3a24f633e7029ec59f288b57fe5668da1363c926ea0d87062170440b2aef3332ada59515b8c11c9548f195137ea63507ca06705ec9547a
|
data/.rubocop.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -6,6 +6,18 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
6
6
|
|
7
7
|
## [Unreleased]
|
8
8
|
|
9
|
+
## [3.3.2] 2024-10-30
|
10
|
+
|
11
|
+
### Fixed
|
12
|
+
|
13
|
+
- Rails integration with `ActionController::API`
|
14
|
+
|
15
|
+
## [3.3.1] 2024-10-17
|
16
|
+
|
17
|
+
### Fixed
|
18
|
+
|
19
|
+
- Add ostruct as gemspec dependency to be prepared for ruby 3.3.5. [#386](https://github.com/okuramasafumi/alba/pull/386)
|
20
|
+
|
9
21
|
## [3.3.0] 2024-10-09
|
10
22
|
|
11
23
|
### Added
|
data/Gemfile
CHANGED
@@ -11,7 +11,7 @@ gem 'ffaker', require: false # For testing
|
|
11
11
|
gem 'minitest', '~> 5.14' # For test
|
12
12
|
gem 'railties', require: false # For Rails integration testing
|
13
13
|
gem 'rake', '~> 13.0' # For test and automation
|
14
|
-
gem 'rubocop', '~> 1.
|
14
|
+
gem 'rubocop', '~> 1.67.0', require: false # For lint
|
15
15
|
gem 'rubocop-gem_dev', '>= 0.3.0', require: false # For lint
|
16
16
|
gem 'rubocop-md', '~> 1.0', require: false # For lint
|
17
17
|
gem 'rubocop-minitest', '~> 0.36.0', require: false # For lint
|
data/README.md
CHANGED
@@ -6,7 +6,7 @@
|
|
6
6
|
[](https://codeclimate.com/github/okuramasafumi/alba/maintainability)
|
7
7
|

|
8
8
|

|
9
|
-
[](
|
9
|
+
[](CODE_OF_CONDUCT.md)
|
10
10
|
|
11
11
|
# Alba
|
12
12
|
|
data/alba.gemspec
CHANGED
data/benchmark/Gemfile
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
source 'https://rubygems.org'
|
4
|
+
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
|
5
|
+
|
6
|
+
gem 'active_model_serializers'
|
7
|
+
gem 'activerecord', '~> 7.1'
|
8
|
+
gem 'alba', path: '../'
|
9
|
+
gem 'benchmark-ips'
|
10
|
+
gem 'benchmark-memory'
|
11
|
+
gem 'blueprinter'
|
12
|
+
gem 'fast_serializer_ruby'
|
13
|
+
gem 'jbuilder'
|
14
|
+
gem 'jserializer'
|
15
|
+
gem 'multi_json'
|
16
|
+
gem 'oj'
|
17
|
+
gem 'oj_serializers'
|
18
|
+
gem 'panko_serializer'
|
19
|
+
gem 'pg'
|
20
|
+
gem 'primalize'
|
21
|
+
gem 'representable'
|
22
|
+
gem 'simple_ams'
|
23
|
+
gem 'sqlite3', '~> 1.4'
|
24
|
+
gem 'turbostreamer'
|
data/lib/alba/railtie.rb
CHANGED
@@ -7,11 +7,11 @@ module Alba
|
|
7
7
|
Alba.inflector = :active_support
|
8
8
|
|
9
9
|
ActiveSupport.on_load(:action_controller) do
|
10
|
-
|
10
|
+
define_method(:serialize) do |obj, with: nil, &block|
|
11
11
|
with.nil? ? Alba.resource_with(obj, &block) : with.new(obj)
|
12
12
|
end
|
13
13
|
|
14
|
-
|
14
|
+
define_method(:render_serialized_json) do |obj, with: nil, &block|
|
15
15
|
json = with.nil? ? Alba.resource_with(obj, &block) : with.new(obj)
|
16
16
|
render json: json
|
17
17
|
end
|
data/lib/alba/version.rb
CHANGED
data/lib/alba.rb
CHANGED
@@ -261,7 +261,7 @@ module Alba
|
|
261
261
|
inflector
|
262
262
|
end
|
263
263
|
|
264
|
-
def register_default_types # rubocop:disable
|
264
|
+
def register_default_types # rubocop:disable Metrics/AbcSize
|
265
265
|
[String, :String].each do |t|
|
266
266
|
register_type(t, check: ->(obj) { obj.is_a?(String) }, converter: lambda(&:to_s))
|
267
267
|
end
|
metadata
CHANGED
@@ -1,14 +1,28 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: alba
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.3.
|
4
|
+
version: 3.3.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- OKURA Masafumi
|
8
8
|
bindir: exe
|
9
9
|
cert_chain: []
|
10
|
-
date: 2024-10-
|
11
|
-
dependencies:
|
10
|
+
date: 2024-10-30 00:00:00.000000000 Z
|
11
|
+
dependencies:
|
12
|
+
- !ruby/object:Gem::Dependency
|
13
|
+
name: ostruct
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
15
|
+
requirements:
|
16
|
+
- - "~>"
|
17
|
+
- !ruby/object:Gem::Version
|
18
|
+
version: '0.6'
|
19
|
+
type: :runtime
|
20
|
+
prerelease: false
|
21
|
+
version_requirements: !ruby/object:Gem::Requirement
|
22
|
+
requirements:
|
23
|
+
- - "~>"
|
24
|
+
- !ruby/object:Gem::Version
|
25
|
+
version: '0.6'
|
12
26
|
description: Alba is the fastest JSON serializer for Ruby. It focuses on performance,
|
13
27
|
flexibility and usability.
|
14
28
|
email:
|
@@ -25,7 +39,6 @@ files:
|
|
25
39
|
- ".github/workflows/codeql-analysis.yml"
|
26
40
|
- ".github/workflows/lint.yml"
|
27
41
|
- ".github/workflows/main.yml"
|
28
|
-
- ".github/workflows/perf.yml"
|
29
42
|
- ".gitignore"
|
30
43
|
- ".rubocop.yml"
|
31
44
|
- ".yardopts"
|
@@ -39,6 +52,7 @@ files:
|
|
39
52
|
- Rakefile
|
40
53
|
- SECURITY.md
|
41
54
|
- alba.gemspec
|
55
|
+
- benchmark/Gemfile
|
42
56
|
- benchmark/README.md
|
43
57
|
- benchmark/collection.rb
|
44
58
|
- benchmark/prep.rb
|
@@ -68,7 +82,6 @@ files:
|
|
68
82
|
- logo/alba-card.png
|
69
83
|
- logo/alba-sign.png
|
70
84
|
- logo/alba-typography.png
|
71
|
-
- script/perf_check.rb
|
72
85
|
homepage: https://github.com/okuramasafumi/alba
|
73
86
|
licenses:
|
74
87
|
- MIT
|
data/.github/workflows/perf.yml
DELETED
@@ -1,16 +0,0 @@
|
|
1
|
-
name: Performance Check
|
2
|
-
|
3
|
-
on: [pull_request]
|
4
|
-
|
5
|
-
jobs:
|
6
|
-
build:
|
7
|
-
runs-on: ubuntu-latest
|
8
|
-
steps:
|
9
|
-
- uses: actions/checkout@v4
|
10
|
-
- name: Set up Ruby
|
11
|
-
uses: ruby/setup-ruby@v1
|
12
|
-
with:
|
13
|
-
ruby-version: 3.3
|
14
|
-
- name: Run benchmark
|
15
|
-
run: |
|
16
|
-
ruby script/perf_check.rb
|
data/script/perf_check.rb
DELETED
@@ -1,107 +0,0 @@
|
|
1
|
-
# Benchmark script to run varieties of JSON serializers
|
2
|
-
# Fetch Alba from local, otherwise fetch latest from RubyGems
|
3
|
-
# exit(status)
|
4
|
-
|
5
|
-
require_relative '../benchmark/prep'
|
6
|
-
|
7
|
-
# --- Alba serializers ---
|
8
|
-
|
9
|
-
require "alba"
|
10
|
-
|
11
|
-
class AlbaCommentResource
|
12
|
-
include ::Alba::Resource
|
13
|
-
attributes :id, :body
|
14
|
-
end
|
15
|
-
|
16
|
-
class AlbaPostResource
|
17
|
-
include ::Alba::Resource
|
18
|
-
attributes :id, :body
|
19
|
-
attribute :commenter_names do |post|
|
20
|
-
post.commenters.pluck(:name)
|
21
|
-
end
|
22
|
-
many :comments, resource: AlbaCommentResource
|
23
|
-
end
|
24
|
-
|
25
|
-
# --- Blueprint serializers ---
|
26
|
-
|
27
|
-
require "blueprinter"
|
28
|
-
|
29
|
-
class CommentBlueprint < Blueprinter::Base
|
30
|
-
fields :id, :body
|
31
|
-
end
|
32
|
-
|
33
|
-
class PostBlueprint < Blueprinter::Base
|
34
|
-
fields :id, :body, :commenter_names
|
35
|
-
association :comments, blueprint: CommentBlueprint
|
36
|
-
|
37
|
-
def commenter_names
|
38
|
-
commenters.pluck(:name)
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
# --- JBuilder serializers ---
|
43
|
-
|
44
|
-
require "jbuilder"
|
45
|
-
|
46
|
-
class Post
|
47
|
-
def to_builder
|
48
|
-
Jbuilder.new do |post|
|
49
|
-
post.call(self, :id, :body, :commenter_names, :comments)
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
def commenter_names
|
54
|
-
commenters.pluck(:name)
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
class Comment
|
59
|
-
def to_builder
|
60
|
-
Jbuilder.new do |comment|
|
61
|
-
comment.call(self, :id, :body)
|
62
|
-
end
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
# --- Test data creation ---
|
67
|
-
|
68
|
-
100.times do |i|
|
69
|
-
post = Post.create!(body: "post#{i}")
|
70
|
-
user1 = User.create!(name: "John#{i}")
|
71
|
-
user2 = User.create!(name: "Jane#{i}")
|
72
|
-
10.times do |n|
|
73
|
-
post.comments.create!(commenter: user1, body: "Comment1_#{i}_#{n}")
|
74
|
-
post.comments.create!(commenter: user2, body: "Comment2_#{i}_#{n}")
|
75
|
-
end
|
76
|
-
end
|
77
|
-
|
78
|
-
posts = Post.all.to_a
|
79
|
-
|
80
|
-
# --- Store the serializers in procs ---
|
81
|
-
|
82
|
-
alba = Proc.new { AlbaPostResource.new(posts).serialize }
|
83
|
-
blueprinter = Proc.new { PostBlueprint.render(posts) }
|
84
|
-
jbuilder = Proc.new do
|
85
|
-
Jbuilder.new do |json|
|
86
|
-
json.array!(posts) do |post|
|
87
|
-
json.post post.to_builder
|
88
|
-
end
|
89
|
-
end.target!
|
90
|
-
end
|
91
|
-
|
92
|
-
# --- Run the benchmarks ---
|
93
|
-
|
94
|
-
require 'benchmark/ips'
|
95
|
-
result = Benchmark.ips do |x|
|
96
|
-
x.report(:alba, &alba)
|
97
|
-
x.report(:blueprinter, &blueprinter)
|
98
|
-
x.report(:jbuilder, &jbuilder)
|
99
|
-
end
|
100
|
-
|
101
|
-
entries = result.entries.map {|entry| [entry.label, entry.iterations]}
|
102
|
-
alba_ips = entries.find {|e| e.first == :alba }.last
|
103
|
-
blueprinter_ips = entries.find {|e| e.first == :blueprinter }.last
|
104
|
-
jbuidler_ips = entries.find {|e| e.first == :jbuilder }.last
|
105
|
-
# Alba should be as fast as jbuilder and faster than blueprinter
|
106
|
-
alba_is_fast_enough = (alba_ips - jbuidler_ips) > -10.0 && (alba_ips - blueprinter_ips) > 10.0
|
107
|
-
exit(alba_is_fast_enough)
|