dry-initializer 3.0.2 → 3.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (64) hide show
  1. checksums.yaml +4 -4
  2. data/.github/ISSUE_TEMPLATE/---bug-report.md +1 -5
  3. data/.github/workflows/custom_ci.yml +31 -47
  4. data/.github/workflows/sync_configs.yml +29 -7
  5. data/.rspec +1 -1
  6. data/.rubocop.yml +19 -6
  7. data/CHANGELOG.md +6 -0
  8. data/Gemfile +27 -29
  9. data/Gemfile.devtools +16 -0
  10. data/Guardfile +3 -3
  11. data/LICENSE +1 -1
  12. data/README.md +17 -77
  13. data/Rakefile +4 -4
  14. data/benchmarks/compare_several_defaults.rb +27 -27
  15. data/benchmarks/plain_options.rb +14 -14
  16. data/benchmarks/plain_params.rb +22 -22
  17. data/benchmarks/with_coercion.rb +14 -14
  18. data/benchmarks/with_defaults.rb +17 -17
  19. data/benchmarks/with_defaults_and_coercion.rb +14 -14
  20. data/bin/.gitkeep +0 -0
  21. data/dry-initializer.gemspec +13 -13
  22. data/lib/dry-initializer.rb +1 -1
  23. data/lib/dry/initializer.rb +9 -9
  24. data/lib/dry/initializer/builders.rb +2 -2
  25. data/lib/dry/initializer/builders/attribute.rb +12 -7
  26. data/lib/dry/initializer/builders/initializer.rb +9 -13
  27. data/lib/dry/initializer/builders/reader.rb +3 -1
  28. data/lib/dry/initializer/builders/signature.rb +3 -3
  29. data/lib/dry/initializer/config.rb +6 -4
  30. data/lib/dry/initializer/definition.rb +9 -9
  31. data/lib/dry/initializer/dispatchers.rb +10 -10
  32. data/lib/dry/initializer/dispatchers/prepare_default.rb +2 -2
  33. data/lib/dry/initializer/dispatchers/prepare_ivar.rb +1 -1
  34. data/lib/dry/initializer/dispatchers/prepare_reader.rb +3 -3
  35. data/lib/dry/initializer/dispatchers/wrap_type.rb +1 -0
  36. data/lib/dry/initializer/mixin.rb +4 -4
  37. data/lib/dry/initializer/version.rb +5 -0
  38. data/lib/tasks/benchmark.rake +13 -13
  39. data/lib/tasks/profile.rake +16 -16
  40. data/project.yml +2 -0
  41. data/spec/attributes_spec.rb +7 -7
  42. data/spec/coercion_of_nil_spec.rb +3 -3
  43. data/spec/custom_dispatchers_spec.rb +6 -6
  44. data/spec/custom_initializer_spec.rb +2 -2
  45. data/spec/default_values_spec.rb +9 -9
  46. data/spec/definition_spec.rb +10 -10
  47. data/spec/invalid_default_spec.rb +2 -2
  48. data/spec/list_type_spec.rb +8 -8
  49. data/spec/missed_default_spec.rb +2 -2
  50. data/spec/nested_type_spec.rb +10 -10
  51. data/spec/optional_spec.rb +16 -16
  52. data/spec/options_tolerance_spec.rb +2 -2
  53. data/spec/public_attributes_utility_spec.rb +5 -5
  54. data/spec/reader_spec.rb +13 -13
  55. data/spec/repetitive_definitions_spec.rb +9 -9
  56. data/spec/several_assignments_spec.rb +9 -9
  57. data/spec/spec_helper.rb +3 -8
  58. data/spec/subclassing_spec.rb +5 -5
  59. data/spec/support/coverage.rb +7 -0
  60. data/spec/support/warnings.rb +7 -0
  61. data/spec/type_argument_spec.rb +13 -13
  62. data/spec/type_constraint_spec.rb +44 -26
  63. data/spec/value_coercion_via_dry_types_spec.rb +7 -7
  64. metadata +11 -31
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f5d079daa17830b65177c99533e1b7f280bb4aee14dbcba097ba8c40de273abd
4
- data.tar.gz: a59b00abe9c741b764152a6213ff40c29adbdf27094ecebbaaf766b2e056aa99
3
+ metadata.gz: b6ced45dbc940dabce6d9f202a03e1ffc01b46cc14cb8981961d959392837a56
4
+ data.tar.gz: 70357b155bbe3516384a62d42b222f31ca401f29d8377dec06220124c0e95c07
5
5
  SHA512:
6
- metadata.gz: 4fee1158d5ddd7bfca050f61788ee7012bf0a0f424239095ea649c6dd34ba47b157627efe7261f9e5fdaef405654b589addd26990a912b72cd0f76e339003754
7
- data.tar.gz: 64a5e73606be0a238d0dba9173d32f90d8366d0aae64edf378dd851705a07d4ede0906ed241cc85ff9cb9b5c5f3fe9734bfb77d53fb6fc71bf29565b8607c388
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 [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.
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-mri:
19
+ tests:
14
20
  runs-on: ubuntu-latest
15
21
  strategy:
16
22
  fail-fast: false
17
23
  matrix:
18
- ruby: ["2.6.x", "2.5.x", "2.4.x", "2.3.x"]
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.x"
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: actions/setup-ruby@v1
41
+ uses: eregon/use-ruby-action@master
26
42
  with:
27
43
  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}}
44
+ - name: Install latest bundler
39
45
  run: |
40
46
  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'"
47
+ bundle config set without 'tools benchmarks docs'
48
+ - name: Bundle install
49
+ run: bundle install --jobs 4 --retry 3
46
50
  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
51
+ DRY_TYPES_FROM_MASTER: ${{matrix.dry_types_from_master}}
70
52
  - 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
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: Update configuration files from devtools
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
- git clone https://github.com/dry-rb/devtools.git tmp/devtools
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 -av --exclude '.github/workflows/ci.yml' tmp/devtools/shared/ . ;
42
+ rsync -arv --exclude '.github/workflows/ci.yml' tmp/devtools/shared/ . ;
23
43
  else
24
- rsync -av tmp/devtools/shared/ . ;
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] config sync" || echo "nothing changed"
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
@@ -1,4 +1,4 @@
1
1
  --color
2
2
  --require spec_helper
3
3
  --order random
4
-
4
+ --warnings
@@ -10,9 +10,13 @@ Style/StringLiterals:
10
10
  Enabled: true
11
11
  EnforcedStyle: single_quotes
12
12
 
13
- Style/Alias:
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
- Max: 22
43
+ Enabled: false
40
44
 
41
45
  Metrics/ClassLength:
42
- Max: 150
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
@@ -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 "https://rubygems.org"
1
+ source 'https://rubygems.org'
2
2
 
3
- # Specify your gem"s dependencies in dry-initializer.gemspec
4
- gemspec
3
+ eval_gemfile 'Gemfile.devtools'
5
4
 
6
- unless ENV['CI'].eql?('true')
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
- gem "active_attr"
15
- gem "anima"
16
- gem "attr_extras"
17
- gem "benchmark-ips", "~> 2.5"
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 :development, :test do
29
- gem "pry", platform: :mri
30
- gem "pry-byebug", platform: :mri
31
- if RUBY_VERSION >= "2.4"
32
- gem 'ossy', git: 'https://github.com/solnic/ossy.git', branch: 'master', platform: :mri
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 'simplecov', require: false
33
+ group :development, :test do
34
+ gem 'pry', platform: :mri
35
+ gem 'pry-byebug', platform: :mri
38
36
  end
@@ -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: "bundle exec rspec" do
1
+ guard :rspec, cmd: 'bundle exec rspec' do
2
2
  watch(%r{^spec/.+_spec\.rb$})
3
- watch(%r{^spec/(spec_helper|support)}) { "spec" }
4
- watch(%r{^lib/.+}) { "spec" }
3
+ watch(%r{^spec/(spec_helper|support)}) { 'spec' }
4
+ watch(%r{^lib/.+}) { 'spec' }
5
5
  end
data/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2015-2019 dry-rb team
3
+ Copyright (c) 2015-2020 dry-rb team
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy of
6
6
  this software and associated documentation files (the "Software"), to deal in
data/README.md CHANGED
@@ -1,89 +1,29 @@
1
- # dry-initializer [![Join the chat at https://dry-rb.zulipchat.com](https://img.shields.io/badge/dry--rb-join%20chat-%23346b7a.svg)][chat]
2
-
3
- [![Gem Version](https://badge.fury.io/rb/dry-initializer.svg)][gem]
4
- [![Build Status](https://github.com/dry-rb/dry-initializer/workflows/ci/badge.svg)][ci]
5
- [![Code Climate](https://codeclimate.com/github/dry-rb/dry-initializer/badges/gpa.svg)][codeclimate]
6
- [![Test Coverage](https://api.codeclimate.com/v1/badges/73cb64231f3fb2c86e26/test_coverage)][codeclimate]
7
- [![Inline docs](http://inch-ci.org/github/dry-rb/dry-initializer.svg?branch=master)][inchpages]
8
-
9
1
  [gem]: https://rubygems.org/gems/dry-initializer
10
- [ci]: https://github.com/dry-rb/dry-initializer/actions?query=workflow%3Aci
11
- [codeclimate]: https://codeclimate.com/github/dry-rb/dry-initializer
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
- DSL for building class initializer with params and options.
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 [![Join the chat at https://dry-rb.zulipchat.com](https://img.shields.io/badge/dry--rb-join%20chat-%23346b7a.svg)][chat]
69
8
 
70
- ## Benchmarks
9
+ [![Gem Version](https://badge.fury.io/rb/dry-initializer.svg)][gem]
10
+ [![CI Status](https://github.com/dry-rb/dry-initializer/workflows/ci/badge.svg)][actions]
11
+ [![Codacy Badge](https://api.codacy.com/project/badge/Grade/03c8923afd734e9fb0f4bfe9cc893edb)][codacy]
12
+ [![Codacy Badge](https://api.codacy.com/project/badge/Coverage/03c8923afd734e9fb0f4bfe9cc893edb)][codacy]
13
+ [![Inline docs](http://inch-ci.org/github/dry-rb/dry-initializer.svg?branch=master)][inchpages]
71
14
 
72
- The `dry-initializer` is pretty fast for rubies 2.3+ [comparing to other libraries][benchmarks].
15
+ ## Links
73
16
 
74
- ## Compatibility
17
+ * [User documentation](http://dry-rb.org/gems/dry-initializer)
18
+ * [API documentation](http://rubydoc.info/gems/dry-initializer)
75
19
 
76
- Tested under rubies [compatible to MRI 2.3+](.travis.yml).
20
+ ## Supported Ruby versions
77
21
 
78
- ## Contributing
22
+ This library officially supports the following Ruby versions:
79
23
 
80
- - [Fork the project](https://github.com/dry-rb/dry-initializer)
81
- - Create your feature branch (`git checkout -b my-new-feature`)
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
- The gem is available as open source under the terms of the [MIT License][license].
29
+ See `LICENSE` file.