alba 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/main.yml +10 -1
- data/.rubocop.yml +9 -0
- data/CHANGELOG.md +9 -0
- data/Gemfile +7 -3
- data/README.md +31 -10
- data/Rakefile +4 -1
- data/alba.gemspec +2 -2
- data/gemfiles/all.gemfile +18 -0
- data/gemfiles/without_active_support.gemfile +17 -0
- data/gemfiles/without_oj.gemfile +17 -0
- data/lib/alba.rb +6 -10
- data/lib/alba/association.rb +0 -5
- data/lib/alba/key_transformer.rb +1 -0
- data/lib/alba/version.rb +1 -1
- metadata +7 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3fc2741e03be6373aa324768358a1acf4b713ec43bba5daf80d133a08d0cc12b
|
4
|
+
data.tar.gz: 7228dc09384d5d4d6e99456a6f14d6e0cb3d678483cd59a7439d6a150f463e4b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0fb68a3a1c786aa1b776246d08fd23bada8d4c7fcff0ea2ba33a49a1410d9b1e839407450ff2d1137f531a8e80738977369a4f857199d3bb65c98b140d7cd6b9
|
7
|
+
data.tar.gz: fcfb93544bab6b48e6ae24946992231a6023df52763d807dad276f1468c1ce77d255fe637de3a72efacffe2d20915d203ddc1f247908c4f6e4d69ae6ea4c97da
|
data/.github/workflows/main.yml
CHANGED
@@ -8,11 +8,16 @@ jobs:
|
|
8
8
|
fail-fast: false
|
9
9
|
matrix:
|
10
10
|
os: [ubuntu-latest, windows-latest, macos-latest]
|
11
|
-
ruby: [2.5, 2.6, 2.7, 3.0, head, truffleruby]
|
11
|
+
ruby: [2.5, 2.6, 2.7, 3.0, head, jruby, truffleruby]
|
12
|
+
gemfile: [all, without_active_support, without_oj]
|
12
13
|
exclude:
|
14
|
+
- os: windows-latest
|
15
|
+
ruby: jruby
|
13
16
|
- os: windows-latest
|
14
17
|
ruby: truffleruby
|
15
18
|
runs-on: ${{ matrix.os }}
|
19
|
+
env: # $BUNDLE_GEMFILE must be set at the job level, so it is set for all steps
|
20
|
+
BUNDLE_GEMFILE: gemfiles/${{ matrix.gemfile }}.gemfile
|
16
21
|
steps:
|
17
22
|
- uses: actions/checkout@v2
|
18
23
|
- name: Set up Ruby
|
@@ -23,3 +28,7 @@ jobs:
|
|
23
28
|
- name: Run the default task
|
24
29
|
run: |
|
25
30
|
bundle exec rake
|
31
|
+
- name: CodeCov
|
32
|
+
uses: codecov/codecov-action@v1
|
33
|
+
with:
|
34
|
+
files: ./coverage/coverage.xml
|
data/.rubocop.yml
CHANGED
@@ -42,6 +42,11 @@ Metrics/ParameterLists:
|
|
42
42
|
Exclude:
|
43
43
|
- 'lib/alba/resource.rb'
|
44
44
|
|
45
|
+
# We need to eval resource code to test errors on resource classes
|
46
|
+
Security/Eval:
|
47
|
+
Exclude:
|
48
|
+
- 'test/**/*.rb'
|
49
|
+
|
45
50
|
Style/ConstantVisibility:
|
46
51
|
Exclude:
|
47
52
|
- 'lib/alba/version.rb'
|
@@ -61,3 +66,7 @@ Style/InlineComment:
|
|
61
66
|
|
62
67
|
Style/MethodCallWithArgsParentheses:
|
63
68
|
Enabled: false
|
69
|
+
|
70
|
+
# There are so many cases we just want `if` expression!
|
71
|
+
Style/MissingElse:
|
72
|
+
EnforcedStyle: case
|
data/CHANGELOG.md
CHANGED
@@ -6,6 +6,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
6
6
|
|
7
7
|
## [Unreleased]
|
8
8
|
|
9
|
+
## [1.0.1] - 2021-04-15
|
10
|
+
|
11
|
+
- [Fix] Don't cache resource class for `Alba.serialize` [9ed5253]
|
12
|
+
- [Improve] Warn when `ActiveSupport` or `Oj` are absent [d3ab3eb]
|
13
|
+
- [Fix] Delete unreachable `to_hash` method on Association [1ba1f90]
|
14
|
+
- [Fix] Stringify key before transforming [b4eb79e]
|
15
|
+
- [Misc] Support Ruby 2.5.0 and above, not 2.5.7 and above [43f1d17]
|
16
|
+
- [Fix] Remove accidentally added `p` debug [5d0324b]
|
17
|
+
|
9
18
|
## [1.0.0] - 2021-04-07
|
10
19
|
|
11
20
|
This is the first major release of Alba and it includes so many features. To see all the features you can have a look at [README](https://github.com/okuramasafumi/alba/blob/master/README.md#features).
|
data/Gemfile
CHANGED
@@ -4,14 +4,18 @@ source 'https://rubygems.org'
|
|
4
4
|
gemspec
|
5
5
|
|
6
6
|
gem 'activesupport', require: false # For backend
|
7
|
-
gem 'coveralls', require: false # For test coverage
|
8
7
|
gem 'minitest', '~> 5.14' # For test
|
9
|
-
gem 'oj', '~> 3.11', platform: :ruby, require: false # For backend
|
10
8
|
gem 'rake', '~> 13.0' # For test and automation
|
11
9
|
gem 'rubocop', '>= 0.79.0', require: false # For lint
|
12
10
|
gem 'rubocop-minitest', '~> 0.11.0', require: false # For lint
|
13
11
|
gem 'rubocop-performance', '~> 1.10.1', require: false # For lint
|
14
12
|
gem 'rubocop-rake', '>= 0.5.1', require: false # For lint
|
15
13
|
gem 'rubocop-sensible', '~> 0.3.0', require: false # For lint
|
16
|
-
gem '
|
14
|
+
gem 'simplecov', '~> 0.21.0', require: false # For test coverage
|
15
|
+
gem 'simplecov-cobertura', require: false # For test coverage
|
17
16
|
gem 'yard', require: false
|
17
|
+
|
18
|
+
platforms :ruby do
|
19
|
+
gem 'oj', '~> 3.11', require: false # For backend
|
20
|
+
gem 'ruby-prof', require: false # For performance profiling
|
21
|
+
end
|
data/README.md
CHANGED
@@ -1,28 +1,38 @@
|
|
1
1
|
[![Gem Version](https://badge.fury.io/rb/alba.svg)](https://badge.fury.io/rb/alba)
|
2
|
-
[![
|
3
|
-
[![
|
2
|
+
[![CI](https://github.com/okuramasafumi/alba/actions/workflows/main.yml/badge.svg)](https://github.com/okuramasafumi/alba/actions/workflows/main.yml)
|
3
|
+
[![codecov](https://codecov.io/gh/okuramasafumi/alba/branch/master/graph/badge.svg?token=3D3HEZ5OXT)](https://codecov.io/gh/okuramasafumi/alba)
|
4
4
|
[![Maintainability](https://api.codeclimate.com/v1/badges/fdab4cc0de0b9addcfe8/maintainability)](https://codeclimate.com/github/okuramasafumi/alba/maintainability)
|
5
5
|
![GitHub code size in bytes](https://img.shields.io/github/languages/code-size/okuramasafumi/alba)
|
6
6
|
![GitHub](https://img.shields.io/github/license/okuramasafumi/alba)
|
7
7
|
|
8
8
|
# Alba
|
9
9
|
|
10
|
-
`Alba` is the fastest JSON serializer for Ruby.
|
10
|
+
`Alba` is the fastest JSON serializer for Ruby, JRuby an TruffleRuby.
|
11
11
|
|
12
|
-
##
|
12
|
+
## Discussions
|
13
13
|
|
14
|
-
|
14
|
+
Alba uses [GitHub Discussions](https://github.com/okuramasafumi/alba/discussions) to openly discuss the project.
|
15
15
|
|
16
|
-
Alba
|
16
|
+
If you've already used Alba, please consider posting your thoughts and feelings on [Feedback](https://github.com/okuramasafumi/alba/discussions/categories/feedback). The fact that you enjoy using Alba gives me energy to keep developing Alba!
|
17
17
|
|
18
|
-
|
18
|
+
If you have feature requests or interesting ideas, join us with [Ideas](https://github.com/okuramasafumi/alba/discussions/categories/ideas). Let's make Alba even better, together!
|
19
19
|
|
20
|
-
|
20
|
+
## Why Alba?
|
21
21
|
|
22
|
-
|
22
|
+
Because it's fast, flexible and well-maintained!
|
23
|
+
|
24
|
+
### Fast
|
23
25
|
|
24
26
|
Alba is faster than most of the alternatives. We have a [benchmark](https://github.com/okuramasafumi/alba/tree/master/benchmark).
|
25
27
|
|
28
|
+
### Flexible
|
29
|
+
|
30
|
+
Alba provides a small set of DSL to define your serialization logic. It also provides methods you can override to alter and filter serialized hash so that you have full control over the result.
|
31
|
+
|
32
|
+
### Maintained
|
33
|
+
|
34
|
+
Alba is well-maintained and adds features quickly. [Coverage Status](https://coveralls.io/github/okuramasafumi/alba?branch=master) and [CodeClimate Maintainability](https://codeclimate.com/github/okuramasafumi/alba/maintainability) show the code base is quite healthy.
|
35
|
+
|
26
36
|
## Installation
|
27
37
|
|
28
38
|
Add this line to your application's Gemfile:
|
@@ -41,7 +51,7 @@ Or install it yourself as:
|
|
41
51
|
|
42
52
|
## Supported Ruby versions
|
43
53
|
|
44
|
-
Alba supports CRuby 2.5
|
54
|
+
Alba supports CRuby 2.5 and higher and latest JRuby and TruffleRuby.
|
45
55
|
|
46
56
|
## Documentation
|
47
57
|
|
@@ -440,6 +450,10 @@ Alba.on_error do |error, object, key, attribute, resource_class|
|
|
440
450
|
end
|
441
451
|
```
|
442
452
|
|
453
|
+
### Caching
|
454
|
+
|
455
|
+
Currently, Alba doesn't support caching, primarily due to the behavior of `ActiveRecord::Relation`'s cache. See [the issue](https://github.com/rails/rails/issues/41784).
|
456
|
+
|
443
457
|
## Comparison
|
444
458
|
|
445
459
|
Alba is faster than alternatives.
|
@@ -457,6 +471,13 @@ Alba.backend = :active_support
|
|
457
471
|
|
458
472
|
The name "Alba" comes from "albatross", a kind of birds. In Japanese, this bird is called "Aho-dori", which means "stupid bird". I find it funny because in fact albatrosses fly really fast. I hope Alba looks stupid but in fact it does its job quick.
|
459
473
|
|
474
|
+
## Pioneers
|
475
|
+
|
476
|
+
There are great pioneers in Ruby's ecosystem which does basically the same thing as Alba does. To name a few:
|
477
|
+
|
478
|
+
* [ActiveModelSerializers](https://github.com/rails-api/active_model_serializers) a.k.a AMS, the most famous implementation of JSON serializer for Ruby
|
479
|
+
* [Blueprinter](https://github.com/procore/blueprinter) shares some concepts with Alba
|
480
|
+
|
460
481
|
## Development
|
461
482
|
|
462
483
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
data/Rakefile
CHANGED
@@ -1,10 +1,13 @@
|
|
1
1
|
require "bundler/gem_tasks"
|
2
2
|
require "rake/testtask"
|
3
3
|
|
4
|
+
ENV["BUNDLE_GEMFILE"] = File.expand_path("gemfiles/all.gemfile") if ENV["BUNDLE_GEMFILE"] == File.expand_path("Gemfile") || ENV["BUNDLE_GEMFILE"].empty? || ENV["BUNDLE_GEMFILE"].nil?
|
5
|
+
|
4
6
|
Rake::TestTask.new(:test) do |t|
|
5
7
|
t.libs << "test"
|
6
8
|
t.libs << "lib"
|
7
|
-
|
9
|
+
file_list = ENV["BUNDLE_GEMFILE"] == File.expand_path("gemfiles/all.gemfile") ? FileList["test/**/*_test.rb"] : FileList["test/dependencies/test_dependencies.rb"]
|
10
|
+
t.test_files = file_list
|
8
11
|
end
|
9
12
|
|
10
13
|
task :default => :test
|
data/alba.gemspec
CHANGED
@@ -10,11 +10,11 @@ Gem::Specification.new do |spec|
|
|
10
10
|
spec.description = "Alba is designed to be a simple, easy to use and fast alternative to existing JSON serializers. Its performance is better than almost all gems which do similar things. The internal is so simple that it's easy to hack and maintain."
|
11
11
|
spec.homepage = 'https://github.com/okuramasafumi/alba'
|
12
12
|
spec.license = 'MIT'
|
13
|
-
spec.required_ruby_version = Gem::Requirement.new('>= 2.5.
|
13
|
+
spec.required_ruby_version = Gem::Requirement.new('>= 2.5.0')
|
14
14
|
|
15
15
|
spec.metadata['homepage_uri'] = spec.homepage
|
16
16
|
spec.metadata['source_code_uri'] = 'https://github.com/okuramasafumi/alba'
|
17
|
-
spec.metadata['changelog_uri'] = 'https://github.com/okuramasafumi/alba/CHANGELOG.md'
|
17
|
+
spec.metadata['changelog_uri'] = 'https://github.com/okuramasafumi/alba/blob/master/CHANGELOG.md'
|
18
18
|
|
19
19
|
# Specify which files should be added to the gem when it is released.
|
20
20
|
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
@@ -0,0 +1,18 @@
|
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
|
3
|
+
gem 'activesupport', require: false # For backend
|
4
|
+
gem 'minitest', '~> 5.14' # For test
|
5
|
+
gem 'rake', '~> 13.0' # For test and automation
|
6
|
+
gem 'rubocop', '>= 0.79.0', require: false # For lint
|
7
|
+
gem 'rubocop-minitest', '~> 0.11.0', require: false # For lint
|
8
|
+
gem 'rubocop-performance', '~> 1.10.1', require: false # For lint
|
9
|
+
gem 'rubocop-rake', '>= 0.5.1', require: false # For lint
|
10
|
+
gem 'rubocop-sensible', '~> 0.3.0', require: false # For lint
|
11
|
+
gem 'simplecov', '~> 0.21.0', require: false # For test coverage
|
12
|
+
gem 'simplecov-cobertura', require: false # For test coverage
|
13
|
+
gem 'yard', require: false
|
14
|
+
|
15
|
+
platforms :ruby do
|
16
|
+
gem 'oj', '~> 3.11', require: false # For backend
|
17
|
+
gem 'ruby-prof', require: false # For performance profiling
|
18
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
|
3
|
+
gem 'minitest', '~> 5.14' # For test
|
4
|
+
gem 'rake', '~> 13.0' # For test and automation
|
5
|
+
gem 'rubocop', '>= 0.79.0', require: false # For lint
|
6
|
+
gem 'rubocop-minitest', '~> 0.11.0', require: false # For lint
|
7
|
+
gem 'rubocop-performance', '~> 1.10.1', require: false # For lint
|
8
|
+
gem 'rubocop-rake', '>= 0.5.1', require: false # For lint
|
9
|
+
gem 'rubocop-sensible', '~> 0.3.0', require: false # For lint
|
10
|
+
gem 'simplecov', '~> 0.21.0', require: false # For test coverage
|
11
|
+
gem 'simplecov-cobertura', require: false # For test coverage
|
12
|
+
gem 'yard', require: false
|
13
|
+
|
14
|
+
platforms :ruby do
|
15
|
+
gem 'oj', '~> 3.11', require: false # For backend
|
16
|
+
gem 'ruby-prof', require: false # For performance profiling
|
17
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
|
3
|
+
gem 'activesupport', require: false # For backend
|
4
|
+
gem 'minitest', '~> 5.14' # For test
|
5
|
+
gem 'rake', '~> 13.0' # For test and automation
|
6
|
+
gem 'rubocop', '>= 0.79.0', require: false # For lint
|
7
|
+
gem 'rubocop-minitest', '~> 0.11.0', require: false # For lint
|
8
|
+
gem 'rubocop-performance', '~> 1.10.1', require: false # For lint
|
9
|
+
gem 'rubocop-rake', '>= 0.5.1', require: false # For lint
|
10
|
+
gem 'rubocop-sensible', '~> 0.3.0', require: false # For lint
|
11
|
+
gem 'simplecov', '~> 0.21.0', require: false # For test coverage
|
12
|
+
gem 'simplecov-cobertura', require: false # For test coverage
|
13
|
+
gem 'yard', require: false
|
14
|
+
|
15
|
+
platforms :ruby do
|
16
|
+
gem 'ruby-prof', require: false # For performance profiling
|
17
|
+
end
|
data/lib/alba.rb
CHANGED
@@ -33,8 +33,10 @@ module Alba
|
|
33
33
|
def serialize(object, key: nil, &block)
|
34
34
|
raise ArgumentError, 'Block required' unless block
|
35
35
|
|
36
|
-
|
37
|
-
|
36
|
+
klass = Class.new
|
37
|
+
klass.include(Alba::Resource)
|
38
|
+
klass.class_eval(&block)
|
39
|
+
resource = klass.new(object)
|
38
40
|
resource.serialize(key: key)
|
39
41
|
end
|
40
42
|
|
@@ -61,7 +63,6 @@ module Alba
|
|
61
63
|
raise ArgumentError, 'You cannot specify error handler with both Symbol and block' if handler && block
|
62
64
|
raise ArgumentError, 'You must specify error handler with either Symbol or block' unless handler || block
|
63
65
|
|
64
|
-
p block if block
|
65
66
|
@_on_error = handler || block
|
66
67
|
end
|
67
68
|
|
@@ -84,6 +85,7 @@ module Alba
|
|
84
85
|
require 'oj'
|
85
86
|
->(hash) { Oj.dump(hash, mode: :strict) }
|
86
87
|
rescue LoadError
|
88
|
+
Kernel.warn '`Oj` is not installed, falling back to default JSON encoder.'
|
87
89
|
default_encoder
|
88
90
|
end
|
89
91
|
|
@@ -91,6 +93,7 @@ module Alba
|
|
91
93
|
require 'active_support/json'
|
92
94
|
->(hash) { ActiveSupport::JSON.encode(hash) }
|
93
95
|
rescue LoadError
|
96
|
+
Kernel.warn '`ActiveSupport` is not installed, falling back to default JSON encoder.'
|
94
97
|
default_encoder
|
95
98
|
end
|
96
99
|
|
@@ -100,13 +103,6 @@ module Alba
|
|
100
103
|
JSON.dump(hash)
|
101
104
|
end
|
102
105
|
end
|
103
|
-
|
104
|
-
def resource_class
|
105
|
-
@resource_class ||= begin
|
106
|
-
klass = Class.new
|
107
|
-
klass.include(Alba::Resource)
|
108
|
-
end
|
109
|
-
end
|
110
106
|
end
|
111
107
|
|
112
108
|
@encoder = default_encoder
|
data/lib/alba/association.rb
CHANGED
data/lib/alba/key_transformer.rb
CHANGED
data/lib/alba/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: alba
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- OKURA Masafumi
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-04-
|
11
|
+
date: 2021-04-15 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Alba is designed to be a simple, easy to use and fast alternative to
|
14
14
|
existing JSON serializers. Its performance is better than almost all gems which
|
@@ -33,6 +33,9 @@ files:
|
|
33
33
|
- benchmark/local.rb
|
34
34
|
- bin/console
|
35
35
|
- bin/setup
|
36
|
+
- gemfiles/all.gemfile
|
37
|
+
- gemfiles/without_active_support.gemfile
|
38
|
+
- gemfiles/without_oj.gemfile
|
36
39
|
- lib/alba.rb
|
37
40
|
- lib/alba/association.rb
|
38
41
|
- lib/alba/key_transformer.rb
|
@@ -47,7 +50,7 @@ licenses:
|
|
47
50
|
metadata:
|
48
51
|
homepage_uri: https://github.com/okuramasafumi/alba
|
49
52
|
source_code_uri: https://github.com/okuramasafumi/alba
|
50
|
-
changelog_uri: https://github.com/okuramasafumi/alba/CHANGELOG.md
|
53
|
+
changelog_uri: https://github.com/okuramasafumi/alba/blob/master/CHANGELOG.md
|
51
54
|
post_install_message:
|
52
55
|
rdoc_options: []
|
53
56
|
require_paths:
|
@@ -56,7 +59,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
56
59
|
requirements:
|
57
60
|
- - ">="
|
58
61
|
- !ruby/object:Gem::Version
|
59
|
-
version: 2.5.
|
62
|
+
version: 2.5.0
|
60
63
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
61
64
|
requirements:
|
62
65
|
- - ">="
|