dry-initializer 3.0.2 → 3.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +260 -241
- data/LICENSE +1 -1
- data/README.md +18 -77
- data/dry-initializer.gemspec +34 -19
- data/lib/dry/initializer/builders/attribute.rb +78 -69
- data/lib/dry/initializer/builders/initializer.rb +56 -58
- data/lib/dry/initializer/builders/reader.rb +55 -47
- data/lib/dry/initializer/builders/signature.rb +29 -23
- data/lib/dry/initializer/builders.rb +9 -5
- data/lib/dry/initializer/config.rb +162 -158
- data/lib/dry/initializer/definition.rb +58 -54
- data/lib/dry/initializer/dispatchers/build_nested_type.rb +54 -40
- data/lib/dry/initializer/dispatchers/check_type.rb +45 -39
- data/lib/dry/initializer/dispatchers/prepare_default.rb +32 -25
- data/lib/dry/initializer/dispatchers/prepare_ivar.rb +13 -6
- data/lib/dry/initializer/dispatchers/prepare_optional.rb +14 -7
- data/lib/dry/initializer/dispatchers/prepare_reader.rb +29 -22
- data/lib/dry/initializer/dispatchers/prepare_source.rb +12 -5
- data/lib/dry/initializer/dispatchers/prepare_target.rb +44 -37
- data/lib/dry/initializer/dispatchers/unwrap_type.rb +21 -10
- data/lib/dry/initializer/dispatchers/wrap_type.rb +25 -17
- data/lib/dry/initializer/dispatchers.rb +48 -43
- data/lib/dry/initializer/dsl.rb +42 -34
- data/lib/dry/initializer/mixin/local.rb +19 -13
- data/lib/dry/initializer/mixin/root.rb +12 -7
- data/lib/dry/initializer/mixin.rb +17 -12
- data/lib/dry/initializer/struct.rb +34 -29
- data/lib/dry/initializer/undefined.rb +7 -1
- data/lib/dry/initializer/version.rb +7 -0
- data/lib/dry/initializer.rb +2 -0
- data/lib/dry-initializer.rb +2 -0
- data/lib/tasks/benchmark.rake +2 -0
- data/lib/tasks/profile.rake +4 -0
- metadata +25 -125
- data/.codeclimate.yml +0 -12
- data/.github/ISSUE_TEMPLATE/----please-don-t-ask-for-support-via-issues.md +0 -10
- data/.github/ISSUE_TEMPLATE/---bug-report.md +0 -34
- data/.github/ISSUE_TEMPLATE/---feature-request.md +0 -18
- data/.github/workflows/custom_ci.yml +0 -74
- data/.github/workflows/docsite.yml +0 -34
- data/.github/workflows/sync_configs.yml +0 -34
- data/.gitignore +0 -12
- data/.rspec +0 -4
- data/.rubocop.yml +0 -89
- data/CODE_OF_CONDUCT.md +0 -13
- data/CONTRIBUTING.md +0 -29
- data/Gemfile +0 -38
- data/Guardfile +0 -5
- data/LICENSE.txt +0 -21
- data/Rakefile +0 -8
- data/benchmarks/compare_several_defaults.rb +0 -82
- data/benchmarks/plain_options.rb +0 -63
- data/benchmarks/plain_params.rb +0 -84
- data/benchmarks/with_coercion.rb +0 -71
- data/benchmarks/with_defaults.rb +0 -66
- data/benchmarks/with_defaults_and_coercion.rb +0 -59
- data/docsite/source/attributes.html.md +0 -106
- data/docsite/source/container-version.html.md +0 -39
- data/docsite/source/index.html.md +0 -43
- data/docsite/source/inheritance.html.md +0 -43
- data/docsite/source/optionals-and-defaults.html.md +0 -130
- data/docsite/source/options-tolerance.html.md +0 -27
- data/docsite/source/params-and-options.html.md +0 -74
- data/docsite/source/rails-support.html.md +0 -101
- data/docsite/source/readers.html.md +0 -43
- data/docsite/source/skip-undefined.html.md +0 -59
- data/docsite/source/type-constraints.html.md +0 -160
- data/spec/attributes_spec.rb +0 -38
- data/spec/coercion_of_nil_spec.rb +0 -25
- data/spec/custom_dispatchers_spec.rb +0 -35
- data/spec/custom_initializer_spec.rb +0 -30
- data/spec/default_values_spec.rb +0 -83
- data/spec/definition_spec.rb +0 -111
- data/spec/invalid_default_spec.rb +0 -13
- data/spec/list_type_spec.rb +0 -32
- data/spec/missed_default_spec.rb +0 -14
- data/spec/nested_type_spec.rb +0 -48
- data/spec/optional_spec.rb +0 -71
- data/spec/options_tolerance_spec.rb +0 -11
- data/spec/public_attributes_utility_spec.rb +0 -22
- data/spec/reader_spec.rb +0 -87
- data/spec/repetitive_definitions_spec.rb +0 -69
- data/spec/several_assignments_spec.rb +0 -41
- data/spec/spec_helper.rb +0 -29
- data/spec/subclassing_spec.rb +0 -49
- data/spec/type_argument_spec.rb +0 -35
- data/spec/type_constraint_spec.rb +0 -78
- data/spec/value_coercion_via_dry_types_spec.rb +0 -29
@@ -1,34 +0,0 @@
|
|
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
|
@@ -1,34 +0,0 @@
|
|
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/.gitignore
DELETED
data/.rspec
DELETED
data/.rubocop.yml
DELETED
@@ -1,89 +0,0 @@
|
|
1
|
-
# this file is managed by dry-rb/devtools project
|
2
|
-
|
3
|
-
AllCops:
|
4
|
-
TargetRubyVersion: 2.4
|
5
|
-
|
6
|
-
Style/EachWithObject:
|
7
|
-
Enabled: false
|
8
|
-
|
9
|
-
Style/StringLiterals:
|
10
|
-
Enabled: true
|
11
|
-
EnforcedStyle: single_quotes
|
12
|
-
|
13
|
-
Style/Alias:
|
14
|
-
Enabled: false
|
15
|
-
|
16
|
-
Style/LambdaCall:
|
17
|
-
Enabled: false
|
18
|
-
|
19
|
-
Style/StabbyLambdaParentheses:
|
20
|
-
Enabled: false
|
21
|
-
|
22
|
-
Style/FormatString:
|
23
|
-
Enabled: false
|
24
|
-
|
25
|
-
Style/Documentation:
|
26
|
-
Enabled: false
|
27
|
-
|
28
|
-
Layout/SpaceInLambdaLiteral:
|
29
|
-
Enabled: false
|
30
|
-
|
31
|
-
Layout/MultilineMethodCallIndentation:
|
32
|
-
Enabled: true
|
33
|
-
EnforcedStyle: indented
|
34
|
-
|
35
|
-
Metrics/LineLength:
|
36
|
-
Max: 100
|
37
|
-
|
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:
|
61
|
-
Enabled: false
|
62
|
-
|
63
|
-
Layout/IndentFirstArrayElement:
|
64
|
-
EnforcedStyle: consistent
|
65
|
-
|
66
|
-
Style/ClassAndModuleChildren:
|
67
|
-
Exclude:
|
68
|
-
- "spec/**/*_spec.rb"
|
69
|
-
|
70
|
-
Lint/HandleExceptions:
|
71
|
-
Exclude:
|
72
|
-
- "spec/spec_helper.rb"
|
73
|
-
|
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
|
87
|
-
|
88
|
-
Style/AsciiComments:
|
89
|
-
Enabled: false
|
data/CODE_OF_CONDUCT.md
DELETED
@@ -1,13 +0,0 @@
|
|
1
|
-
# Contributor Code of Conduct
|
2
|
-
|
3
|
-
As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
|
4
|
-
|
5
|
-
We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, age, or religion.
|
6
|
-
|
7
|
-
Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
|
8
|
-
|
9
|
-
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
|
10
|
-
|
11
|
-
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
|
12
|
-
|
13
|
-
This Code of Conduct is adapted from the [Contributor Covenant](http:contributor-covenant.org), version 1.4.0, available at [https://www.contributor-covenant.org/version/1/4/code-of-conduct](https://www.contributor-covenant.org/version/1/4/code-of-conduct)
|
data/CONTRIBUTING.md
DELETED
@@ -1,29 +0,0 @@
|
|
1
|
-
# Issue Guidelines
|
2
|
-
|
3
|
-
## Reporting bugs
|
4
|
-
|
5
|
-
If you found a bug, report an issue and describe what's the expected behavior versus what actually happens. If the bug causes a crash, attach a full backtrace. If possible, a reproduction script showing the problem is highly appreciated.
|
6
|
-
|
7
|
-
## Reporting feature requests
|
8
|
-
|
9
|
-
Report a feature request **only after discussing it first on [discourse.dry-rb.org](https://discourse.dry-rb.org)** where it was accepted. Please provide a concise description of the feature, don't link to a discussion thread, and instead summarize what was discussed.
|
10
|
-
|
11
|
-
## Reporting questions, support requests, ideas, concerns etc.
|
12
|
-
|
13
|
-
**PLEASE DON'T** - use [discourse.dry-rb.org](http://discourse.dry-rb.org) instead.
|
14
|
-
|
15
|
-
# Pull Request Guidelines
|
16
|
-
|
17
|
-
A Pull Request will only be accepted if it addresses a specific issue that was reported previously, or fixes typos, mistakes in documentation etc.
|
18
|
-
|
19
|
-
Other requirements:
|
20
|
-
|
21
|
-
1) Do not open a pull request if you can't provide tests along with it. If you have problems writing tests, ask for help in the related issue.
|
22
|
-
2) Follow the style conventions of the surrounding code. In most cases, this is standard ruby style.
|
23
|
-
3) Add API documentation if it's a new feature
|
24
|
-
4) Update API documentation if it changes an existing feature
|
25
|
-
5) Bonus points for sending a PR to [github.com/dry-rb/dry-rb.org](github.com/dry-rb/dry-rb.org) which updates user documentation and guides
|
26
|
-
|
27
|
-
# Asking for help
|
28
|
-
|
29
|
-
If these guidelines aren't helpful, and you're stuck, please post a message on [discourse.dry-rb.org](https://discourse.dry-rb.org) or join [our chat](https://dry-rb.zulipchat.com).
|
data/Gemfile
DELETED
@@ -1,38 +0,0 @@
|
|
1
|
-
source "https://rubygems.org"
|
2
|
-
|
3
|
-
# Specify your gem"s dependencies in dry-initializer.gemspec
|
4
|
-
gemspec
|
5
|
-
|
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
|
13
|
-
|
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
|
26
|
-
end
|
27
|
-
|
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
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
group :test do
|
37
|
-
gem 'simplecov', require: false
|
38
|
-
end
|
data/Guardfile
DELETED
data/LICENSE.txt
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
The MIT License (MIT)
|
2
|
-
|
3
|
-
Copyright (c) 2016-2017 Andrew Kozin (nepalez), Vladimir Kochnev (marshall-lee)
|
4
|
-
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
7
|
-
in the Software without restriction, including without limitation the rights
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
10
|
-
furnished to do so, subject to the following conditions:
|
11
|
-
|
12
|
-
The above copyright notice and this permission notice shall be included in
|
13
|
-
all copies or substantial portions of the Software.
|
14
|
-
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
-
THE SOFTWARE.
|
data/Rakefile
DELETED
@@ -1,82 +0,0 @@
|
|
1
|
-
Bundler.require(:benchmarks)
|
2
|
-
|
3
|
-
require "dry-initializer"
|
4
|
-
class WithoutDefaults
|
5
|
-
extend Dry::Initializer
|
6
|
-
|
7
|
-
param :foo
|
8
|
-
param :bar
|
9
|
-
param :baz
|
10
|
-
end
|
11
|
-
|
12
|
-
class WithOneDefault
|
13
|
-
extend Dry::Initializer
|
14
|
-
|
15
|
-
param :foo
|
16
|
-
param :bar
|
17
|
-
param :baz, default: proc { "BAZ" }
|
18
|
-
end
|
19
|
-
|
20
|
-
class WithTwoDefaults
|
21
|
-
extend Dry::Initializer
|
22
|
-
|
23
|
-
param :foo
|
24
|
-
param :bar, default: proc { "BAR" }
|
25
|
-
param :baz, default: proc { "BAZ" }
|
26
|
-
end
|
27
|
-
|
28
|
-
class WithThreeDefaults
|
29
|
-
extend Dry::Initializer
|
30
|
-
|
31
|
-
param :foo, default: proc { "FOO" }
|
32
|
-
param :bar, default: proc { "BAR" }
|
33
|
-
param :baz, default: proc { "BAZ" }
|
34
|
-
end
|
35
|
-
|
36
|
-
puts "Benchmark for various options"
|
37
|
-
|
38
|
-
Benchmark.ips do |x|
|
39
|
-
x.config time: 15, warmup: 10
|
40
|
-
|
41
|
-
x.report("without defaults") do
|
42
|
-
WithoutDefaults.new "FOO", "BAR", "BAZ"
|
43
|
-
end
|
44
|
-
|
45
|
-
x.report("with 0 of 1 default used") do
|
46
|
-
WithOneDefault.new "FOO", "BAR", "BAZ"
|
47
|
-
end
|
48
|
-
|
49
|
-
x.report("with 1 of 1 default used") do
|
50
|
-
WithOneDefault.new "FOO", "BAR"
|
51
|
-
end
|
52
|
-
|
53
|
-
x.report("with 0 of 2 defaults used") do
|
54
|
-
WithTwoDefaults.new "FOO", "BAR", "BAZ"
|
55
|
-
end
|
56
|
-
|
57
|
-
x.report("with 1 of 2 defaults used") do
|
58
|
-
WithTwoDefaults.new "FOO", "BAR"
|
59
|
-
end
|
60
|
-
|
61
|
-
x.report("with 2 of 2 defaults used") do
|
62
|
-
WithTwoDefaults.new "FOO"
|
63
|
-
end
|
64
|
-
|
65
|
-
x.report("with 0 of 3 defaults used") do
|
66
|
-
WithThreeDefaults.new "FOO", "BAR", "BAZ"
|
67
|
-
end
|
68
|
-
|
69
|
-
x.report("with 1 of 3 defaults used") do
|
70
|
-
WithThreeDefaults.new "FOO", "BAR"
|
71
|
-
end
|
72
|
-
|
73
|
-
x.report("with 2 of 3 defaults used") do
|
74
|
-
WithThreeDefaults.new "FOO"
|
75
|
-
end
|
76
|
-
|
77
|
-
x.report("with 3 of 3 defaults used") do
|
78
|
-
WithThreeDefaults.new
|
79
|
-
end
|
80
|
-
|
81
|
-
x.compare!
|
82
|
-
end
|
data/benchmarks/plain_options.rb
DELETED
@@ -1,63 +0,0 @@
|
|
1
|
-
Bundler.require(:benchmarks)
|
2
|
-
|
3
|
-
require "dry-initializer"
|
4
|
-
class DryTest
|
5
|
-
extend Dry::Initializer[undefined: false]
|
6
|
-
|
7
|
-
option :foo
|
8
|
-
option :bar
|
9
|
-
end
|
10
|
-
|
11
|
-
class DryTestUndefined
|
12
|
-
extend Dry::Initializer
|
13
|
-
|
14
|
-
option :foo
|
15
|
-
option :bar
|
16
|
-
end
|
17
|
-
|
18
|
-
class PlainRubyTest
|
19
|
-
attr_reader :foo, :bar
|
20
|
-
|
21
|
-
def initialize(options = {})
|
22
|
-
@foo = options[:foo]
|
23
|
-
@bar = options[:bar]
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
require "anima"
|
28
|
-
class AnimaTest
|
29
|
-
include Anima.new(:foo, :bar)
|
30
|
-
end
|
31
|
-
|
32
|
-
require "kwattr"
|
33
|
-
class KwattrTest
|
34
|
-
kwattr :foo, :bar
|
35
|
-
end
|
36
|
-
|
37
|
-
puts "Benchmark for instantiation with plain options"
|
38
|
-
|
39
|
-
Benchmark.ips do |x|
|
40
|
-
x.config time: 15, warmup: 10
|
41
|
-
|
42
|
-
x.report("plain Ruby") do
|
43
|
-
PlainRubyTest.new foo: "FOO", bar: "BAR"
|
44
|
-
end
|
45
|
-
|
46
|
-
x.report("dry-initializer") do
|
47
|
-
DryTest.new foo: "FOO", bar: "BAR"
|
48
|
-
end
|
49
|
-
|
50
|
-
x.report("dry-initializer (with UNDEFINED)") do
|
51
|
-
DryTestUndefined.new foo: "FOO", bar: "BAR"
|
52
|
-
end
|
53
|
-
|
54
|
-
x.report("anima") do
|
55
|
-
AnimaTest.new foo: "FOO", bar: "BAR"
|
56
|
-
end
|
57
|
-
|
58
|
-
x.report("kwattr") do
|
59
|
-
KwattrTest.new foo: "FOO", bar: "BAR"
|
60
|
-
end
|
61
|
-
|
62
|
-
x.compare!
|
63
|
-
end
|
data/benchmarks/plain_params.rb
DELETED
@@ -1,84 +0,0 @@
|
|
1
|
-
Bundler.require(:benchmarks)
|
2
|
-
|
3
|
-
require "dry-initializer"
|
4
|
-
class DryTest
|
5
|
-
extend Dry::Initializer[undefined: false]
|
6
|
-
|
7
|
-
param :foo
|
8
|
-
param :bar
|
9
|
-
end
|
10
|
-
|
11
|
-
class DryTestUndefined
|
12
|
-
extend Dry::Initializer
|
13
|
-
|
14
|
-
param :foo
|
15
|
-
param :bar
|
16
|
-
end
|
17
|
-
|
18
|
-
class PlainRubyTest
|
19
|
-
attr_reader :foo, :bar
|
20
|
-
|
21
|
-
def initialize(foo, bar)
|
22
|
-
@foo = foo
|
23
|
-
@bar = bar
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
StructTest = Struct.new(:foo, :bar)
|
28
|
-
|
29
|
-
require "concord"
|
30
|
-
class ConcordTest
|
31
|
-
include Concord.new(:foo, :bar)
|
32
|
-
end
|
33
|
-
|
34
|
-
require "values"
|
35
|
-
ValueTest = Value.new(:foo, :bar)
|
36
|
-
|
37
|
-
require "value_struct"
|
38
|
-
ValueStructTest = ValueStruct.new(:foo, :bar)
|
39
|
-
|
40
|
-
require "attr_extras"
|
41
|
-
class AttrExtrasText
|
42
|
-
attr_initialize :foo, :bar
|
43
|
-
attr_reader :foo, :bar
|
44
|
-
end
|
45
|
-
|
46
|
-
puts "Benchmark for instantiation with plain params"
|
47
|
-
|
48
|
-
Benchmark.ips do |x|
|
49
|
-
x.config time: 15, warmup: 10
|
50
|
-
|
51
|
-
x.report("plain Ruby") do
|
52
|
-
PlainRubyTest.new "FOO", "BAR"
|
53
|
-
end
|
54
|
-
|
55
|
-
x.report("Core Struct") do
|
56
|
-
StructTest.new "FOO", "BAR"
|
57
|
-
end
|
58
|
-
|
59
|
-
x.report("values") do
|
60
|
-
ValueTest.new "FOO", "BAR"
|
61
|
-
end
|
62
|
-
|
63
|
-
x.report("value_struct") do
|
64
|
-
ValueStructTest.new "FOO", "BAR"
|
65
|
-
end
|
66
|
-
|
67
|
-
x.report("dry-initializer") do
|
68
|
-
DryTest.new "FOO", "BAR"
|
69
|
-
end
|
70
|
-
|
71
|
-
x.report("dry-initializer (with UNDEFINED)") do
|
72
|
-
DryTestUndefined.new "FOO", "BAR"
|
73
|
-
end
|
74
|
-
|
75
|
-
x.report("concord") do
|
76
|
-
ConcordTest.new "FOO", "BAR"
|
77
|
-
end
|
78
|
-
|
79
|
-
x.report("attr_extras") do
|
80
|
-
AttrExtrasText.new "FOO", "BAR"
|
81
|
-
end
|
82
|
-
|
83
|
-
x.compare!
|
84
|
-
end
|
data/benchmarks/with_coercion.rb
DELETED
@@ -1,71 +0,0 @@
|
|
1
|
-
Bundler.require(:benchmarks)
|
2
|
-
|
3
|
-
require "dry-initializer"
|
4
|
-
class DryTest
|
5
|
-
extend Dry::Initializer[undefined: false]
|
6
|
-
|
7
|
-
option :foo, proc(&:to_s)
|
8
|
-
option :bar, proc(&:to_s)
|
9
|
-
end
|
10
|
-
|
11
|
-
class DryTestUndefined
|
12
|
-
extend Dry::Initializer
|
13
|
-
|
14
|
-
option :foo, proc(&:to_s)
|
15
|
-
option :bar, proc(&:to_s)
|
16
|
-
end
|
17
|
-
|
18
|
-
class PlainRubyTest
|
19
|
-
attr_reader :foo, :bar
|
20
|
-
|
21
|
-
def initialize(options)
|
22
|
-
@foo = options[:foo].to_s
|
23
|
-
@bar = options[:bar].to_s
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
require "virtus"
|
28
|
-
class VirtusTest
|
29
|
-
include Virtus.model
|
30
|
-
|
31
|
-
attribute :foo, String
|
32
|
-
attribute :bar, String
|
33
|
-
end
|
34
|
-
|
35
|
-
require "fast_attributes"
|
36
|
-
class FastAttributesTest
|
37
|
-
extend FastAttributes
|
38
|
-
|
39
|
-
define_attributes initialize: true do
|
40
|
-
attribute :foo, String
|
41
|
-
attribute :bar, String
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
puts "Benchmark for instantiation with coercion"
|
46
|
-
|
47
|
-
Benchmark.ips do |x|
|
48
|
-
x.config time: 15, warmup: 10
|
49
|
-
|
50
|
-
x.report("plain Ruby") do
|
51
|
-
PlainRubyTest.new foo: "FOO", bar: "BAR"
|
52
|
-
end
|
53
|
-
|
54
|
-
x.report("dry-initializer") do
|
55
|
-
DryTest.new foo: "FOO", bar: "BAR"
|
56
|
-
end
|
57
|
-
|
58
|
-
x.report("dry-initializer (with UNDEFINED)") do
|
59
|
-
DryTestUndefined.new foo: "FOO", bar: "BAR"
|
60
|
-
end
|
61
|
-
|
62
|
-
x.report("virtus") do
|
63
|
-
VirtusTest.new foo: "FOO", bar: "BAR"
|
64
|
-
end
|
65
|
-
|
66
|
-
x.report("fast_attributes") do
|
67
|
-
FastAttributesTest.new foo: "FOO", bar: "BAR"
|
68
|
-
end
|
69
|
-
|
70
|
-
x.compare!
|
71
|
-
end
|
data/benchmarks/with_defaults.rb
DELETED
@@ -1,66 +0,0 @@
|
|
1
|
-
Bundler.require(:benchmarks)
|
2
|
-
|
3
|
-
require "dry-initializer"
|
4
|
-
class DryTest
|
5
|
-
extend Dry::Initializer[undefined: false]
|
6
|
-
|
7
|
-
option :foo, default: -> { "FOO" }
|
8
|
-
option :bar, default: -> { "BAR" }
|
9
|
-
end
|
10
|
-
|
11
|
-
class DryTestUndefined
|
12
|
-
extend Dry::Initializer
|
13
|
-
|
14
|
-
option :foo, default: -> { "FOO" }
|
15
|
-
option :bar, default: -> { "BAR" }
|
16
|
-
end
|
17
|
-
|
18
|
-
class PlainRubyTest
|
19
|
-
attr_reader :foo, :bar
|
20
|
-
|
21
|
-
def initialize(foo: "FOO", bar: "BAR")
|
22
|
-
@foo = foo
|
23
|
-
@bar = bar
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
require "kwattr"
|
28
|
-
class KwattrTest
|
29
|
-
kwattr foo: "FOO", bar: "BAR"
|
30
|
-
end
|
31
|
-
|
32
|
-
require "active_attr"
|
33
|
-
class ActiveAttrTest
|
34
|
-
include ActiveAttr::AttributeDefaults
|
35
|
-
|
36
|
-
attribute :foo, default: "FOO"
|
37
|
-
attribute :bar, default: "BAR"
|
38
|
-
end
|
39
|
-
|
40
|
-
puts "Benchmark for instantiation with default values"
|
41
|
-
|
42
|
-
Benchmark.ips do |x|
|
43
|
-
x.config time: 15, warmup: 10
|
44
|
-
|
45
|
-
x.report("plain Ruby") do
|
46
|
-
PlainRubyTest.new
|
47
|
-
end
|
48
|
-
|
49
|
-
x.report("dry-initializer") do
|
50
|
-
DryTest.new
|
51
|
-
end
|
52
|
-
|
53
|
-
x.report("dry-initializer (with UNDEFINED)") do
|
54
|
-
DryTestUndefined.new
|
55
|
-
end
|
56
|
-
|
57
|
-
x.report("kwattr") do
|
58
|
-
KwattrTest.new
|
59
|
-
end
|
60
|
-
|
61
|
-
x.report("active_attr") do
|
62
|
-
ActiveAttrTest.new
|
63
|
-
end
|
64
|
-
|
65
|
-
x.compare!
|
66
|
-
end
|