alba 1.6.0 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c7ab62feaab9747cd1441aea57b8d8f7f1d149261d86e4e64e9f859ae8f1091c
4
- data.tar.gz: 4442a77416ee235ad6537580ec0600c4b1c9b0bea7b154b3a96010514316531d
3
+ metadata.gz: e445a59555f43f7c601699a3a2ceee967d33a37ea77f2b15a0e806dec0dfc5b8
4
+ data.tar.gz: 3506f93a8fd9c00c5d8d85566f41032f3bc23356c753d202ce48e9ba984f1acc
5
5
  SHA512:
6
- metadata.gz: 373f00c4b2bf57f18d65d86a9c8209f9d0c94038f44a98df8e7c7768158d23e03f427729006eb113f0e88fde17a829364cf561026858c83bbb861a7d7eefba13
7
- data.tar.gz: ad75036a0f554d13637d32413906f17166347459f2e3bcd3e1fe55f4ddc5d805da59ece5c1e46babadea434d667927aab4e3b7f6b0d37887ee6f58cae10396c9
6
+ metadata.gz: 46251245a639ad19d4c75d9b3afee2f9afdd19380ae70c1a1113ccc96966402bfff6434ac2fef9cdef4785873438d6ba828ee64712a8757dc497798fd890337a
7
+ data.tar.gz: ce096713947ae541071331d67212dc1fb35957dd7849b8d87b98ce6a8eda05b867406ec4ffad2d64eb76fcfe2a5d8be16486f2f4cd2c88e82c259b0e58b37887
data/.codeclimate.yml ADDED
@@ -0,0 +1,11 @@
1
+ version: "2" # required to adjust maintainability checks
2
+
3
+ checks:
4
+ method-complexity:
5
+ enabled: true
6
+ config:
7
+ threshold: 7
8
+
9
+ exclude_patterns:
10
+ - "benchmark/**/*"
11
+ - "script/**/*"
@@ -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
@@ -38,11 +38,11 @@ jobs:
38
38
 
39
39
  steps:
40
40
  - name: Checkout repository
41
- uses: actions/checkout@v2
41
+ uses: actions/checkout@v3
42
42
 
43
43
  # Initializes the CodeQL tools for scanning.
44
44
  - name: Initialize CodeQL
45
- uses: github/codeql-action/init@v1
45
+ uses: github/codeql-action/init@v2
46
46
  with:
47
47
  languages: ${{ matrix.language }}
48
48
  # If you wish to specify custom queries, you can do so here or in a config file.
@@ -53,7 +53,7 @@ jobs:
53
53
  # Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
54
54
  # If this step fails, then you should remove it and run the build manually (see below)
55
55
  - name: Autobuild
56
- uses: github/codeql-action/autobuild@v1
56
+ uses: github/codeql-action/autobuild@v2
57
57
 
58
58
  # ℹ️ Command-line programs to run using the OS shell.
59
59
  # 📚 https://git.io/JvXDl
@@ -67,4 +67,4 @@ jobs:
67
67
  # make release
68
68
 
69
69
  - name: Perform CodeQL Analysis
70
- uses: github/codeql-action/analyze@v1
70
+ uses: github/codeql-action/analyze@v2
@@ -8,20 +8,18 @@ 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, 3.1, head, jruby, truffleruby]
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
- - os: windows-latest
15
- ruby: 3.1
16
14
  - os: windows-latest
17
15
  ruby: jruby
18
16
  - os: windows-latest
19
17
  ruby: truffleruby
20
18
  runs-on: ${{ matrix.os }}
21
19
  env: # $BUNDLE_GEMFILE must be set at the job level, so it is set for all steps
22
- BUNDLE_GEMFILE: gemfiles/${{ matrix.gemfile }}.gemfile
20
+ BUNDLE_GEMFILE: ${{ (matrix.gemfile == 'without_active_support' && 'gemfiles/without_active_support.gemfile') || (matrix.gemfile == 'without_oj' && 'gemfiles/without_oj.gemfile') || null }}
23
21
  steps:
24
- - uses: actions/checkout@v2
22
+ - uses: actions/checkout@v3
25
23
  - name: Set up Ruby
26
24
  uses: ruby/setup-ruby@v1
27
25
  with:
@@ -31,6 +29,6 @@ jobs:
31
29
  run: |
32
30
  bundle exec rake
33
31
  - name: CodeCov
34
- uses: codecov/codecov-action@v1
32
+ uses: codecov/codecov-action@v3
35
33
  with:
36
34
  files: ./coverage/coverage.xml
@@ -7,10 +7,10 @@ jobs:
7
7
  strategy:
8
8
  fail-fast: false
9
9
  matrix:
10
- ruby: [2.5, 2.6, 2.7, 3.0]
10
+ ruby: [2.7, 3.0, 3.1]
11
11
  runs-on: ubuntu-latest
12
12
  steps:
13
- - uses: actions/checkout@v2
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.5
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:
@@ -54,6 +54,7 @@ Metrics/ModuleLength:
54
54
 
55
55
  # Resource class includes DSLs, which tend to accept long list of parameters
56
56
  Metrics/ParameterLists:
57
+ Max: 7
57
58
  Exclude:
58
59
  - 'test/**/*.rb'
59
60
 
@@ -65,6 +66,7 @@ Security/Eval:
65
66
  Style/ConstantVisibility:
66
67
  Exclude:
67
68
  - 'lib/alba/version.rb'
69
+ - 'test/**/*.rb'
68
70
 
69
71
  Style/Copyright:
70
72
  Enabled: false
data/CHANGELOG.md CHANGED
@@ -6,6 +6,30 @@ 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
+
9
33
  ## [1.6.0] 2022-03-16
10
34
 
11
35
  - [Feat] Support instance method as an attribute
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.18.0', require: false # For lint
13
- gem 'rubocop-performance', '~> 1.13.0', require: false # For lint
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.