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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cabbda58cec9e9d6d1c96149f6d72d589a653f3db8112781a8a5267e4d3a5c25
4
- data.tar.gz: b670cb0a6d034da44cab1f267a32e44fe2e99defd3d4318cbe03efc6bf02c8f4
3
+ metadata.gz: 61d5619d6222aee091fc2401da8a274a2d8aa5beebf3d8626f2bc82c6c24e89f
4
+ data.tar.gz: c6368081ef1701ec0d7444c9e544071d03ab5ae706fc344c9d52b027833efa4b
5
5
  SHA512:
6
- metadata.gz: 350fd6d656ef37072e22033cb77cf9bb50f613f53392fcb20a0bc229ceeaa4a90f03ad41f75e1176f1adca65bb5a2eeffef13c33e60d288a71600fbaa5fb2572
7
- data.tar.gz: 494d0202f252fd01613ba3621284e8d100d25df5d0e73e8732d4aaddc989ecf05282320c6f24c38548cd7ebc1d45920a44da6abaa09fb9efe7b180898d0ffdf3
6
+ metadata.gz: d303cd41e825e8c9bbdfd9213d9e76b99969b348e1943ebee1deb2d9ee469338dcfcab5e5fb3661915f602e1e9bed532ac96add4a387e843e1e74f356e4aae1b
7
+ data.tar.gz: 73cc7d1b8236c33c4f3a24f633e7029ec59f288b57fe5668da1363c926ea0d87062170440b2aef3332ada59515b8c11c9548f195137ea63507ca06705ec9547a
data/.rubocop.yml CHANGED
@@ -23,6 +23,10 @@ AllCops:
23
23
  EnabledByDefault: true
24
24
  TargetRubyVersion: 3.0
25
25
 
26
+ Bundler/GemComment:
27
+ Exclude:
28
+ - 'benchmark/**/*'
29
+
26
30
  # Items in Gemfile is dev dependencies and we don't have to specify versions.
27
31
  Bundler/GemVersion:
28
32
  Enabled: false
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.66.1', require: false # For lint
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
  [![Maintainability](https://api.codeclimate.com/v1/badges/fdab4cc0de0b9addcfe8/maintainability)](https://codeclimate.com/github/okuramasafumi/alba/maintainability)
7
7
  ![GitHub code size in bytes](https://img.shields.io/github/languages/code-size/okuramasafumi/alba)
8
8
  ![GitHub](https://img.shields.io/github/license/okuramasafumi/alba)
9
- [![Contributor Covenant](https://img.shields.io/badge/Contributor%20Covenant-2.1-4baaaa.svg)](code_of_conduct.md)
9
+ [![Contributor Covenant](https://img.shields.io/badge/Contributor%20Covenant-2.1-4baaaa.svg)](CODE_OF_CONDUCT.md)
10
10
 
11
11
  # Alba
12
12
 
data/alba.gemspec CHANGED
@@ -28,4 +28,6 @@ Gem::Specification.new do |spec|
28
28
  spec.bindir = 'exe'
29
29
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
30
30
  spec.require_paths = ['lib']
31
+
32
+ spec.add_dependency "ostruct", "~> 0.6"
31
33
  end
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
- ActionController::Base.define_method(:serialize) do |obj, with: nil, &block|
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
- ActionController::Base.define_method(:render_serialized_json) do |obj, with: nil, &block|
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Alba
4
- VERSION = '3.3.0'
4
+ VERSION = '3.3.2'
5
5
  end
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 Mertics/AbcSize
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.0
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-09 00:00:00.000000000 Z
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
@@ -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)