dry-initializer 2.5.0 → 3.0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (67) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +367 -239
  3. data/LICENSE +20 -0
  4. data/README.md +17 -79
  5. data/dry-initializer.gemspec +29 -16
  6. data/lib/dry-initializer.rb +1 -1
  7. data/lib/dry/initializer.rb +16 -14
  8. data/lib/dry/initializer/builders.rb +2 -2
  9. data/lib/dry/initializer/builders/attribute.rb +12 -7
  10. data/lib/dry/initializer/builders/initializer.rb +9 -13
  11. data/lib/dry/initializer/builders/reader.rb +3 -1
  12. data/lib/dry/initializer/builders/signature.rb +3 -3
  13. data/lib/dry/initializer/config.rb +22 -8
  14. data/lib/dry/initializer/definition.rb +20 -71
  15. data/lib/dry/initializer/dispatchers.rb +101 -33
  16. data/lib/dry/initializer/dispatchers/build_nested_type.rb +59 -0
  17. data/lib/dry/initializer/dispatchers/check_type.rb +43 -0
  18. data/lib/dry/initializer/dispatchers/prepare_default.rb +40 -0
  19. data/lib/dry/initializer/dispatchers/prepare_ivar.rb +12 -0
  20. data/lib/dry/initializer/dispatchers/prepare_optional.rb +13 -0
  21. data/lib/dry/initializer/dispatchers/prepare_reader.rb +30 -0
  22. data/lib/dry/initializer/dispatchers/prepare_source.rb +28 -0
  23. data/lib/dry/initializer/dispatchers/prepare_target.rb +44 -0
  24. data/lib/dry/initializer/dispatchers/unwrap_type.rb +22 -0
  25. data/lib/dry/initializer/dispatchers/wrap_type.rb +28 -0
  26. data/lib/dry/initializer/mixin.rb +4 -4
  27. data/lib/dry/initializer/mixin/root.rb +1 -0
  28. data/lib/dry/initializer/struct.rb +39 -0
  29. data/lib/dry/initializer/undefined.rb +2 -0
  30. data/lib/dry/initializer/version.rb +5 -0
  31. data/lib/tasks/benchmark.rake +13 -13
  32. data/lib/tasks/profile.rake +16 -16
  33. metadata +38 -103
  34. data/.codeclimate.yml +0 -23
  35. data/.gitignore +0 -10
  36. data/.rspec +0 -4
  37. data/.rubocop.yml +0 -51
  38. data/.travis.yml +0 -24
  39. data/Gemfile +0 -29
  40. data/Guardfile +0 -5
  41. data/LICENSE.txt +0 -21
  42. data/Rakefile +0 -8
  43. data/benchmarks/compare_several_defaults.rb +0 -82
  44. data/benchmarks/plain_options.rb +0 -63
  45. data/benchmarks/plain_params.rb +0 -84
  46. data/benchmarks/with_coercion.rb +0 -71
  47. data/benchmarks/with_defaults.rb +0 -66
  48. data/benchmarks/with_defaults_and_coercion.rb +0 -59
  49. data/spec/attributes_spec.rb +0 -38
  50. data/spec/coercion_of_nil_spec.rb +0 -25
  51. data/spec/custom_dispatchers_spec.rb +0 -35
  52. data/spec/custom_initializer_spec.rb +0 -30
  53. data/spec/default_values_spec.rb +0 -83
  54. data/spec/definition_spec.rb +0 -107
  55. data/spec/invalid_default_spec.rb +0 -13
  56. data/spec/missed_default_spec.rb +0 -14
  57. data/spec/optional_spec.rb +0 -71
  58. data/spec/options_tolerance_spec.rb +0 -11
  59. data/spec/public_attributes_utility_spec.rb +0 -22
  60. data/spec/reader_spec.rb +0 -87
  61. data/spec/repetitive_definitions_spec.rb +0 -69
  62. data/spec/several_assignments_spec.rb +0 -41
  63. data/spec/spec_helper.rb +0 -21
  64. data/spec/subclassing_spec.rb +0 -49
  65. data/spec/type_argument_spec.rb +0 -35
  66. data/spec/type_constraint_spec.rb +0 -78
  67. data/spec/value_coercion_via_dry_types_spec.rb +0 -29
@@ -1,23 +0,0 @@
1
- ---
2
- engines:
3
- rubocop:
4
- 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/**/*"
data/.gitignore DELETED
@@ -1,10 +0,0 @@
1
- /.bundle/
2
- /.yardoc
3
- /Gemfile.lock
4
- /_yardoc/
5
- /coverage/
6
- /doc/
7
- /pkg/
8
- /spec/reports/
9
- /tmp/
10
- /*.gem
data/.rspec DELETED
@@ -1,4 +0,0 @@
1
- --format documentation
2
- --color
3
- --require spec_helper
4
- --warnings
@@ -1,51 +0,0 @@
1
- ---
2
- AllCops:
3
- DisplayCopNames: true
4
- DisplayStyleGuide: true
5
- StyleGuideCopsOnly: true
6
- TargetRubyVersion: 2.3
7
- Exclude:
8
- - lib/tasks/*.rake
9
-
10
- Bundler/DuplicatedGem:
11
- Enabled: false
12
-
13
- Style/CaseEquality:
14
- Enabled: false
15
-
16
- Style/ClassVars:
17
- Enabled: false
18
-
19
- Style/ClassAndModuleChildren:
20
- Enabled: false
21
-
22
- Style/Documentation:
23
- Enabled: false
24
-
25
- Style/DoubleNegation:
26
- Enabled: false
27
-
28
- Style/FileName:
29
- Exclude:
30
- - lib/dry-initializer.rb
31
-
32
- Style/Lambda:
33
- Exclude:
34
- - spec/**/*.rb
35
-
36
- Style/LambdaCall:
37
- Enabled: false
38
-
39
- Style/RescueModified:
40
- Exclude:
41
- - spec/**/*.rb
42
-
43
- Style/Semicolon:
44
- Exclude:
45
- - spec/**/*.rb
46
-
47
- Style/StringLiterals:
48
- EnforcedStyle: double_quotes
49
-
50
- Style/StringLiteralsInInterpolation:
51
- EnforcedStyle: double_quotes
@@ -1,24 +0,0 @@
1
- ---
2
- language: ruby
3
- sudo: false
4
- cache: bundler
5
- bundler_args: --without benchmarks tools
6
- script:
7
- - bundle exec rake spec
8
- rvm:
9
- - 2.3.0
10
- - 2.4.0
11
- - jruby-9000
12
- - rbx-3
13
- - ruby-head
14
- env:
15
- global:
16
- - JRUBY_OPTS='--dev -J-Xmx1024M'
17
- matrix:
18
- allow_failures:
19
- - rvm: rbx-3
20
- - rvm: ruby-head
21
- - rvm: jruby-head
22
- include:
23
- - rvm: jruby-head
24
- before_install: gem install bundler --no-ri --no-rdoc
data/Gemfile DELETED
@@ -1,29 +0,0 @@
1
- source "https://rubygems.org"
2
-
3
- # Specify your gem"s dependencies in dry-initializer.gemspec
4
- gemspec
5
-
6
- group :benchmarks do
7
- if RUBY_VERSION < "2.4"
8
- gem "activesupport", "< 5"
9
- else
10
- gem "activesupport"
11
- end
12
-
13
- gem "active_attr"
14
- gem "anima"
15
- gem "attr_extras"
16
- gem "benchmark-ips", "~> 2.5"
17
- gem "concord"
18
- gem "fast_attributes"
19
- gem "kwattr"
20
- gem "ruby-prof"
21
- gem "value_struct"
22
- gem "values"
23
- gem "virtus"
24
- end
25
-
26
- group :development, :test do
27
- gem "pry", platform: :mri
28
- gem "pry-byebug", platform: :mri
29
- end
data/Guardfile DELETED
@@ -1,5 +0,0 @@
1
- guard :rspec, cmd: "bundle exec rspec" do
2
- watch(%r{^spec/.+_spec\.rb$})
3
- watch(%r{^spec/(spec_helper|support)}) { "spec" }
4
- watch(%r{^lib/.+}) { "spec" }
5
- end
@@ -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,8 +0,0 @@
1
- require "bundler/setup"
2
- Bundler::GemHelper.install_tasks
3
-
4
- require "rspec/core/rake_task"
5
- RSpec::Core::RakeTask.new :default
6
-
7
- load "lib/tasks/benchmark.rake"
8
- load "lib/tasks/profile.rake"
@@ -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
@@ -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
@@ -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
@@ -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