alba 1.5.0 → 2.0.0
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/.codeclimate.yml +11 -0
- data/.github/dependabot.yml +4 -18
- data/.github/workflows/codeql-analysis.yml +70 -0
- data/.github/workflows/main.yml +4 -4
- data/.github/workflows/perf.yml +2 -2
- data/.rubocop.yml +5 -1
- data/CHANGELOG.md +34 -0
- data/CONTRIBUTING.md +30 -0
- data/Gemfile +6 -2
- data/HACKING.md +41 -0
- data/README.md +599 -128
- data/Rakefile +2 -2
- data/alba.gemspec +8 -4
- data/benchmark/README.md +81 -0
- data/benchmark/collection.rb +60 -74
- data/benchmark/single_resource.rb +33 -2
- data/docs/migrate_from_jbuilder.md +18 -4
- data/docs/rails.md +44 -0
- data/lib/alba/association.rb +49 -9
- data/lib/alba/conditional_attribute.rb +54 -0
- data/lib/alba/default_inflector.rb +13 -24
- data/lib/alba/errors.rb +10 -0
- data/lib/alba/layout.rb +67 -0
- data/lib/alba/nested_attribute.rb +18 -0
- data/lib/alba/resource.rb +240 -156
- data/lib/alba/typed_attribute.rb +1 -1
- data/lib/alba/version.rb +1 -1
- data/lib/alba.rb +43 -58
- data/logo/alba-card.png +0 -0
- data/logo/alba-sign.png +0 -0
- data/logo/alba-typography.png +0 -0
- metadata +21 -11
- data/gemfiles/all.gemfile +0 -19
- data/lib/alba/key_transform_factory.rb +0 -33
- data/lib/alba/many.rb +0 -21
- data/lib/alba/one.rb +0 -21
- data/sider.yml +0 -60
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e445a59555f43f7c601699a3a2ceee967d33a37ea77f2b15a0e806dec0dfc5b8
|
4
|
+
data.tar.gz: 3506f93a8fd9c00c5d8d85566f41032f3bc23356c753d202ce48e9ba984f1acc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 46251245a639ad19d4c75d9b3afee2f9afdd19380ae70c1a1113ccc96966402bfff6434ac2fef9cdef4785873438d6ba828ee64712a8757dc497798fd890337a
|
7
|
+
data.tar.gz: ce096713947ae541071331d67212dc1fb35957dd7849b8d87b98ce6a8eda05b867406ec4ffad2d64eb76fcfe2a5d8be16486f2f4cd2c88e82c259b0e58b37887
|
data/.codeclimate.yml
ADDED
data/.github/dependabot.yml
CHANGED
@@ -1,26 +1,12 @@
|
|
1
1
|
version: 2
|
2
2
|
updates:
|
3
|
+
- package-ecosystem: github-actions
|
4
|
+
directory: "/"
|
5
|
+
schedule:
|
6
|
+
interval: daily
|
3
7
|
- package-ecosystem: bundler
|
4
8
|
directory: "/"
|
5
9
|
schedule:
|
6
10
|
interval: daily
|
7
11
|
time: "20:00"
|
8
12
|
open-pull-requests-limit: 10
|
9
|
-
ignore:
|
10
|
-
- dependency-name: rubocop
|
11
|
-
versions:
|
12
|
-
- 1.12.0
|
13
|
-
- 1.9.0
|
14
|
-
- dependency-name: rubocop-performance
|
15
|
-
versions:
|
16
|
-
- 1.10.0
|
17
|
-
- 1.10.2
|
18
|
-
- dependency-name: oj
|
19
|
-
versions:
|
20
|
-
- 3.11.3
|
21
|
-
- dependency-name: minitest
|
22
|
-
versions:
|
23
|
-
- 5.14.4
|
24
|
-
- dependency-name: activesupport
|
25
|
-
versions:
|
26
|
-
- 6.1.2
|
@@ -0,0 +1,70 @@
|
|
1
|
+
# For most projects, this workflow file will not need changing; you simply need
|
2
|
+
# to commit it to your repository.
|
3
|
+
#
|
4
|
+
# You may wish to alter this file to override the set of languages analyzed,
|
5
|
+
# or to provide custom queries or build logic.
|
6
|
+
#
|
7
|
+
# ******** NOTE ********
|
8
|
+
# We have attempted to detect the languages in your repository. Please check
|
9
|
+
# the `language` matrix defined below to confirm you have the correct set of
|
10
|
+
# supported CodeQL languages.
|
11
|
+
#
|
12
|
+
name: "CodeQL"
|
13
|
+
|
14
|
+
on:
|
15
|
+
push:
|
16
|
+
branches: [ main ]
|
17
|
+
pull_request:
|
18
|
+
# The branches below must be a subset of the branches above
|
19
|
+
branches: [ main ]
|
20
|
+
schedule:
|
21
|
+
- cron: '21 4 * * 5'
|
22
|
+
|
23
|
+
jobs:
|
24
|
+
analyze:
|
25
|
+
name: Analyze
|
26
|
+
runs-on: ubuntu-latest
|
27
|
+
permissions:
|
28
|
+
actions: read
|
29
|
+
contents: read
|
30
|
+
security-events: write
|
31
|
+
|
32
|
+
strategy:
|
33
|
+
fail-fast: false
|
34
|
+
matrix:
|
35
|
+
language: [ 'ruby' ]
|
36
|
+
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ]
|
37
|
+
# Learn more about CodeQL language support at https://git.io/codeql-language-support
|
38
|
+
|
39
|
+
steps:
|
40
|
+
- name: Checkout repository
|
41
|
+
uses: actions/checkout@v3
|
42
|
+
|
43
|
+
# Initializes the CodeQL tools for scanning.
|
44
|
+
- name: Initialize CodeQL
|
45
|
+
uses: github/codeql-action/init@v2
|
46
|
+
with:
|
47
|
+
languages: ${{ matrix.language }}
|
48
|
+
# If you wish to specify custom queries, you can do so here or in a config file.
|
49
|
+
# By default, queries listed here will override any specified in a config file.
|
50
|
+
# Prefix the list here with "+" to use these queries and those in the config file.
|
51
|
+
# queries: ./path/to/local/query, your-org/your-repo/queries@main
|
52
|
+
|
53
|
+
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
|
54
|
+
# If this step fails, then you should remove it and run the build manually (see below)
|
55
|
+
- name: Autobuild
|
56
|
+
uses: github/codeql-action/autobuild@v2
|
57
|
+
|
58
|
+
# ℹ️ Command-line programs to run using the OS shell.
|
59
|
+
# 📚 https://git.io/JvXDl
|
60
|
+
|
61
|
+
# ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
|
62
|
+
# and modify them (or add more) to build your code if your project
|
63
|
+
# uses a compiled language
|
64
|
+
|
65
|
+
#- run: |
|
66
|
+
# make bootstrap
|
67
|
+
# make release
|
68
|
+
|
69
|
+
- name: Perform CodeQL Analysis
|
70
|
+
uses: github/codeql-action/analyze@v2
|
data/.github/workflows/main.yml
CHANGED
@@ -8,7 +8,7 @@ jobs:
|
|
8
8
|
fail-fast: false
|
9
9
|
matrix:
|
10
10
|
os: [ubuntu-latest, windows-latest, macos-latest]
|
11
|
-
ruby: [2.
|
11
|
+
ruby: [2.6, 2.7, 3.0, 3.1, head, jruby, truffleruby]
|
12
12
|
gemfile: [all, without_active_support, without_oj]
|
13
13
|
exclude:
|
14
14
|
- os: windows-latest
|
@@ -17,9 +17,9 @@ jobs:
|
|
17
17
|
ruby: truffleruby
|
18
18
|
runs-on: ${{ matrix.os }}
|
19
19
|
env: # $BUNDLE_GEMFILE must be set at the job level, so it is set for all steps
|
20
|
-
BUNDLE_GEMFILE:
|
20
|
+
BUNDLE_GEMFILE: ${{ (matrix.gemfile == 'without_active_support' && 'gemfiles/without_active_support.gemfile') || (matrix.gemfile == 'without_oj' && 'gemfiles/without_oj.gemfile') || null }}
|
21
21
|
steps:
|
22
|
-
- uses: actions/checkout@
|
22
|
+
- uses: actions/checkout@v3
|
23
23
|
- name: Set up Ruby
|
24
24
|
uses: ruby/setup-ruby@v1
|
25
25
|
with:
|
@@ -29,6 +29,6 @@ jobs:
|
|
29
29
|
run: |
|
30
30
|
bundle exec rake
|
31
31
|
- name: CodeCov
|
32
|
-
uses: codecov/codecov-action@
|
32
|
+
uses: codecov/codecov-action@v3
|
33
33
|
with:
|
34
34
|
files: ./coverage/coverage.xml
|
data/.github/workflows/perf.yml
CHANGED
@@ -7,10 +7,10 @@ jobs:
|
|
7
7
|
strategy:
|
8
8
|
fail-fast: false
|
9
9
|
matrix:
|
10
|
-
ruby: [2.
|
10
|
+
ruby: [2.7, 3.0, 3.1]
|
11
11
|
runs-on: ubuntu-latest
|
12
12
|
steps:
|
13
|
-
- uses: actions/checkout@
|
13
|
+
- uses: actions/checkout@v3
|
14
14
|
- name: Set up Ruby
|
15
15
|
uses: ruby/setup-ruby@v1
|
16
16
|
with:
|
data/.rubocop.yml
CHANGED
@@ -16,7 +16,7 @@ AllCops:
|
|
16
16
|
- 'script/**/*.rb'
|
17
17
|
NewCops: enable
|
18
18
|
EnabledByDefault: true
|
19
|
-
TargetRubyVersion: 2.
|
19
|
+
TargetRubyVersion: 2.6
|
20
20
|
|
21
21
|
# Items in Gemfile is dev dependencies and we don't have to specify versions.
|
22
22
|
Bundler/GemVersion:
|
@@ -46,12 +46,15 @@ Metrics:
|
|
46
46
|
- 'test/**/*.rb'
|
47
47
|
|
48
48
|
# `Resource` module is a core module and its length tends to be long...
|
49
|
+
# `Alba` main module is also long because it has all parts of configuration
|
49
50
|
Metrics/ModuleLength:
|
50
51
|
Exclude:
|
51
52
|
- 'lib/alba/resource.rb'
|
53
|
+
- 'lib/alba.rb'
|
52
54
|
|
53
55
|
# Resource class includes DSLs, which tend to accept long list of parameters
|
54
56
|
Metrics/ParameterLists:
|
57
|
+
Max: 7
|
55
58
|
Exclude:
|
56
59
|
- 'test/**/*.rb'
|
57
60
|
|
@@ -63,6 +66,7 @@ Security/Eval:
|
|
63
66
|
Style/ConstantVisibility:
|
64
67
|
Exclude:
|
65
68
|
- 'lib/alba/version.rb'
|
69
|
+
- 'test/**/*.rb'
|
66
70
|
|
67
71
|
Style/Copyright:
|
68
72
|
Enabled: false
|
data/CHANGELOG.md
CHANGED
@@ -6,6 +6,40 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
6
6
|
|
7
7
|
## [Unreleased]
|
8
8
|
|
9
|
+
## [2.0.0] 2022-10-21
|
10
|
+
|
11
|
+
### Breaking changes
|
12
|
+
|
13
|
+
- All Hash-related methods now return String key instead of Symbol key
|
14
|
+
This affects all users, but you can use `deep_symbolize_keys` in Rails environment if you prefer Symbol keys
|
15
|
+
Some DSLs that take key argument such as `on_nil` and `on_error`, are also affected
|
16
|
+
|
17
|
+
### New features
|
18
|
+
|
19
|
+
- Passing an initial object to proc function in associations
|
20
|
+
- Allow association resource to be Proc
|
21
|
+
- `collection_key` to serialize collection into a Hash
|
22
|
+
- params is now overridable
|
23
|
+
- Key transformation now cascades
|
24
|
+
- nested attribute
|
25
|
+
- Implement `as_json`
|
26
|
+
|
27
|
+
### Bugfix
|
28
|
+
|
29
|
+
- fix the bug where nesting is empty string and invalid
|
30
|
+
- `handle_error` now raises the same error
|
31
|
+
- let Rails implicitly call `to_json`
|
32
|
+
|
33
|
+
## [1.6.0] 2022-03-16
|
34
|
+
|
35
|
+
- [Feat] Support instance method as an attribute
|
36
|
+
- [Fix] Explicitly raise error when inference is disabled
|
37
|
+
- [Improve] `enable_inference!` now takes inflector as argument
|
38
|
+
- [Improve] `transform_keys` now accepts `:snake` and `:none`
|
39
|
+
- [Deprecate] `to_hash` is special method and should not be used
|
40
|
+
- [Deprecate] `ignoring` in favor of `attributes` overriding
|
41
|
+
- [Deprecate] `Alba.on_nil`, `Alba.on_error` and `Alba.enable_root_key_transformation!`
|
42
|
+
|
9
43
|
## [1.5.0] 2021-11-28
|
10
44
|
|
11
45
|
- [Feat] Add nil handler
|
data/CONTRIBUTING.md
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# CONTRIBUTORS GUIDELINE
|
2
|
+
|
3
|
+
## Welcome
|
4
|
+
|
5
|
+
Welcome to Alba, and thank you for being interested in contributing to Alba. This document describes how to contribute to Alba.
|
6
|
+
|
7
|
+
## Code of Conduct
|
8
|
+
|
9
|
+
We have the [code of conduct](https://github.com/okuramasafumi/alba/blob/master/CODE_OF_CONDUCT.md) that all contributors are expected to adhere for Alba to be a safe and welcoming space.
|
10
|
+
|
11
|
+
## Bugs and Issues
|
12
|
+
|
13
|
+
If you find any bugs or issues, please submit an issue on [GitHub](https://github.com/okuramasafumi/alba/issues). Please follow the issue template as much as possible so that maintainers can find and fix it quickly.
|
14
|
+
|
15
|
+
## Feature Request
|
16
|
+
|
17
|
+
If you have any feature that you think Alba should have, please submit a feature request on [GitHub](https://github.com/okuramasafumi/alba/issues).
|
18
|
+
|
19
|
+
## Pull Request
|
20
|
+
|
21
|
+
You're more than welcomed to submit a Pull Request! You are expected to follow these rules before submitting:
|
22
|
+
|
23
|
+
* You must split your Pull Request into multiple ones if you solve more than one problem
|
24
|
+
* You must write tests if you implement a feature or fix a bug
|
25
|
+
* You should provide reason(s) behind your change unless it's so simple
|
26
|
+
|
27
|
+
## Documents
|
28
|
+
|
29
|
+
* [code of conduct](https://github.com/okuramasafumi/alba/blob/master/CODE_OF_CONDUCT.md) for all contributors
|
30
|
+
* [hacking document](https://github.com/okuramasafumi/alba/blob/master/DESIGN.md) for those who want to know the internal of Alba
|
data/Gemfile
CHANGED
@@ -4,17 +4,21 @@ source 'https://rubygems.org'
|
|
4
4
|
gemspec
|
5
5
|
|
6
6
|
gem 'activesupport', require: false # For backend
|
7
|
+
gem 'dry-inflector', require: false # For inflection
|
7
8
|
gem 'ffaker', require: false # For testing
|
8
9
|
gem 'inch', require: false # For inline documents
|
9
10
|
gem 'minitest', '~> 5.14' # For test
|
10
11
|
gem 'rake', '~> 13.0' # For test and automation
|
11
12
|
gem 'rubocop', '>= 0.79.0', require: false # For lint
|
12
|
-
gem 'rubocop-minitest', '~> 0.
|
13
|
-
gem 'rubocop-performance', '~> 1.
|
13
|
+
gem 'rubocop-minitest', '~> 0.22.0', require: false # For lint
|
14
|
+
gem 'rubocop-performance', '~> 1.15.0', require: false # For lint
|
14
15
|
gem 'rubocop-rake', '>= 0.5.1', require: false # For lint
|
15
16
|
gem 'rubocop-sensible', '~> 0.3.0', require: false # For lint
|
17
|
+
gem 'ruby-lsp', require: false # For language server
|
16
18
|
gem 'simplecov', '~> 0.21.0', require: false # For test coverage
|
17
19
|
gem 'simplecov-cobertura', require: false # For test coverage
|
20
|
+
# gem 'steep', require: false # For language server and typing
|
21
|
+
# gem 'typeprof', require: false # For language server and typing
|
18
22
|
gem 'yard', require: false # For documentation
|
19
23
|
|
20
24
|
platforms :ruby do
|
data/HACKING.md
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
# Hacking document
|
2
|
+
|
3
|
+
This document is intended to provide detailed information about the internal design and implementation of Alba. You are recommended to read through it if you want to hack Alba.
|
4
|
+
|
5
|
+
## Design
|
6
|
+
|
7
|
+
The design of Alba is simple. `Alba::Resource` module is the only interface end users use by `include`ing it. Other classes and modules are referenced by `Alba::Resource`.
|
8
|
+
|
9
|
+
When a class `include`s `Alba::Resource` module it defines `ClassMethods` such as `attributes` and `InstanceMethods` such as `serialize`. Instance methods work with information collected by class methods.
|
10
|
+
|
11
|
+
## Methods
|
12
|
+
|
13
|
+
The main methods users directly use are listed below.
|
14
|
+
|
15
|
+
Class methods (DSL):
|
16
|
+
|
17
|
+
* `attribute` for block style attribute
|
18
|
+
* `attributes` for symbol style attribute
|
19
|
+
* `association` and its aliases such as `one` for association
|
20
|
+
|
21
|
+
Instance methods:
|
22
|
+
|
23
|
+
* `serializable_hash` and `to_h` for hash from target object
|
24
|
+
* `serialize` and `to_json` for serialized JSON string
|
25
|
+
|
26
|
+
Other methods are rather trivial. They'll be added to this list when it turned out it's important enough.
|
27
|
+
|
28
|
+
## Implementation
|
29
|
+
|
30
|
+
In `Alba::Resource` module there are some things to note.
|
31
|
+
|
32
|
+
`@object` is an object for serialization. It's either singular object or collection.
|
33
|
+
|
34
|
+
Attribute object can be either `Symbol`, `Proc`, `Alba::Association` or `Alba::TypedAttribute`.
|
35
|
+
|
36
|
+
* `Symbol` attributes come from `attributes` method and are sent to `__send__` as method name
|
37
|
+
* `Proc` attributes come from `attribute` method and are `instance_exec`uted
|
38
|
+
* `Alba::Association` attributes come from `association` method and `to_h` method on the object is called
|
39
|
+
* `Alba::TypedAttribute` attributes come when users specify `type` option and `value` method on the object is called
|
40
|
+
|
41
|
+
When users provide `if` option, the attribute object becomes an `Array`. It contains two element, attribute itself and condition.
|