dry-initializer 2.3.0 → 3.0.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 +5 -5
- data/.codeclimate.yml +10 -21
- data/.github/ISSUE_TEMPLATE/----please-don-t-ask-for-support-via-issues.md +10 -0
- data/.github/ISSUE_TEMPLATE/---bug-report.md +34 -0
- data/.github/ISSUE_TEMPLATE/---feature-request.md +18 -0
- data/.github/workflows/custom_ci.yml +74 -0
- data/.github/workflows/docsite.yml +34 -0
- data/.github/workflows/sync_configs.yml +34 -0
- data/.gitignore +2 -0
- data/.rspec +2 -2
- data/.rubocop.yml +65 -27
- data/CHANGELOG.md +160 -13
- data/CODE_OF_CONDUCT.md +13 -0
- data/CONTRIBUTING.md +29 -0
- data/Gemfile +26 -17
- data/LICENSE +20 -0
- data/README.md +13 -15
- data/docsite/source/attributes.html.md +106 -0
- data/docsite/source/container-version.html.md +39 -0
- data/docsite/source/index.html.md +43 -0
- data/docsite/source/inheritance.html.md +43 -0
- data/docsite/source/optionals-and-defaults.html.md +130 -0
- data/docsite/source/options-tolerance.html.md +27 -0
- data/docsite/source/params-and-options.html.md +74 -0
- data/docsite/source/rails-support.html.md +101 -0
- data/docsite/source/readers.html.md +43 -0
- data/docsite/source/skip-undefined.html.md +59 -0
- data/docsite/source/type-constraints.html.md +160 -0
- data/dry-initializer.gemspec +3 -3
- data/lib/dry/initializer.rb +11 -9
- data/lib/dry/initializer/builders/attribute.rb +4 -4
- data/lib/dry/initializer/builders/reader.rb +1 -1
- data/lib/dry/initializer/config.rb +22 -11
- data/lib/dry/initializer/definition.rb +11 -62
- data/lib/dry/initializer/dispatchers.rb +112 -0
- data/lib/dry/initializer/dispatchers/build_nested_type.rb +59 -0
- data/lib/dry/initializer/dispatchers/check_type.rb +43 -0
- data/lib/dry/initializer/dispatchers/prepare_default.rb +40 -0
- data/lib/dry/initializer/dispatchers/prepare_ivar.rb +12 -0
- data/lib/dry/initializer/dispatchers/prepare_optional.rb +13 -0
- data/lib/dry/initializer/dispatchers/prepare_reader.rb +30 -0
- data/lib/dry/initializer/dispatchers/prepare_source.rb +28 -0
- data/lib/dry/initializer/dispatchers/prepare_target.rb +44 -0
- data/lib/dry/initializer/dispatchers/unwrap_type.rb +22 -0
- data/lib/dry/initializer/dispatchers/wrap_type.rb +27 -0
- data/lib/dry/initializer/mixin/root.rb +1 -0
- data/lib/dry/initializer/struct.rb +39 -0
- data/lib/dry/initializer/undefined.rb +2 -0
- data/spec/coercion_of_nil_spec.rb +25 -0
- data/spec/custom_dispatchers_spec.rb +35 -0
- data/spec/definition_spec.rb +6 -2
- data/spec/list_type_spec.rb +32 -0
- data/spec/nested_type_spec.rb +48 -0
- data/spec/spec_helper.rb +9 -1
- data/spec/type_argument_spec.rb +2 -2
- data/spec/type_constraint_spec.rb +6 -6
- data/spec/value_coercion_via_dry_types_spec.rb +1 -1
- metadata +48 -9
- data/.travis.yml +0 -24
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: f5d079daa17830b65177c99533e1b7f280bb4aee14dbcba097ba8c40de273abd
|
4
|
+
data.tar.gz: a59b00abe9c741b764152a6213ff40c29adbdf27094ecebbaaf766b2e056aa99
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4fee1158d5ddd7bfca050f61788ee7012bf0a0f424239095ea649c6dd34ba47b157627efe7261f9e5fdaef405654b589addd26990a912b72cd0f76e339003754
|
7
|
+
data.tar.gz: 64a5e73606be0a238d0dba9173d32f90d8366d0aae64edf378dd851705a07d4ede0906ed241cc85ff9cb9b5c5f3fe9734bfb77d53fb6fc71bf29565b8607c388
|
data/.codeclimate.yml
CHANGED
@@ -1,23 +1,12 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
# this file is managed by dry-rb/devtools project
|
2
|
+
|
3
|
+
version: "2"
|
4
|
+
|
5
|
+
exclude_patterns:
|
6
|
+
- "benchmarks/"
|
7
|
+
- "examples/"
|
8
|
+
- "spec/"
|
9
|
+
|
10
|
+
plugins:
|
3
11
|
rubocop:
|
4
12
|
enabled: true
|
5
|
-
checks:
|
6
|
-
Rubocop/Style/FrozenStringLiteralComment:
|
7
|
-
enabled: false
|
8
|
-
Rubocop/Style/PercentLiteralDelimiters:
|
9
|
-
enabled: false
|
10
|
-
Rubocop/Lint/UnderscorePrefixedVariableName:
|
11
|
-
enabled: false
|
12
|
-
duplication:
|
13
|
-
enabled: true
|
14
|
-
config:
|
15
|
-
languages:
|
16
|
-
- ruby
|
17
|
-
exclude_paths:
|
18
|
-
- "benchmarks/**/*"
|
19
|
-
- "spec/**/*"
|
20
|
-
- "lib/tasks/**/*"
|
21
|
-
ratings:
|
22
|
-
paths:
|
23
|
-
- "lib/**/*"
|
@@ -0,0 +1,34 @@
|
|
1
|
+
---
|
2
|
+
name: "\U0001F41B Bug report"
|
3
|
+
about: See CONTRIBUTING.md for more information
|
4
|
+
title: ''
|
5
|
+
labels: bug
|
6
|
+
assignees: ''
|
7
|
+
|
8
|
+
---
|
9
|
+
|
10
|
+
**Before you submit this: WE ONLY ACCEPT BUG REPORTS AND FEATURE REQUESTS**
|
11
|
+
|
12
|
+
For more information see [our contribution guidelines](https://github.com/rom-rb/rom/blob/master/CONTRIBUTING.md)
|
13
|
+
|
14
|
+
**Before you report**
|
15
|
+
|
16
|
+
:warning: If you have a problem related to a schema, please **report it under [dry-schema issues](https://github.com/dry-rb/dry-schema/issues/new?assignees=&labels=bug&template=---bug-report.md&title=)** instead.
|
17
|
+
|
18
|
+
**Describe the bug**
|
19
|
+
|
20
|
+
A clear and concise description of what the bug is.
|
21
|
+
|
22
|
+
**To Reproduce**
|
23
|
+
|
24
|
+
Provide detailed steps to reproduce, an executable script would be best.
|
25
|
+
|
26
|
+
**Expected behavior**
|
27
|
+
|
28
|
+
A clear and concise description of what you expected to happen.
|
29
|
+
|
30
|
+
**Your environment**
|
31
|
+
|
32
|
+
- Affects my production application: **YES/NO**
|
33
|
+
- Ruby version: ...
|
34
|
+
- OS: ...
|
@@ -0,0 +1,18 @@
|
|
1
|
+
---
|
2
|
+
name: "\U0001F6E0 Feature request"
|
3
|
+
about: See CONTRIBUTING.md for more information
|
4
|
+
title: ''
|
5
|
+
labels: feature
|
6
|
+
assignees: ''
|
7
|
+
|
8
|
+
---
|
9
|
+
|
10
|
+
Summary of what the feature is supposed to do.
|
11
|
+
|
12
|
+
## Examples
|
13
|
+
|
14
|
+
Code examples showing how the feature could be used.
|
15
|
+
|
16
|
+
## Resources
|
17
|
+
|
18
|
+
Additional information, like a link to the discussion forum thread where the feature was discussed etc.
|
@@ -0,0 +1,74 @@
|
|
1
|
+
name: ci
|
2
|
+
|
3
|
+
on:
|
4
|
+
push:
|
5
|
+
paths:
|
6
|
+
- .github/workflows/custom_ci.yml
|
7
|
+
- lib/**
|
8
|
+
- spec/**
|
9
|
+
- Gemfile
|
10
|
+
- "*.gemspec"
|
11
|
+
|
12
|
+
jobs:
|
13
|
+
tests-mri:
|
14
|
+
runs-on: ubuntu-latest
|
15
|
+
strategy:
|
16
|
+
fail-fast: false
|
17
|
+
matrix:
|
18
|
+
ruby: ["2.6.x", "2.5.x", "2.4.x", "2.3.x"]
|
19
|
+
include:
|
20
|
+
- ruby: "2.6.x"
|
21
|
+
coverage: "true"
|
22
|
+
steps:
|
23
|
+
- uses: actions/checkout@v1
|
24
|
+
- name: Set up Ruby
|
25
|
+
uses: actions/setup-ruby@v1
|
26
|
+
with:
|
27
|
+
ruby-version: ${{matrix.ruby}}
|
28
|
+
- name: Download test reporter
|
29
|
+
if: "matrix.coverage == 'true'"
|
30
|
+
run: |
|
31
|
+
mkdir -p tmp/
|
32
|
+
curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./tmp/cc-test-reporter
|
33
|
+
chmod +x ./tmp/cc-test-reporter
|
34
|
+
./tmp/cc-test-reporter before-build
|
35
|
+
- name: Run all tests
|
36
|
+
env:
|
37
|
+
CI: "true"
|
38
|
+
COVERAGE: ${{matrix.coverage}}
|
39
|
+
run: |
|
40
|
+
gem install bundler
|
41
|
+
bundle config set without 'tools docs benchmarks'
|
42
|
+
bundle install --jobs 4 --retry 3
|
43
|
+
bundle exec rake
|
44
|
+
- name: Send coverage results
|
45
|
+
if: "matrix.coverage == 'true'"
|
46
|
+
env:
|
47
|
+
CC_TEST_REPORTER_ID: ${{secrets.CC_TEST_REPORTER_ID}}
|
48
|
+
GIT_COMMIT_SHA: ${{github.sha}}
|
49
|
+
GIT_BRANCH: ${{github.ref}}
|
50
|
+
GIT_COMMITTED_AT: ${{github.event.head_commit.timestamp}}
|
51
|
+
run: |
|
52
|
+
GIT_BRANCH=`ruby -e "puts ENV['GITHUB_REF'].split('/', 3).last"` \
|
53
|
+
GIT_COMMITTED_AT=`ruby -r time -e "puts Time.iso8601(ENV['GIT_COMMITTED_AT']).to_i"` \
|
54
|
+
./tmp/cc-test-reporter after-build
|
55
|
+
|
56
|
+
tests-others:
|
57
|
+
runs-on: ubuntu-latest
|
58
|
+
strategy:
|
59
|
+
fail-fast: false
|
60
|
+
matrix:
|
61
|
+
image: ["jruby:9.2.8", "ruby:rc"]
|
62
|
+
container:
|
63
|
+
image: ${{matrix.image}}
|
64
|
+
steps:
|
65
|
+
- uses: actions/checkout@v1
|
66
|
+
- name: Install git
|
67
|
+
run: |
|
68
|
+
apt-get update
|
69
|
+
apt-get install -y --no-install-recommends git
|
70
|
+
- name: Run all tests
|
71
|
+
run: |
|
72
|
+
gem install bundler
|
73
|
+
bundle install --jobs 4 --retry 3 --without tools docs benchmarks
|
74
|
+
bundle exec rspec
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# this file is managed by dry-rb/devtools project
|
2
|
+
|
3
|
+
name: docsite
|
4
|
+
|
5
|
+
on:
|
6
|
+
push:
|
7
|
+
paths:
|
8
|
+
- docsite/**
|
9
|
+
- .github/workflows/docsite.yml
|
10
|
+
branches:
|
11
|
+
- master
|
12
|
+
- release-**
|
13
|
+
tags:
|
14
|
+
|
15
|
+
jobs:
|
16
|
+
update-docs:
|
17
|
+
runs-on: ubuntu-latest
|
18
|
+
steps:
|
19
|
+
- uses: actions/checkout@v1
|
20
|
+
- name: Set up Ruby
|
21
|
+
uses: actions/setup-ruby@v1
|
22
|
+
with:
|
23
|
+
ruby-version: "2.6.x"
|
24
|
+
- name: Install dependencies
|
25
|
+
run: |
|
26
|
+
gem install bundler
|
27
|
+
bundle install --jobs 4 --retry 3 --without benchmarks sql
|
28
|
+
- name: Symlink ossy
|
29
|
+
run: mkdir -p bin && ln -sf "$(bundle show ossy)/bin/ossy" bin/ossy
|
30
|
+
- name: Trigger dry-rb.org deploy
|
31
|
+
env:
|
32
|
+
GITHUB_LOGIN: dry-bot
|
33
|
+
GITHUB_TOKEN: ${{ secrets.GH_PAT }}
|
34
|
+
run: bin/ossy github workflow dry-rb/dry-rb.org ci
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# this file is managed by dry-rb/devtools project
|
2
|
+
|
3
|
+
name: sync_configs
|
4
|
+
|
5
|
+
on:
|
6
|
+
repository_dispatch:
|
7
|
+
|
8
|
+
jobs:
|
9
|
+
sync-configs:
|
10
|
+
runs-on: ubuntu-latest
|
11
|
+
if: github.event.action == 'sync_configs'
|
12
|
+
steps:
|
13
|
+
- uses: actions/checkout@v1
|
14
|
+
- name: Update configuration files from devtools
|
15
|
+
env:
|
16
|
+
GITHUB_LOGIN: dry-bot
|
17
|
+
GITHUB_TOKEN: ${{ secrets.GH_PAT }}
|
18
|
+
run: |
|
19
|
+
git clone https://github.com/dry-rb/devtools.git tmp/devtools
|
20
|
+
|
21
|
+
if [ -f ".github/workflows/custom_ci.yml" ]; then
|
22
|
+
rsync -av --exclude '.github/workflows/ci.yml' tmp/devtools/shared/ . ;
|
23
|
+
else
|
24
|
+
rsync -av tmp/devtools/shared/ . ;
|
25
|
+
fi
|
26
|
+
|
27
|
+
git config --local user.email "dry-bot@dry-rb.org"
|
28
|
+
git config --local user.name "dry-bot"
|
29
|
+
git add -A
|
30
|
+
git commit -m "[devtools] config sync" || echo "nothing changed"
|
31
|
+
- name: Push changes
|
32
|
+
uses: ad-m/github-push-action@master
|
33
|
+
with:
|
34
|
+
github_token: ${{ secrets.GH_PAT }}
|
data/.rspec
CHANGED
data/.rubocop.yml
CHANGED
@@ -1,51 +1,89 @@
|
|
1
|
-
|
1
|
+
# this file is managed by dry-rb/devtools project
|
2
|
+
|
2
3
|
AllCops:
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
Exclude:
|
8
|
-
- lib/tasks/*.rake
|
4
|
+
TargetRubyVersion: 2.4
|
5
|
+
|
6
|
+
Style/EachWithObject:
|
7
|
+
Enabled: false
|
9
8
|
|
10
|
-
|
9
|
+
Style/StringLiterals:
|
10
|
+
Enabled: true
|
11
|
+
EnforcedStyle: single_quotes
|
12
|
+
|
13
|
+
Style/Alias:
|
11
14
|
Enabled: false
|
12
15
|
|
13
|
-
Style/
|
16
|
+
Style/LambdaCall:
|
14
17
|
Enabled: false
|
15
18
|
|
16
|
-
Style/
|
19
|
+
Style/StabbyLambdaParentheses:
|
17
20
|
Enabled: false
|
18
21
|
|
19
|
-
Style/
|
22
|
+
Style/FormatString:
|
20
23
|
Enabled: false
|
21
24
|
|
22
25
|
Style/Documentation:
|
23
26
|
Enabled: false
|
24
27
|
|
25
|
-
|
28
|
+
Layout/SpaceInLambdaLiteral:
|
26
29
|
Enabled: false
|
27
30
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
+
Layout/MultilineMethodCallIndentation:
|
32
|
+
Enabled: true
|
33
|
+
EnforcedStyle: indented
|
31
34
|
|
32
|
-
|
33
|
-
|
34
|
-
- spec/**/*.rb
|
35
|
+
Metrics/LineLength:
|
36
|
+
Max: 100
|
35
37
|
|
36
|
-
|
38
|
+
Metrics/MethodLength:
|
39
|
+
Max: 22
|
40
|
+
|
41
|
+
Metrics/ClassLength:
|
42
|
+
Max: 150
|
43
|
+
|
44
|
+
Metrics/AbcSize:
|
45
|
+
Max: 20
|
46
|
+
|
47
|
+
Metrics/BlockLength:
|
48
|
+
Enabled: false
|
49
|
+
|
50
|
+
Metrics/CyclomaticComplexity:
|
51
|
+
Enabled: true
|
52
|
+
Max: 10
|
53
|
+
|
54
|
+
Lint/BooleanSymbol:
|
55
|
+
Enabled: false
|
56
|
+
|
57
|
+
Style/AccessModifierDeclarations:
|
58
|
+
Enabled: false
|
59
|
+
|
60
|
+
Style/BlockDelimiters:
|
37
61
|
Enabled: false
|
38
62
|
|
39
|
-
|
63
|
+
Layout/IndentFirstArrayElement:
|
64
|
+
EnforcedStyle: consistent
|
65
|
+
|
66
|
+
Style/ClassAndModuleChildren:
|
40
67
|
Exclude:
|
41
|
-
- spec
|
68
|
+
- "spec/**/*_spec.rb"
|
42
69
|
|
43
|
-
|
70
|
+
Lint/HandleExceptions:
|
44
71
|
Exclude:
|
45
|
-
- spec
|
72
|
+
- "spec/spec_helper.rb"
|
46
73
|
|
47
|
-
|
48
|
-
|
74
|
+
Naming/FileName:
|
75
|
+
Exclude:
|
76
|
+
- "lib/dry-*.rb"
|
77
|
+
|
78
|
+
Style/SymbolArray:
|
79
|
+
Exclude:
|
80
|
+
- "spec/**/*_spec.rb"
|
81
|
+
|
82
|
+
Style/ConditionalAssignment:
|
83
|
+
Enabled: false
|
84
|
+
|
85
|
+
Naming/MethodName:
|
86
|
+
Enabled: false
|
49
87
|
|
50
|
-
Style/
|
51
|
-
|
88
|
+
Style/AsciiComments:
|
89
|
+
Enabled: false
|
data/CHANGELOG.md
CHANGED
@@ -5,6 +5,145 @@ All notable changes to this project will be documented in this file.
|
|
5
5
|
The format is based on [Keep a Changelog](http://keepachangelog.com/)
|
6
6
|
and this project adheres to [Semantic Versioning](http://semver.org/).
|
7
7
|
|
8
|
+
## [3.0.2] [2019-11-07]
|
9
|
+
|
10
|
+
### Fixed
|
11
|
+
|
12
|
+
- Warnings about keyword arguments (flash-gordon)
|
13
|
+
|
14
|
+
## [3.0.1] [2019-04-15]
|
15
|
+
|
16
|
+
### Fixed
|
17
|
+
|
18
|
+
- Usage of underscored names of `option`-s and `param`-s (nepalez)
|
19
|
+
|
20
|
+
You can use any sequence of underscores except for in nested types.
|
21
|
+
In nested types single underscores can be used to split alphanumeric
|
22
|
+
parts only.
|
23
|
+
|
24
|
+
```ruby
|
25
|
+
class Test
|
26
|
+
extend Dry::Initializer
|
27
|
+
|
28
|
+
# Proper usage
|
29
|
+
option :foo_bar do
|
30
|
+
option :__foo__, proc(&:to_s)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
# Improper usage
|
35
|
+
option :__foo__ do
|
36
|
+
# ...
|
37
|
+
end
|
38
|
+
|
39
|
+
option :foo__bar do
|
40
|
+
# ...
|
41
|
+
end
|
42
|
+
end
|
43
|
+
```
|
44
|
+
|
45
|
+
This restriction is necessary because we constantize option/param names
|
46
|
+
when defining nested structs.
|
47
|
+
|
48
|
+
## [3.0.0] [2019-04-14]
|
49
|
+
|
50
|
+
### Added
|
51
|
+
|
52
|
+
- Support of wrapped types/coercers (nepalez)
|
53
|
+
|
54
|
+
```ruby
|
55
|
+
class Test
|
56
|
+
# Wrap type to the array
|
57
|
+
param :foo, [proc(&:to_s)]
|
58
|
+
end
|
59
|
+
|
60
|
+
# And the value will be wrapped as well
|
61
|
+
test = Test.new(42)
|
62
|
+
test.foo # => ["42"]
|
63
|
+
```
|
64
|
+
|
65
|
+
- It works with several layers of nesting (nepalez)
|
66
|
+
|
67
|
+
```ruby
|
68
|
+
class Test
|
69
|
+
# Wrap type to the array
|
70
|
+
param :foo, [[proc(&:to_s)]]
|
71
|
+
end
|
72
|
+
|
73
|
+
# And the value will be wrapped as well
|
74
|
+
test = Test.new(42)
|
75
|
+
test.foo # => [["42"]]
|
76
|
+
```
|
77
|
+
|
78
|
+
- Support of nested types/coercers (nepalez)
|
79
|
+
|
80
|
+
```ruby
|
81
|
+
class Test
|
82
|
+
param :foo do
|
83
|
+
option :bar do
|
84
|
+
option :baz, proc(&:to_s)
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
test = Test.new(bar: { "baz" => 42 })
|
90
|
+
test.foo.bar.baz # => "42"
|
91
|
+
```
|
92
|
+
|
93
|
+
- Wrapped/nested combinations are supported as well (nepalez)
|
94
|
+
|
95
|
+
```ruby
|
96
|
+
class Test
|
97
|
+
param :foo, [] do
|
98
|
+
option :bar, proc(&:to_s)
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
test = Test.new(bar: 42)
|
103
|
+
test.foo.first.bar # => "42"
|
104
|
+
```
|
105
|
+
|
106
|
+
## [2.7.0] Unreleazed
|
107
|
+
|
108
|
+
### Fixed
|
109
|
+
|
110
|
+
- Roll back master to the state of [2.5.0].
|
111
|
+
|
112
|
+
Somehow distinction between `@default_null` and `@null` variables
|
113
|
+
in the `Dry::Initializer::Builders` broken the `rom` library.
|
114
|
+
|
115
|
+
The version [2.6.0] has been yanked on rubygems, so the master
|
116
|
+
was rolled back to the previous state until the reason for
|
117
|
+
the incompatibility become clear (bjeanes, nepalez)
|
118
|
+
|
119
|
+
## [2.6.0] [2018-09-09] (YANKED)
|
120
|
+
|
121
|
+
## [2.5.0] [2018-08-17]
|
122
|
+
|
123
|
+
### Fixed
|
124
|
+
|
125
|
+
- `nil` coercion (belousovAV)
|
126
|
+
|
127
|
+
When default value is `nil` instead of `Dry::Initializer::UNDEFINED`,
|
128
|
+
the coercion should be applied to any value, including `nil`, because
|
129
|
+
we cannot distinct "undefined" `nil` from the "assigned" `nil` value.
|
130
|
+
|
131
|
+
## [2.4.0] [2018-02-01]
|
132
|
+
|
133
|
+
### Added
|
134
|
+
- Dispatchers for adding syntax sugar to `param` and `options` (nepalez)
|
135
|
+
|
136
|
+
```ruby
|
137
|
+
# Converts `integer: true` to `type: proc(&:to_i)`
|
138
|
+
dispatcher = ->(op) { op[:integer] ? op.merge(type: proc(&:to_i)) : op }
|
139
|
+
# Register a dispatcher
|
140
|
+
Dry::Initializer::Dispatchers << dispatcher
|
141
|
+
# Use syntax sugar
|
142
|
+
class User
|
143
|
+
param :id, integer: true # same as param :id, proc(&:to_i)
|
144
|
+
end
|
145
|
+
```
|
146
|
+
|
8
147
|
## [2.3.0] [2017-09-19]
|
9
148
|
|
10
149
|
### Added
|
@@ -15,7 +154,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
|
|
15
154
|
```ruby
|
16
155
|
class Location < String
|
17
156
|
attr_reader :parameter # refers back to its parameter
|
18
|
-
|
157
|
+
|
19
158
|
def initialize(name, parameter)
|
20
159
|
super(name)
|
21
160
|
@parameter = parameter
|
@@ -303,7 +442,7 @@ and to @gzigzigzeo for persuading me to do this refactoring.
|
|
303
442
|
|
304
443
|
### Added
|
305
444
|
- No-undefined configuration of the initializer (nepalez, flash-gordon)
|
306
|
-
|
445
|
+
|
307
446
|
You can either extend or include module `Dry::Initializer` with additional option
|
308
447
|
`[undefined: false]`. This time `nil` will be assigned instead of
|
309
448
|
`Dry::Initializer::UNDEFINED`. Readers becomes faster because there is no need
|
@@ -351,18 +490,20 @@ and to @gzigzigzeo for persuading me to do this refactoring.
|
|
351
490
|
### Added
|
352
491
|
- enhancement via `Dry::Initializer::Attribute.dispatchers` registry (nepalez)
|
353
492
|
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
493
|
+
```ruby
|
494
|
+
# Register dispatcher for `:string` option
|
495
|
+
Dry::Initializer::Attribute.dispatchers << ->(string: nil, **op) do
|
496
|
+
string ? op.merge(type: proc(&:to_s)) : op
|
497
|
+
end
|
358
498
|
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
499
|
+
# Now you can use the `:string` key for `param` and `option`
|
500
|
+
class User
|
501
|
+
extend Dry::Initializer
|
502
|
+
param :name, string: true
|
503
|
+
end
|
364
504
|
|
365
|
-
|
505
|
+
User.new(:Andy).name # => "Andy"
|
506
|
+
```
|
366
507
|
|
367
508
|
### Changed
|
368
509
|
- optimize assignments for performance (nepalez)
|
@@ -413,7 +554,7 @@ In this version the code has been rewritten for simplicity
|
|
413
554
|
|
414
555
|
### Internal
|
415
556
|
- Refactor the way [#initializer] method is (re)defined (nepalez)
|
416
|
-
|
557
|
+
|
417
558
|
When you extend class with `Dry::Initializer::Mixin`, the initializer is
|
418
559
|
defined not "inside" the class per se, but inside the included module. The
|
419
560
|
reference to that module is stored as class-level `__initializer_mixin__`.
|
@@ -741,3 +882,9 @@ First public release
|
|
741
882
|
[2.1.0]: https://github.com/dry-rb/dry-initializer/compare/v2.0.0...v2.1.0
|
742
883
|
[2.2.0]: https://github.com/dry-rb/dry-initializer/compare/v2.1.0...v2.2.0
|
743
884
|
[2.3.0]: https://github.com/dry-rb/dry-initializer/compare/v2.2.0...v2.3.0
|
885
|
+
[2.4.0]: https://github.com/dry-rb/dry-initializer/compare/v2.3.0...v2.4.0
|
886
|
+
[2.6.0]: https://github.com/dry-rb/dry-initializer/compare/v2.4.0...v2.5.0
|
887
|
+
[2.6.0]: https://github.com/dry-rb/dry-initializer/compare/v2.5.0...v2.6.0
|
888
|
+
[3.0.0]: https://github.com/dry-rb/dry-initializer/compare/v2.5.0...v3.0.0
|
889
|
+
[3.0.1]: https://github.com/dry-rb/dry-initializer/compare/v3.0.0...v3.0.1
|
890
|
+
[3.0.2]: https://github.com/dry-rb/dry-initializer/compare/v3.0.1...v3.0.2
|