dry-initializer 3.0.2 → 3.0.3
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/.github/ISSUE_TEMPLATE/---bug-report.md +1 -5
- data/.github/workflows/custom_ci.yml +31 -47
- data/.github/workflows/sync_configs.yml +29 -7
- data/.rspec +1 -1
- data/.rubocop.yml +19 -6
- data/CHANGELOG.md +6 -0
- data/Gemfile +27 -29
- data/Gemfile.devtools +16 -0
- data/Guardfile +3 -3
- data/LICENSE +1 -1
- data/README.md +17 -77
- data/Rakefile +4 -4
- data/benchmarks/compare_several_defaults.rb +27 -27
- data/benchmarks/plain_options.rb +14 -14
- data/benchmarks/plain_params.rb +22 -22
- data/benchmarks/with_coercion.rb +14 -14
- data/benchmarks/with_defaults.rb +17 -17
- data/benchmarks/with_defaults_and_coercion.rb +14 -14
- data/bin/.gitkeep +0 -0
- data/dry-initializer.gemspec +13 -13
- data/lib/dry-initializer.rb +1 -1
- data/lib/dry/initializer.rb +9 -9
- data/lib/dry/initializer/builders.rb +2 -2
- data/lib/dry/initializer/builders/attribute.rb +12 -7
- data/lib/dry/initializer/builders/initializer.rb +9 -13
- data/lib/dry/initializer/builders/reader.rb +3 -1
- data/lib/dry/initializer/builders/signature.rb +3 -3
- data/lib/dry/initializer/config.rb +6 -4
- data/lib/dry/initializer/definition.rb +9 -9
- data/lib/dry/initializer/dispatchers.rb +10 -10
- data/lib/dry/initializer/dispatchers/prepare_default.rb +2 -2
- data/lib/dry/initializer/dispatchers/prepare_ivar.rb +1 -1
- data/lib/dry/initializer/dispatchers/prepare_reader.rb +3 -3
- data/lib/dry/initializer/dispatchers/wrap_type.rb +1 -0
- data/lib/dry/initializer/mixin.rb +4 -4
- data/lib/dry/initializer/version.rb +5 -0
- data/lib/tasks/benchmark.rake +13 -13
- data/lib/tasks/profile.rake +16 -16
- data/project.yml +2 -0
- data/spec/attributes_spec.rb +7 -7
- data/spec/coercion_of_nil_spec.rb +3 -3
- data/spec/custom_dispatchers_spec.rb +6 -6
- data/spec/custom_initializer_spec.rb +2 -2
- data/spec/default_values_spec.rb +9 -9
- data/spec/definition_spec.rb +10 -10
- data/spec/invalid_default_spec.rb +2 -2
- data/spec/list_type_spec.rb +8 -8
- data/spec/missed_default_spec.rb +2 -2
- data/spec/nested_type_spec.rb +10 -10
- data/spec/optional_spec.rb +16 -16
- data/spec/options_tolerance_spec.rb +2 -2
- data/spec/public_attributes_utility_spec.rb +5 -5
- data/spec/reader_spec.rb +13 -13
- data/spec/repetitive_definitions_spec.rb +9 -9
- data/spec/several_assignments_spec.rb +9 -9
- data/spec/spec_helper.rb +3 -8
- data/spec/subclassing_spec.rb +5 -5
- data/spec/support/coverage.rb +7 -0
- data/spec/support/warnings.rb +7 -0
- data/spec/type_argument_spec.rb +13 -13
- data/spec/type_constraint_spec.rb +44 -26
- data/spec/value_coercion_via_dry_types_spec.rb +7 -7
- metadata +11 -31
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b6ced45dbc940dabce6d9f202a03e1ffc01b46cc14cb8981961d959392837a56
|
4
|
+
data.tar.gz: 70357b155bbe3516384a62d42b222f31ca401f29d8377dec06220124c0e95c07
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9c24c4d7127c8723d2142033da1a50f87450b725f69aa6948ea5b311154006e754f2ceaca88419e07bd4d648749097a9037763d180cfe87b8db525da888d82c2
|
7
|
+
data.tar.gz: 39dd6072626a6e80cc485c63462c19a93f1fa72c9e91300bb175c6c4ac643e71189963d8ee2d2f67dab4c1265dc224119ff3b3aa488f294231e333def76e9770
|
@@ -9,11 +9,7 @@ assignees: ''
|
|
9
9
|
|
10
10
|
**Before you submit this: WE ONLY ACCEPT BUG REPORTS AND FEATURE REQUESTS**
|
11
11
|
|
12
|
-
For more information see
|
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.
|
12
|
+
For more information see `CONTRIBUTING.md`.
|
17
13
|
|
18
14
|
**Describe the bug**
|
19
15
|
|
@@ -6,69 +6,53 @@ on:
|
|
6
6
|
- .github/workflows/custom_ci.yml
|
7
7
|
- lib/**
|
8
8
|
- spec/**
|
9
|
+
- Rakefile
|
9
10
|
- Gemfile
|
11
|
+
- Gemfile.devtools
|
10
12
|
- "*.gemspec"
|
13
|
+
- ".rubocop.yml"
|
14
|
+
pull_request:
|
15
|
+
branches:
|
16
|
+
- master
|
11
17
|
|
12
18
|
jobs:
|
13
|
-
tests
|
19
|
+
tests:
|
14
20
|
runs-on: ubuntu-latest
|
15
21
|
strategy:
|
16
22
|
fail-fast: false
|
17
23
|
matrix:
|
18
|
-
ruby:
|
24
|
+
ruby:
|
25
|
+
- "2.7"
|
26
|
+
- "2.6"
|
27
|
+
- "2.5"
|
28
|
+
- "2.4"
|
29
|
+
- "jruby"
|
30
|
+
runtime_deps:
|
31
|
+
- "dry-types-latest"
|
32
|
+
- "dry-types-master"
|
19
33
|
include:
|
20
|
-
- ruby: "2.6
|
34
|
+
- ruby: "2.6"
|
21
35
|
coverage: "true"
|
36
|
+
- runtime_deps: "dry-types-master"
|
37
|
+
dry_types_from_master: "true"
|
22
38
|
steps:
|
23
39
|
- uses: actions/checkout@v1
|
24
40
|
- name: Set up Ruby
|
25
|
-
uses:
|
41
|
+
uses: eregon/use-ruby-action@master
|
26
42
|
with:
|
27
43
|
ruby-version: ${{matrix.ruby}}
|
28
|
-
- name:
|
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}}
|
44
|
+
- name: Install latest bundler
|
39
45
|
run: |
|
40
46
|
gem install bundler
|
41
|
-
bundle config set without 'tools docs
|
42
|
-
|
43
|
-
|
44
|
-
- name: Send coverage results
|
45
|
-
if: "matrix.coverage == 'true'"
|
47
|
+
bundle config set without 'tools benchmarks docs'
|
48
|
+
- name: Bundle install
|
49
|
+
run: bundle install --jobs 4 --retry 3
|
46
50
|
env:
|
47
|
-
|
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
|
51
|
+
DRY_TYPES_FROM_MASTER: ${{matrix.dry_types_from_master}}
|
70
52
|
- name: Run all tests
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
53
|
+
env:
|
54
|
+
DRY_TYPES_FROM_MASTER: ${{matrix.dry_types_from_master}}
|
55
|
+
COVERAGE: ${{matrix.coverage}}
|
56
|
+
CODACY_RUN_LOCAL: true
|
57
|
+
CODACY_PROJECT_TOKEN: ${{secrets.CODACY_PROJECT_TOKEN}}
|
58
|
+
run: bundle exec rake
|
@@ -11,23 +11,45 @@ jobs:
|
|
11
11
|
if: github.event.action == 'sync_configs'
|
12
12
|
steps:
|
13
13
|
- uses: actions/checkout@v1
|
14
|
-
- name:
|
14
|
+
- name: Set up Ruby
|
15
|
+
uses: eregon/use-ruby-action@master
|
16
|
+
with:
|
17
|
+
ruby-version: 2.6
|
18
|
+
- name: Install latest bundler
|
19
|
+
run: |
|
20
|
+
gem install bundler
|
21
|
+
bundle config set without 'tools benchmarks docs'
|
22
|
+
- name: Install dependencies
|
23
|
+
run: bundle install --jobs 4 --retry 3 --without tools test benchmarks docs
|
24
|
+
- name: Symlink ossy
|
25
|
+
run: ln -sf "$(bundle info ossy --path)/bin/ossy" bin/ossy
|
26
|
+
- name: Clone devtools
|
27
|
+
run: git clone https://github.com/dry-rb/devtools.git tmp/devtools
|
28
|
+
- name: Compile file templates
|
15
29
|
env:
|
16
30
|
GITHUB_LOGIN: dry-bot
|
17
31
|
GITHUB_TOKEN: ${{ secrets.GH_PAT }}
|
18
32
|
run: |
|
19
|
-
|
20
|
-
|
33
|
+
if [ -f "project.yml" ]; then
|
34
|
+
for t in `ls tmp/devtools/templates`
|
35
|
+
do
|
36
|
+
bin/ossy t c tmp/devtools/templates/$t $(basename $t .erb) project.yml
|
37
|
+
done
|
38
|
+
fi
|
39
|
+
- name: Update configuration files from devtools
|
40
|
+
run: |
|
21
41
|
if [ -f ".github/workflows/custom_ci.yml" ]; then
|
22
|
-
rsync -
|
42
|
+
rsync -arv --exclude '.github/workflows/ci.yml' tmp/devtools/shared/ . ;
|
23
43
|
else
|
24
|
-
rsync -
|
44
|
+
rsync -arv tmp/devtools/shared/ . ;
|
25
45
|
fi
|
26
|
-
|
46
|
+
- name: Commit changes
|
47
|
+
run: |
|
48
|
+
rm bin/ossy
|
27
49
|
git config --local user.email "dry-bot@dry-rb.org"
|
28
50
|
git config --local user.name "dry-bot"
|
29
51
|
git add -A
|
30
|
-
git commit -m "[devtools]
|
52
|
+
git commit -m "[devtools] sync configs" || echo "nothing changed"
|
31
53
|
- name: Push changes
|
32
54
|
uses: ad-m/github-push-action@master
|
33
55
|
with:
|
data/.rspec
CHANGED
data/.rubocop.yml
CHANGED
@@ -10,9 +10,13 @@ Style/StringLiterals:
|
|
10
10
|
Enabled: true
|
11
11
|
EnforcedStyle: single_quotes
|
12
12
|
|
13
|
-
Style/
|
13
|
+
Style/ParallelAssignment:
|
14
14
|
Enabled: false
|
15
15
|
|
16
|
+
Style/Alias:
|
17
|
+
Enabled: true
|
18
|
+
EnforcedStyle: prefer_alias_method
|
19
|
+
|
16
20
|
Style/LambdaCall:
|
17
21
|
Enabled: false
|
18
22
|
|
@@ -36,17 +40,17 @@ Metrics/LineLength:
|
|
36
40
|
Max: 100
|
37
41
|
|
38
42
|
Metrics/MethodLength:
|
39
|
-
|
43
|
+
Enabled: false
|
40
44
|
|
41
45
|
Metrics/ClassLength:
|
42
|
-
|
43
|
-
|
44
|
-
Metrics/AbcSize:
|
45
|
-
Max: 20
|
46
|
+
Enabled: false
|
46
47
|
|
47
48
|
Metrics/BlockLength:
|
48
49
|
Enabled: false
|
49
50
|
|
51
|
+
Metrics/AbcSize:
|
52
|
+
Max: 20
|
53
|
+
|
50
54
|
Metrics/CyclomaticComplexity:
|
51
55
|
Enabled: true
|
52
56
|
Max: 10
|
@@ -71,6 +75,9 @@ Lint/HandleExceptions:
|
|
71
75
|
Exclude:
|
72
76
|
- "spec/spec_helper.rb"
|
73
77
|
|
78
|
+
Naming/PredicateName:
|
79
|
+
Enabled: false
|
80
|
+
|
74
81
|
Naming/FileName:
|
75
82
|
Exclude:
|
76
83
|
- "lib/dry-*.rb"
|
@@ -87,3 +94,9 @@ Naming/MethodName:
|
|
87
94
|
|
88
95
|
Style/AsciiComments:
|
89
96
|
Enabled: false
|
97
|
+
|
98
|
+
Style/DateTime:
|
99
|
+
Enabled: false
|
100
|
+
|
101
|
+
Style/IfUnlessModifier:
|
102
|
+
Enabled: false
|
data/CHANGELOG.md
CHANGED
@@ -5,6 +5,12 @@ 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.3] [2020-01-08]
|
9
|
+
|
10
|
+
### Fixed
|
11
|
+
|
12
|
+
- Constrained member arrays work correctly now (see #33) (@bjeanes + @solnic)
|
13
|
+
|
8
14
|
## [3.0.2] [2019-11-07]
|
9
15
|
|
10
16
|
### Fixed
|
data/Gemfile
CHANGED
@@ -1,38 +1,36 @@
|
|
1
|
-
source
|
1
|
+
source 'https://rubygems.org'
|
2
2
|
|
3
|
-
|
4
|
-
gemspec
|
3
|
+
eval_gemfile 'Gemfile.devtools'
|
5
4
|
|
6
|
-
|
7
|
-
group :benchmarks do
|
8
|
-
if RUBY_VERSION < "2.4"
|
9
|
-
gem "activesupport", "< 5"
|
10
|
-
else
|
11
|
-
gem "activesupport"
|
12
|
-
end
|
5
|
+
gemspec
|
13
6
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
gem "concord"
|
19
|
-
gem "fast_attributes"
|
20
|
-
gem "kwattr"
|
21
|
-
gem "ruby-prof", platform: :mri
|
22
|
-
gem "value_struct"
|
23
|
-
gem "values"
|
24
|
-
gem "virtus"
|
25
|
-
end
|
7
|
+
if ENV['DRY_TYPES_FROM_MASTER'].eql?('true')
|
8
|
+
gem 'dry-types', github: 'dry-rb/dry-types', branch: 'master'
|
9
|
+
else
|
10
|
+
gem 'dry-types'
|
26
11
|
end
|
27
12
|
|
28
|
-
group :
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
gem '
|
13
|
+
group :benchmarks do
|
14
|
+
if RUBY_VERSION < '2.4'
|
15
|
+
gem 'activesupport', '< 5'
|
16
|
+
else
|
17
|
+
gem 'activesupport'
|
33
18
|
end
|
19
|
+
|
20
|
+
gem 'active_attr'
|
21
|
+
gem 'anima'
|
22
|
+
gem 'attr_extras'
|
23
|
+
gem 'benchmark-ips', '~> 2.5'
|
24
|
+
gem 'concord'
|
25
|
+
gem 'fast_attributes'
|
26
|
+
gem 'kwattr'
|
27
|
+
gem 'ruby-prof', platform: :mri
|
28
|
+
gem 'value_struct'
|
29
|
+
gem 'values'
|
30
|
+
gem 'virtus'
|
34
31
|
end
|
35
32
|
|
36
|
-
group :test do
|
37
|
-
gem '
|
33
|
+
group :development, :test do
|
34
|
+
gem 'pry', platform: :mri
|
35
|
+
gem 'pry-byebug', platform: :mri
|
38
36
|
end
|
data/Gemfile.devtools
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
# this file is managed by dry-rb/devtools project
|
2
|
+
|
3
|
+
git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
|
4
|
+
|
5
|
+
gem "ossy", github: "solnic/ossy", branch: "master", platforms: :ruby
|
6
|
+
|
7
|
+
group :test do
|
8
|
+
gem 'codacy-coverage', require: false, platforms: :ruby
|
9
|
+
gem 'simplecov', require: false, platforms: :ruby
|
10
|
+
gem 'warning'
|
11
|
+
end
|
12
|
+
|
13
|
+
group :tools do
|
14
|
+
# this is the same version that we use on codacy
|
15
|
+
gem 'rubocop', '0.71.0'
|
16
|
+
end
|
data/Guardfile
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
guard :rspec, cmd:
|
1
|
+
guard :rspec, cmd: 'bundle exec rspec' do
|
2
2
|
watch(%r{^spec/.+_spec\.rb$})
|
3
|
-
watch(%r{^spec/(spec_helper|support)}) {
|
4
|
-
watch(%r{^lib/.+}) {
|
3
|
+
watch(%r{^spec/(spec_helper|support)}) { 'spec' }
|
4
|
+
watch(%r{^lib/.+}) { 'spec' }
|
5
5
|
end
|
data/LICENSE
CHANGED
data/README.md
CHANGED
@@ -1,89 +1,29 @@
|
|
1
|
-
# dry-initializer [][chat]
|
2
|
-
|
3
|
-
[][gem]
|
4
|
-
[][ci]
|
5
|
-
[][codeclimate]
|
6
|
-
[][codeclimate]
|
7
|
-
[][inchpages]
|
8
|
-
|
9
1
|
[gem]: https://rubygems.org/gems/dry-initializer
|
10
|
-
[
|
11
|
-
[
|
12
|
-
[coveralls]: https://coveralls.io/r/dry-rb/dry-initializer
|
13
|
-
[inchpages]: http://inch-ci.org/github/dry-rb/dry-initializer
|
14
|
-
[docs]: http://dry-rb.org/gems/dry-initializer/
|
15
|
-
[benchmarks]: https://github.com/dry-rb/dry-initializer/wiki
|
16
|
-
[license]: http://opensource.org/licenses/MIT
|
2
|
+
[actions]: https://github.com/dry-rb/dry-initializer/actions
|
3
|
+
[codacy]: https://www.codacy.com/gh/dry-rb/dry-initializer
|
17
4
|
[chat]: https://dry-rb.zulipchat.com
|
5
|
+
[inchpages]: http://inch-ci.org/github/dry-rb/dry-initializer
|
18
6
|
|
19
|
-
|
20
|
-
|
21
|
-
## Installation
|
22
|
-
|
23
|
-
Add this line to your application's Gemfile:
|
24
|
-
|
25
|
-
```ruby
|
26
|
-
gem 'dry-initializer'
|
27
|
-
```
|
28
|
-
|
29
|
-
And then execute:
|
30
|
-
|
31
|
-
```shell
|
32
|
-
$ bundle
|
33
|
-
```
|
34
|
-
|
35
|
-
Or install it yourself as:
|
36
|
-
|
37
|
-
```shell
|
38
|
-
$ gem install dry-initializer
|
39
|
-
```
|
40
|
-
|
41
|
-
## Synopsis
|
42
|
-
|
43
|
-
```ruby
|
44
|
-
require 'dry-initializer'
|
45
|
-
require 'dry-types'
|
46
|
-
|
47
|
-
class User
|
48
|
-
extend Dry::Initializer
|
49
|
-
|
50
|
-
# Params of the initializer along with corresponding readers
|
51
|
-
param :name, proc(&:to_s)
|
52
|
-
param :role, default: -> { 'customer' }
|
53
|
-
# Options of the initializer along with corresponding readers
|
54
|
-
option :admin, default: -> { false }
|
55
|
-
option :vip, optional: true
|
56
|
-
end
|
57
|
-
|
58
|
-
# Defines the initializer with params and options
|
59
|
-
user = User.new 'Vladimir', 'admin', admin: true
|
60
|
-
|
61
|
-
# Defines readers for single attributes
|
62
|
-
user.name # => 'Vladimir'
|
63
|
-
user.role # => 'admin'
|
64
|
-
user.admin # => true
|
65
|
-
user.vip # => Dry::Initializer::UNDEFINED
|
66
|
-
```
|
67
|
-
|
68
|
-
See full documentation on the [Dry project official site][docs]
|
7
|
+
# dry-initializer [][chat]
|
69
8
|
|
70
|
-
|
9
|
+
[][gem]
|
10
|
+
[][actions]
|
11
|
+
[][codacy]
|
12
|
+
[][codacy]
|
13
|
+
[][inchpages]
|
71
14
|
|
72
|
-
|
15
|
+
## Links
|
73
16
|
|
74
|
-
|
17
|
+
* [User documentation](http://dry-rb.org/gems/dry-initializer)
|
18
|
+
* [API documentation](http://rubydoc.info/gems/dry-initializer)
|
75
19
|
|
76
|
-
|
20
|
+
## Supported Ruby versions
|
77
21
|
|
78
|
-
|
22
|
+
This library officially supports the following Ruby versions:
|
79
23
|
|
80
|
-
|
81
|
-
|
82
|
-
- Add tests for it
|
83
|
-
- Commit your changes (`git commit -am '[UPDATE] Add some feature'`)
|
84
|
-
- Push to the branch (`git push origin my-new-feature`)
|
85
|
-
- Create a new Pull Request
|
24
|
+
* MRI >= `2.4`
|
25
|
+
* jruby >= `9.2`
|
86
26
|
|
87
27
|
## License
|
88
28
|
|
89
|
-
|
29
|
+
See `LICENSE` file.
|