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.
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
data/Rakefile CHANGED
@@ -1,8 +1,8 @@
1
- require "bundler/setup"
1
+ require 'bundler/setup'
2
2
  Bundler::GemHelper.install_tasks
3
3
 
4
- require "rspec/core/rake_task"
4
+ require 'rspec/core/rake_task'
5
5
  RSpec::Core::RakeTask.new :default
6
6
 
7
- load "lib/tasks/benchmark.rake"
8
- load "lib/tasks/profile.rake"
7
+ load 'lib/tasks/benchmark.rake'
8
+ load 'lib/tasks/profile.rake'
@@ -1,6 +1,6 @@
1
1
  Bundler.require(:benchmarks)
2
2
 
3
- require "dry-initializer"
3
+ require 'dry-initializer'
4
4
  class WithoutDefaults
5
5
  extend Dry::Initializer
6
6
 
@@ -14,67 +14,67 @@ class WithOneDefault
14
14
 
15
15
  param :foo
16
16
  param :bar
17
- param :baz, default: proc { "BAZ" }
17
+ param :baz, default: proc { 'BAZ' }
18
18
  end
19
19
 
20
20
  class WithTwoDefaults
21
21
  extend Dry::Initializer
22
22
 
23
23
  param :foo
24
- param :bar, default: proc { "BAR" }
25
- param :baz, default: proc { "BAZ" }
24
+ param :bar, default: proc { 'BAR' }
25
+ param :baz, default: proc { 'BAZ' }
26
26
  end
27
27
 
28
28
  class WithThreeDefaults
29
29
  extend Dry::Initializer
30
30
 
31
- param :foo, default: proc { "FOO" }
32
- param :bar, default: proc { "BAR" }
33
- param :baz, default: proc { "BAZ" }
31
+ param :foo, default: proc { 'FOO' }
32
+ param :bar, default: proc { 'BAR' }
33
+ param :baz, default: proc { 'BAZ' }
34
34
  end
35
35
 
36
- puts "Benchmark for various options"
36
+ puts 'Benchmark for various options'
37
37
 
38
38
  Benchmark.ips do |x|
39
39
  x.config time: 15, warmup: 10
40
40
 
41
- x.report("without defaults") do
42
- WithoutDefaults.new "FOO", "BAR", "BAZ"
41
+ x.report('without defaults') do
42
+ WithoutDefaults.new 'FOO', 'BAR', 'BAZ'
43
43
  end
44
44
 
45
- x.report("with 0 of 1 default used") do
46
- WithOneDefault.new "FOO", "BAR", "BAZ"
45
+ x.report('with 0 of 1 default used') do
46
+ WithOneDefault.new 'FOO', 'BAR', 'BAZ'
47
47
  end
48
48
 
49
- x.report("with 1 of 1 default used") do
50
- WithOneDefault.new "FOO", "BAR"
49
+ x.report('with 1 of 1 default used') do
50
+ WithOneDefault.new 'FOO', 'BAR'
51
51
  end
52
52
 
53
- x.report("with 0 of 2 defaults used") do
54
- WithTwoDefaults.new "FOO", "BAR", "BAZ"
53
+ x.report('with 0 of 2 defaults used') do
54
+ WithTwoDefaults.new 'FOO', 'BAR', 'BAZ'
55
55
  end
56
56
 
57
- x.report("with 1 of 2 defaults used") do
58
- WithTwoDefaults.new "FOO", "BAR"
57
+ x.report('with 1 of 2 defaults used') do
58
+ WithTwoDefaults.new 'FOO', 'BAR'
59
59
  end
60
60
 
61
- x.report("with 2 of 2 defaults used") do
62
- WithTwoDefaults.new "FOO"
61
+ x.report('with 2 of 2 defaults used') do
62
+ WithTwoDefaults.new 'FOO'
63
63
  end
64
64
 
65
- x.report("with 0 of 3 defaults used") do
66
- WithThreeDefaults.new "FOO", "BAR", "BAZ"
65
+ x.report('with 0 of 3 defaults used') do
66
+ WithThreeDefaults.new 'FOO', 'BAR', 'BAZ'
67
67
  end
68
68
 
69
- x.report("with 1 of 3 defaults used") do
70
- WithThreeDefaults.new "FOO", "BAR"
69
+ x.report('with 1 of 3 defaults used') do
70
+ WithThreeDefaults.new 'FOO', 'BAR'
71
71
  end
72
72
 
73
- x.report("with 2 of 3 defaults used") do
74
- WithThreeDefaults.new "FOO"
73
+ x.report('with 2 of 3 defaults used') do
74
+ WithThreeDefaults.new 'FOO'
75
75
  end
76
76
 
77
- x.report("with 3 of 3 defaults used") do
77
+ x.report('with 3 of 3 defaults used') do
78
78
  WithThreeDefaults.new
79
79
  end
80
80
 
@@ -1,6 +1,6 @@
1
1
  Bundler.require(:benchmarks)
2
2
 
3
- require "dry-initializer"
3
+ require 'dry-initializer'
4
4
  class DryTest
5
5
  extend Dry::Initializer[undefined: false]
6
6
 
@@ -24,39 +24,39 @@ class PlainRubyTest
24
24
  end
25
25
  end
26
26
 
27
- require "anima"
27
+ require 'anima'
28
28
  class AnimaTest
29
29
  include Anima.new(:foo, :bar)
30
30
  end
31
31
 
32
- require "kwattr"
32
+ require 'kwattr'
33
33
  class KwattrTest
34
34
  kwattr :foo, :bar
35
35
  end
36
36
 
37
- puts "Benchmark for instantiation with plain options"
37
+ puts 'Benchmark for instantiation with plain options'
38
38
 
39
39
  Benchmark.ips do |x|
40
40
  x.config time: 15, warmup: 10
41
41
 
42
- x.report("plain Ruby") do
43
- PlainRubyTest.new foo: "FOO", bar: "BAR"
42
+ x.report('plain Ruby') do
43
+ PlainRubyTest.new foo: 'FOO', bar: 'BAR'
44
44
  end
45
45
 
46
- x.report("dry-initializer") do
47
- DryTest.new foo: "FOO", bar: "BAR"
46
+ x.report('dry-initializer') do
47
+ DryTest.new foo: 'FOO', bar: 'BAR'
48
48
  end
49
49
 
50
- x.report("dry-initializer (with UNDEFINED)") do
51
- DryTestUndefined.new foo: "FOO", bar: "BAR"
50
+ x.report('dry-initializer (with UNDEFINED)') do
51
+ DryTestUndefined.new foo: 'FOO', bar: 'BAR'
52
52
  end
53
53
 
54
- x.report("anima") do
55
- AnimaTest.new foo: "FOO", bar: "BAR"
54
+ x.report('anima') do
55
+ AnimaTest.new foo: 'FOO', bar: 'BAR'
56
56
  end
57
57
 
58
- x.report("kwattr") do
59
- KwattrTest.new foo: "FOO", bar: "BAR"
58
+ x.report('kwattr') do
59
+ KwattrTest.new foo: 'FOO', bar: 'BAR'
60
60
  end
61
61
 
62
62
  x.compare!
@@ -1,6 +1,6 @@
1
1
  Bundler.require(:benchmarks)
2
2
 
3
- require "dry-initializer"
3
+ require 'dry-initializer'
4
4
  class DryTest
5
5
  extend Dry::Initializer[undefined: false]
6
6
 
@@ -26,58 +26,58 @@ end
26
26
 
27
27
  StructTest = Struct.new(:foo, :bar)
28
28
 
29
- require "concord"
29
+ require 'concord'
30
30
  class ConcordTest
31
31
  include Concord.new(:foo, :bar)
32
32
  end
33
33
 
34
- require "values"
34
+ require 'values'
35
35
  ValueTest = Value.new(:foo, :bar)
36
36
 
37
- require "value_struct"
37
+ require 'value_struct'
38
38
  ValueStructTest = ValueStruct.new(:foo, :bar)
39
39
 
40
- require "attr_extras"
40
+ require 'attr_extras'
41
41
  class AttrExtrasText
42
42
  attr_initialize :foo, :bar
43
43
  attr_reader :foo, :bar
44
44
  end
45
45
 
46
- puts "Benchmark for instantiation with plain params"
46
+ puts 'Benchmark for instantiation with plain params'
47
47
 
48
48
  Benchmark.ips do |x|
49
49
  x.config time: 15, warmup: 10
50
50
 
51
- x.report("plain Ruby") do
52
- PlainRubyTest.new "FOO", "BAR"
51
+ x.report('plain Ruby') do
52
+ PlainRubyTest.new 'FOO', 'BAR'
53
53
  end
54
54
 
55
- x.report("Core Struct") do
56
- StructTest.new "FOO", "BAR"
55
+ x.report('Core Struct') do
56
+ StructTest.new 'FOO', 'BAR'
57
57
  end
58
58
 
59
- x.report("values") do
60
- ValueTest.new "FOO", "BAR"
59
+ x.report('values') do
60
+ ValueTest.new 'FOO', 'BAR'
61
61
  end
62
62
 
63
- x.report("value_struct") do
64
- ValueStructTest.new "FOO", "BAR"
63
+ x.report('value_struct') do
64
+ ValueStructTest.new 'FOO', 'BAR'
65
65
  end
66
66
 
67
- x.report("dry-initializer") do
68
- DryTest.new "FOO", "BAR"
67
+ x.report('dry-initializer') do
68
+ DryTest.new 'FOO', 'BAR'
69
69
  end
70
70
 
71
- x.report("dry-initializer (with UNDEFINED)") do
72
- DryTestUndefined.new "FOO", "BAR"
71
+ x.report('dry-initializer (with UNDEFINED)') do
72
+ DryTestUndefined.new 'FOO', 'BAR'
73
73
  end
74
74
 
75
- x.report("concord") do
76
- ConcordTest.new "FOO", "BAR"
75
+ x.report('concord') do
76
+ ConcordTest.new 'FOO', 'BAR'
77
77
  end
78
78
 
79
- x.report("attr_extras") do
80
- AttrExtrasText.new "FOO", "BAR"
79
+ x.report('attr_extras') do
80
+ AttrExtrasText.new 'FOO', 'BAR'
81
81
  end
82
82
 
83
83
  x.compare!
@@ -1,6 +1,6 @@
1
1
  Bundler.require(:benchmarks)
2
2
 
3
- require "dry-initializer"
3
+ require 'dry-initializer'
4
4
  class DryTest
5
5
  extend Dry::Initializer[undefined: false]
6
6
 
@@ -24,7 +24,7 @@ class PlainRubyTest
24
24
  end
25
25
  end
26
26
 
27
- require "virtus"
27
+ require 'virtus'
28
28
  class VirtusTest
29
29
  include Virtus.model
30
30
 
@@ -32,7 +32,7 @@ class VirtusTest
32
32
  attribute :bar, String
33
33
  end
34
34
 
35
- require "fast_attributes"
35
+ require 'fast_attributes'
36
36
  class FastAttributesTest
37
37
  extend FastAttributes
38
38
 
@@ -42,29 +42,29 @@ class FastAttributesTest
42
42
  end
43
43
  end
44
44
 
45
- puts "Benchmark for instantiation with coercion"
45
+ puts 'Benchmark for instantiation with coercion'
46
46
 
47
47
  Benchmark.ips do |x|
48
48
  x.config time: 15, warmup: 10
49
49
 
50
- x.report("plain Ruby") do
51
- PlainRubyTest.new foo: "FOO", bar: "BAR"
50
+ x.report('plain Ruby') do
51
+ PlainRubyTest.new foo: 'FOO', bar: 'BAR'
52
52
  end
53
53
 
54
- x.report("dry-initializer") do
55
- DryTest.new foo: "FOO", bar: "BAR"
54
+ x.report('dry-initializer') do
55
+ DryTest.new foo: 'FOO', bar: 'BAR'
56
56
  end
57
57
 
58
- x.report("dry-initializer (with UNDEFINED)") do
59
- DryTestUndefined.new foo: "FOO", bar: "BAR"
58
+ x.report('dry-initializer (with UNDEFINED)') do
59
+ DryTestUndefined.new foo: 'FOO', bar: 'BAR'
60
60
  end
61
61
 
62
- x.report("virtus") do
63
- VirtusTest.new foo: "FOO", bar: "BAR"
62
+ x.report('virtus') do
63
+ VirtusTest.new foo: 'FOO', bar: 'BAR'
64
64
  end
65
65
 
66
- x.report("fast_attributes") do
67
- FastAttributesTest.new foo: "FOO", bar: "BAR"
66
+ x.report('fast_attributes') do
67
+ FastAttributesTest.new foo: 'FOO', bar: 'BAR'
68
68
  end
69
69
 
70
70
  x.compare!
@@ -1,64 +1,64 @@
1
1
  Bundler.require(:benchmarks)
2
2
 
3
- require "dry-initializer"
3
+ require 'dry-initializer'
4
4
  class DryTest
5
5
  extend Dry::Initializer[undefined: false]
6
6
 
7
- option :foo, default: -> { "FOO" }
8
- option :bar, default: -> { "BAR" }
7
+ option :foo, default: -> { 'FOO' }
8
+ option :bar, default: -> { 'BAR' }
9
9
  end
10
10
 
11
11
  class DryTestUndefined
12
12
  extend Dry::Initializer
13
13
 
14
- option :foo, default: -> { "FOO" }
15
- option :bar, default: -> { "BAR" }
14
+ option :foo, default: -> { 'FOO' }
15
+ option :bar, default: -> { 'BAR' }
16
16
  end
17
17
 
18
18
  class PlainRubyTest
19
19
  attr_reader :foo, :bar
20
20
 
21
- def initialize(foo: "FOO", bar: "BAR")
21
+ def initialize(foo: 'FOO', bar: 'BAR')
22
22
  @foo = foo
23
23
  @bar = bar
24
24
  end
25
25
  end
26
26
 
27
- require "kwattr"
27
+ require 'kwattr'
28
28
  class KwattrTest
29
- kwattr foo: "FOO", bar: "BAR"
29
+ kwattr foo: 'FOO', bar: 'BAR'
30
30
  end
31
31
 
32
- require "active_attr"
32
+ require 'active_attr'
33
33
  class ActiveAttrTest
34
34
  include ActiveAttr::AttributeDefaults
35
35
 
36
- attribute :foo, default: "FOO"
37
- attribute :bar, default: "BAR"
36
+ attribute :foo, default: 'FOO'
37
+ attribute :bar, default: 'BAR'
38
38
  end
39
39
 
40
- puts "Benchmark for instantiation with default values"
40
+ puts 'Benchmark for instantiation with default values'
41
41
 
42
42
  Benchmark.ips do |x|
43
43
  x.config time: 15, warmup: 10
44
44
 
45
- x.report("plain Ruby") do
45
+ x.report('plain Ruby') do
46
46
  PlainRubyTest.new
47
47
  end
48
48
 
49
- x.report("dry-initializer") do
49
+ x.report('dry-initializer') do
50
50
  DryTest.new
51
51
  end
52
52
 
53
- x.report("dry-initializer (with UNDEFINED)") do
53
+ x.report('dry-initializer (with UNDEFINED)') do
54
54
  DryTestUndefined.new
55
55
  end
56
56
 
57
- x.report("kwattr") do
57
+ x.report('kwattr') do
58
58
  KwattrTest.new
59
59
  end
60
60
 
61
- x.report("active_attr") do
61
+ x.report('active_attr') do
62
62
  ActiveAttrTest.new
63
63
  end
64
64
 
@@ -1,24 +1,24 @@
1
1
  Bundler.require(:benchmarks)
2
2
 
3
- require "dry-initializer"
3
+ require 'dry-initializer'
4
4
  class DryTest
5
5
  extend Dry::Initializer[undefined: false]
6
6
 
7
- option :foo, proc(&:to_s), default: -> { "FOO" }
8
- option :bar, proc(&:to_s), default: -> { "BAR" }
7
+ option :foo, proc(&:to_s), default: -> { 'FOO' }
8
+ option :bar, proc(&:to_s), default: -> { 'BAR' }
9
9
  end
10
10
 
11
11
  class DryTestUndefined
12
12
  extend Dry::Initializer
13
13
 
14
- option :foo, proc(&:to_s), default: -> { "FOO" }
15
- option :bar, proc(&:to_s), default: -> { "BAR" }
14
+ option :foo, proc(&:to_s), default: -> { 'FOO' }
15
+ option :bar, proc(&:to_s), default: -> { 'BAR' }
16
16
  end
17
17
 
18
18
  class PlainRubyTest
19
19
  attr_reader :foo, :bar
20
20
 
21
- def initialize(foo: "FOO", bar: "BAR")
21
+ def initialize(foo: 'FOO', bar: 'BAR')
22
22
  @foo = foo
23
23
  @bar = bar
24
24
  raise TypeError unless String === @foo
@@ -26,32 +26,32 @@ class PlainRubyTest
26
26
  end
27
27
  end
28
28
 
29
- require "virtus"
29
+ require 'virtus'
30
30
  class VirtusTest
31
31
  include Virtus.model
32
32
 
33
- attribute :foo, String, default: "FOO"
34
- attribute :bar, String, default: "BAR"
33
+ attribute :foo, String, default: 'FOO'
34
+ attribute :bar, String, default: 'BAR'
35
35
  end
36
36
 
37
- puts "Benchmark for instantiation with type constraints and default values"
37
+ puts 'Benchmark for instantiation with type constraints and default values'
38
38
 
39
39
  Benchmark.ips do |x|
40
40
  x.config time: 15, warmup: 10
41
41
 
42
- x.report("plain Ruby") do
42
+ x.report('plain Ruby') do
43
43
  PlainRubyTest.new
44
44
  end
45
45
 
46
- x.report("dry-initializer") do
46
+ x.report('dry-initializer') do
47
47
  DryTest.new
48
48
  end
49
49
 
50
- x.report("dry-initializer (with UNDEFINED)") do
50
+ x.report('dry-initializer (with UNDEFINED)') do
51
51
  DryTest.new
52
52
  end
53
53
 
54
- x.report("virtus") do
54
+ x.report('virtus') do
55
55
  VirtusTest.new
56
56
  end
57
57