dry-initializer 3.0.2 → 3.1.1

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 (89) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +260 -241
  3. data/LICENSE +1 -1
  4. data/README.md +18 -77
  5. data/dry-initializer.gemspec +34 -19
  6. data/lib/dry/initializer/builders/attribute.rb +78 -69
  7. data/lib/dry/initializer/builders/initializer.rb +56 -58
  8. data/lib/dry/initializer/builders/reader.rb +55 -47
  9. data/lib/dry/initializer/builders/signature.rb +29 -23
  10. data/lib/dry/initializer/builders.rb +9 -5
  11. data/lib/dry/initializer/config.rb +162 -158
  12. data/lib/dry/initializer/definition.rb +58 -54
  13. data/lib/dry/initializer/dispatchers/build_nested_type.rb +54 -40
  14. data/lib/dry/initializer/dispatchers/check_type.rb +45 -39
  15. data/lib/dry/initializer/dispatchers/prepare_default.rb +32 -25
  16. data/lib/dry/initializer/dispatchers/prepare_ivar.rb +13 -6
  17. data/lib/dry/initializer/dispatchers/prepare_optional.rb +14 -7
  18. data/lib/dry/initializer/dispatchers/prepare_reader.rb +29 -22
  19. data/lib/dry/initializer/dispatchers/prepare_source.rb +12 -5
  20. data/lib/dry/initializer/dispatchers/prepare_target.rb +44 -37
  21. data/lib/dry/initializer/dispatchers/unwrap_type.rb +21 -10
  22. data/lib/dry/initializer/dispatchers/wrap_type.rb +25 -17
  23. data/lib/dry/initializer/dispatchers.rb +48 -43
  24. data/lib/dry/initializer/dsl.rb +42 -34
  25. data/lib/dry/initializer/mixin/local.rb +19 -13
  26. data/lib/dry/initializer/mixin/root.rb +12 -7
  27. data/lib/dry/initializer/mixin.rb +17 -12
  28. data/lib/dry/initializer/struct.rb +34 -29
  29. data/lib/dry/initializer/undefined.rb +7 -1
  30. data/lib/dry/initializer/version.rb +7 -0
  31. data/lib/dry/initializer.rb +2 -0
  32. data/lib/dry-initializer.rb +2 -0
  33. data/lib/tasks/benchmark.rake +2 -0
  34. data/lib/tasks/profile.rake +4 -0
  35. metadata +25 -125
  36. data/.codeclimate.yml +0 -12
  37. data/.github/ISSUE_TEMPLATE/----please-don-t-ask-for-support-via-issues.md +0 -10
  38. data/.github/ISSUE_TEMPLATE/---bug-report.md +0 -34
  39. data/.github/ISSUE_TEMPLATE/---feature-request.md +0 -18
  40. data/.github/workflows/custom_ci.yml +0 -74
  41. data/.github/workflows/docsite.yml +0 -34
  42. data/.github/workflows/sync_configs.yml +0 -34
  43. data/.gitignore +0 -12
  44. data/.rspec +0 -4
  45. data/.rubocop.yml +0 -89
  46. data/CODE_OF_CONDUCT.md +0 -13
  47. data/CONTRIBUTING.md +0 -29
  48. data/Gemfile +0 -38
  49. data/Guardfile +0 -5
  50. data/LICENSE.txt +0 -21
  51. data/Rakefile +0 -8
  52. data/benchmarks/compare_several_defaults.rb +0 -82
  53. data/benchmarks/plain_options.rb +0 -63
  54. data/benchmarks/plain_params.rb +0 -84
  55. data/benchmarks/with_coercion.rb +0 -71
  56. data/benchmarks/with_defaults.rb +0 -66
  57. data/benchmarks/with_defaults_and_coercion.rb +0 -59
  58. data/docsite/source/attributes.html.md +0 -106
  59. data/docsite/source/container-version.html.md +0 -39
  60. data/docsite/source/index.html.md +0 -43
  61. data/docsite/source/inheritance.html.md +0 -43
  62. data/docsite/source/optionals-and-defaults.html.md +0 -130
  63. data/docsite/source/options-tolerance.html.md +0 -27
  64. data/docsite/source/params-and-options.html.md +0 -74
  65. data/docsite/source/rails-support.html.md +0 -101
  66. data/docsite/source/readers.html.md +0 -43
  67. data/docsite/source/skip-undefined.html.md +0 -59
  68. data/docsite/source/type-constraints.html.md +0 -160
  69. data/spec/attributes_spec.rb +0 -38
  70. data/spec/coercion_of_nil_spec.rb +0 -25
  71. data/spec/custom_dispatchers_spec.rb +0 -35
  72. data/spec/custom_initializer_spec.rb +0 -30
  73. data/spec/default_values_spec.rb +0 -83
  74. data/spec/definition_spec.rb +0 -111
  75. data/spec/invalid_default_spec.rb +0 -13
  76. data/spec/list_type_spec.rb +0 -32
  77. data/spec/missed_default_spec.rb +0 -14
  78. data/spec/nested_type_spec.rb +0 -48
  79. data/spec/optional_spec.rb +0 -71
  80. data/spec/options_tolerance_spec.rb +0 -11
  81. data/spec/public_attributes_utility_spec.rb +0 -22
  82. data/spec/reader_spec.rb +0 -87
  83. data/spec/repetitive_definitions_spec.rb +0 -69
  84. data/spec/several_assignments_spec.rb +0 -41
  85. data/spec/spec_helper.rb +0 -29
  86. data/spec/subclassing_spec.rb +0 -49
  87. data/spec/type_argument_spec.rb +0 -35
  88. data/spec/type_constraint_spec.rb +0 -78
  89. data/spec/value_coercion_via_dry_types_spec.rb +0 -29
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-2021 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,30 @@
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
-
1
+ <!--- this file is synced from dry-rb/template-gem project -->
9
2
  [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
3
+ [actions]: https://github.com/dry-rb/dry-initializer/actions
4
+ [codacy]: https://www.codacy.com/gh/dry-rb/dry-initializer
17
5
  [chat]: https://dry-rb.zulipchat.com
6
+ [inchpages]: http://inch-ci.org/github/dry-rb/dry-initializer
18
7
 
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]
8
+ # dry-initializer [![Join the chat at https://dry-rb.zulipchat.com](https://img.shields.io/badge/dry--rb-join%20chat-%23346b7a.svg)][chat]
69
9
 
70
- ## Benchmarks
10
+ [![Gem Version](https://badge.fury.io/rb/dry-initializer.svg)][gem]
11
+ [![CI Status](https://github.com/dry-rb/dry-initializer/workflows/ci/badge.svg)][actions]
12
+ [![Codacy Badge](https://api.codacy.com/project/badge/Grade/03c8923afd734e9fb0f4bfe9cc893edb)][codacy]
13
+ [![Codacy Badge](https://api.codacy.com/project/badge/Coverage/03c8923afd734e9fb0f4bfe9cc893edb)][codacy]
14
+ [![Inline docs](http://inch-ci.org/github/dry-rb/dry-initializer.svg?branch=master)][inchpages]
71
15
 
72
- The `dry-initializer` is pretty fast for rubies 2.3+ [comparing to other libraries][benchmarks].
16
+ ## Links
73
17
 
74
- ## Compatibility
18
+ * [User documentation](https://dry-rb.org/gems/dry-initializer)
19
+ * [API documentation](http://rubydoc.info/gems/dry-initializer)
75
20
 
76
- Tested under rubies [compatible to MRI 2.3+](.travis.yml).
21
+ ## Supported Ruby versions
77
22
 
78
- ## Contributing
23
+ This library officially supports the following Ruby versions:
79
24
 
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
25
+ * MRI `>= 2.7.0`
26
+ * jruby `>= 9.3` (postponed until 2.7 is supported)
86
27
 
87
28
  ## License
88
29
 
89
- The gem is available as open source under the terms of the [MIT License][license].
30
+ See `LICENSE` file.
@@ -1,20 +1,35 @@
1
- Gem::Specification.new do |gem|
2
- gem.name = "dry-initializer"
3
- gem.version = "3.0.2"
4
- gem.author = ["Vladimir Kochnev (marshall-lee)", "Andrew Kozin (nepalez)"]
5
- gem.email = "andrew.kozin@gmail.com"
6
- gem.homepage = "https://github.com/dry-rb/dry-initializer"
7
- gem.summary = "DSL for declaring params and options of the initializer"
8
- gem.license = "MIT"
9
-
10
- gem.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
11
- gem.test_files = gem.files.grep(/^spec/)
12
- gem.extra_rdoc_files = Dir["README.md", "LICENSE", "CHANGELOG.md"]
13
-
14
- gem.required_ruby_version = ">= 2.3"
15
-
16
- gem.add_development_dependency "rspec", "~> 3.0"
17
- gem.add_development_dependency "rake", "> 10"
18
- gem.add_development_dependency "dry-types", "> 0.5.1"
19
- gem.add_development_dependency "rubocop", "~> 0.49.0"
1
+ # frozen_string_literal: true
2
+
3
+ # this file is synced from dry-rb/template-gem project
4
+
5
+ lib = File.expand_path("lib", __dir__)
6
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
7
+ require "dry/initializer/version"
8
+
9
+ Gem::Specification.new do |spec|
10
+ spec.name = "dry-initializer"
11
+ spec.authors = ["Vladimir Kochnev (marshall-lee)", "Andrew Kozin (nepalez)"]
12
+ spec.email = ["andrew.kozin@gmail.com"]
13
+ spec.license = "MIT"
14
+ spec.version = Dry::Initializer::VERSION.dup
15
+
16
+ spec.summary = "DSL for declaring params and options of the initializer"
17
+ spec.description = spec.summary
18
+ spec.homepage = "https://dry-rb.org/gems/dry-initializer"
19
+ spec.files = Dir["CHANGELOG.md", "LICENSE", "README.md", "dry-initializer.gemspec", "lib/**/*"]
20
+ spec.bindir = "bin"
21
+ spec.executables = []
22
+ spec.require_paths = ["lib"]
23
+
24
+ spec.metadata["allowed_push_host"] = "https://rubygems.org"
25
+ spec.metadata["changelog_uri"] = "https://github.com/dry-rb/dry-initializer/blob/master/CHANGELOG.md"
26
+ spec.metadata["source_code_uri"] = "https://github.com/dry-rb/dry-initializer"
27
+ spec.metadata["bug_tracker_uri"] = "https://github.com/dry-rb/dry-initializer/issues"
28
+
29
+ spec.required_ruby_version = ">= 2.7.0"
30
+
31
+ # to update dependencies edit project.yml
32
+
33
+ spec.add_development_dependency "rake"
34
+ spec.add_development_dependency "rspec"
20
35
  end
@@ -1,81 +1,90 @@
1
- module Dry::Initializer::Builders
2
- # @private
3
- class Attribute
4
- def self.[](definition)
5
- new(definition).call
6
- end
1
+ # frozen_string_literal: true
7
2
 
8
- def call
9
- lines.compact
10
- end
3
+ module Dry
4
+ module Initializer
5
+ module Builders
6
+ # @private
7
+ class Attribute
8
+ def self.[](definition)
9
+ new(definition).call
10
+ end
11
11
 
12
- private
13
-
14
- # rubocop: disable Metrics/MethodLength
15
- def initialize(definition)
16
- @definition = definition
17
- @option = definition.option
18
- @type = definition.type
19
- @optional = definition.optional
20
- @default = definition.default
21
- @source = definition.source
22
- @ivar = definition.ivar
23
- @null = definition.null ? "Dry::Initializer::UNDEFINED" : "nil"
24
- @opts = "__dry_initializer_options__"
25
- @congif = "__dry_initializer_config__"
26
- @item = "__dry_initializer_definition__"
27
- @val = @option ? "__dry_initializer_value__" : @source
28
- end
29
- # rubocop: enable Metrics/MethodLength
30
-
31
- def lines
32
- [
33
- "",
34
- definition_line,
35
- reader_line,
36
- default_line,
37
- coercion_line,
38
- assignment_line
39
- ]
40
- end
12
+ def call
13
+ lines.compact
14
+ end
41
15
 
42
- def reader_line
43
- return unless @option
44
- @optional ? optional_reader : required_reader
45
- end
16
+ private
46
17
 
47
- def optional_reader
48
- "#{@val} = #{@opts}.fetch(:'#{@source}', #{@null})"
49
- end
18
+ def initialize(definition)
19
+ @definition = definition
20
+ @option = definition.option
21
+ @type = definition.type
22
+ @optional = definition.optional
23
+ @default = definition.default
24
+ @source = definition.source
25
+ @ivar = definition.ivar
26
+ @null = definition.null ? "Dry::Initializer::UNDEFINED" : "nil"
27
+ @opts = "__dry_initializer_options__"
28
+ @congif = "__dry_initializer_config__"
29
+ @item = "__dry_initializer_definition__"
30
+ @val = @option ? "__dry_initializer_value__" : @source
31
+ end
50
32
 
51
- def required_reader
52
- "#{@val} = #{@opts}.fetch(:'#{@source}')" \
53
- " { raise KeyError, \"\#{self.class}: #{@definition} is required\" }"
54
- end
33
+ def lines
34
+ [
35
+ "",
36
+ definition_line,
37
+ reader_line,
38
+ default_line,
39
+ coercion_line,
40
+ assignment_line
41
+ ]
42
+ end
55
43
 
56
- def definition_line
57
- return unless @type || @default
58
- "#{@item} = __dry_initializer_config__.definitions[:'#{@source}']"
59
- end
44
+ def reader_line
45
+ return unless @option
60
46
 
61
- def default_line
62
- return unless @default
63
- "#{@val} = instance_exec(&#{@item}.default) if #{@null} == #{@val}"
64
- end
47
+ @optional ? optional_reader : required_reader
48
+ end
65
49
 
66
- def coercion_line
67
- return unless @type
68
- arity = @type.is_a?(Proc) ? @type.arity : @type.method(:call).arity
69
- if arity.abs == 1
70
- "#{@val} = #{@item}.type.call(#{@val}) unless #{@null} == #{@val}"
71
- else
72
- "#{@val} = #{@item}.type.call(#{@val}, self) unless #{@null} == #{@val}"
73
- end
74
- end
50
+ def optional_reader
51
+ "#{@val} = #{@opts}.fetch(:'#{@source}', #{@null})"
52
+ end
53
+
54
+ def required_reader
55
+ "#{@val} = #{@opts}.fetch(:'#{@source}')" \
56
+ " { raise KeyError, \"\#{self.class}: #{@definition} is required\" }"
57
+ end
58
+
59
+ def definition_line
60
+ return unless @type || @default
61
+
62
+ "#{@item} = __dry_initializer_config__.definitions[:'#{@source}']"
63
+ end
64
+
65
+ def default_line
66
+ return unless @default
75
67
 
76
- def assignment_line
77
- "#{@ivar} = #{@val}" \
78
- " unless #{@null} == #{@val} && instance_variable_defined?(:#{@ivar})"
68
+ "#{@val} = instance_exec(&#{@item}.default) if #{@null} == #{@val}"
69
+ end
70
+
71
+ def coercion_line
72
+ return unless @type
73
+
74
+ arity = @type.is_a?(Proc) ? @type.arity : @type.method(:call).arity
75
+
76
+ if arity.equal?(1) || arity.negative?
77
+ "#{@val} = #{@item}.type.call(#{@val}) unless #{@null} == #{@val}"
78
+ else
79
+ "#{@val} = #{@item}.type.call(#{@val}, self) unless #{@null} == #{@val}"
80
+ end
81
+ end
82
+
83
+ def assignment_line
84
+ "#{@ivar} = #{@val}" \
85
+ " unless #{@null} == #{@val} && instance_variable_defined?(:#{@ivar})"
86
+ end
87
+ end
79
88
  end
80
89
  end
81
90
  end
@@ -1,61 +1,59 @@
1
- module Dry::Initializer::Builders
2
- # @private
3
- class Initializer
4
- require_relative "signature"
5
- require_relative "attribute"
6
-
7
- def self.[](config)
8
- new(config).call
9
- end
10
-
11
- def call
12
- lines.flatten.compact.join("\n")
13
- end
14
-
15
- private
16
-
17
- def initialize(config)
18
- @config = config
19
- @definitions = config.definitions.values
20
- end
21
-
22
- def lines
23
- [
24
- undef_line,
25
- define_line,
26
- params_lines,
27
- options_lines,
28
- end_line
29
- ]
30
- end
31
-
32
- def undef_line
33
- "undef :__dry_initializer_initialize__" \
34
- " if private_method_defined? :__dry_initializer_initialize__"
35
- end
36
-
37
- def define_line
38
- "private def __dry_initializer_initialize__(#{Signature[@config]})"
39
- end
40
-
41
- def params_lines
42
- @definitions.reject(&:option)
43
- .flat_map { |item| Attribute[item] }
44
- .map { |line| " " << line }
45
- end
46
-
47
- def options_lines
48
- @definitions.select(&:option)
49
- .flat_map { |item| Attribute[item] }
50
- .map { |line| " " << line }
51
- end
52
-
53
- def end_line
54
- "end"
55
- end
56
-
57
- def private_line
58
- "private :__dry_initializer_initialize__"
1
+ # frozen_string_literal: true
2
+
3
+ module Dry
4
+ module Initializer
5
+ module Builders
6
+ # @private
7
+ class Initializer
8
+ require_relative "signature"
9
+ require_relative "attribute"
10
+
11
+ def self.[](config)
12
+ new(config).call
13
+ end
14
+
15
+ def call
16
+ lines.flatten.compact.join("\n")
17
+ end
18
+
19
+ private
20
+
21
+ def initialize(config)
22
+ @config = config
23
+ @definitions = config.definitions.values
24
+ end
25
+
26
+ def lines
27
+ [
28
+ undef_line,
29
+ define_line,
30
+ params_lines,
31
+ options_lines,
32
+ end_line
33
+ ]
34
+ end
35
+
36
+ def undef_line
37
+ "undef :__dry_initializer_initialize__" \
38
+ " if private_method_defined? :__dry_initializer_initialize__"
39
+ end
40
+
41
+ def define_line
42
+ "private def __dry_initializer_initialize__(#{Signature[@config]})"
43
+ end
44
+
45
+ def params_lines
46
+ @definitions.reject(&:option).flat_map { Attribute[_1] }.map { " #{_1}" }
47
+ end
48
+
49
+ def options_lines
50
+ @definitions.select(&:option).flat_map { Attribute[_1] }.map { " #{_1}" }
51
+ end
52
+
53
+ def end_line
54
+ "end"
55
+ end
56
+ end
59
57
  end
60
58
  end
61
59
  end
@@ -1,50 +1,58 @@
1
- module Dry::Initializer::Builders
2
- # @private
3
- class Reader
4
- def self.[](definition)
5
- new(definition).call
6
- end
7
-
8
- def call
9
- lines.flatten.compact.join("\n")
10
- end
11
-
12
- private
13
-
14
- def initialize(definition)
15
- @target = definition.target
16
- @ivar = definition.ivar
17
- @null = definition.null
18
- @reader = definition.reader
19
- end
20
-
21
- def lines
22
- [undef_line, attribute_line, method_lines, type_line]
23
- end
24
-
25
- def undef_line
26
- "undef :#{@target} if method_defined?(:#{@target})" \
27
- " || private_method_defined?(:#{@target})" \
28
- " || protected_method_defined?(:#{@target})"
29
- end
30
-
31
- def attribute_line
32
- return unless @reader
33
- "attr_reader :#{@target}" unless @null
34
- end
35
-
36
- def method_lines
37
- return unless @reader
38
- return unless @null
39
- [
40
- "def #{@target}",
41
- " #{@ivar} unless Dry::Initializer::UNDEFINED == #{@ivar}",
42
- "end"
43
- ]
44
- end
45
-
46
- def type_line
47
- "#{@reader} :#{@target}" if %i[private protected].include? @reader
1
+ # frozen_string_literal: true
2
+
3
+ module Dry
4
+ module Initializer
5
+ module Builders
6
+ # @private
7
+ class Reader
8
+ def self.[](definition)
9
+ new(definition).call
10
+ end
11
+
12
+ def call
13
+ lines.flatten.compact.join("\n")
14
+ end
15
+
16
+ private
17
+
18
+ def initialize(definition)
19
+ @target = definition.target
20
+ @ivar = definition.ivar
21
+ @null = definition.null
22
+ @reader = definition.reader
23
+ end
24
+
25
+ def lines
26
+ [undef_line, attribute_line, method_lines, type_line]
27
+ end
28
+
29
+ def undef_line
30
+ "undef :#{@target} if method_defined?(:#{@target})" \
31
+ " || private_method_defined?(:#{@target})" \
32
+ " || protected_method_defined?(:#{@target})"
33
+ end
34
+
35
+ def attribute_line
36
+ return unless @reader
37
+
38
+ "attr_reader :#{@target}" unless @null
39
+ end
40
+
41
+ def method_lines
42
+ return unless @reader
43
+ return unless @null
44
+
45
+ [
46
+ "def #{@target}",
47
+ " #{@ivar} unless Dry::Initializer::UNDEFINED == #{@ivar}",
48
+ "end"
49
+ ]
50
+ end
51
+
52
+ def type_line
53
+ "#{@reader} :#{@target}" if %i[private protected].include? @reader
54
+ end
55
+ end
48
56
  end
49
57
  end
50
58
  end
@@ -1,32 +1,38 @@
1
- module Dry::Initializer::Builders
2
- # @private
3
- class Signature
4
- def self.[](config)
5
- new(config).call
6
- end
1
+ # frozen_string_literal: true
7
2
 
8
- def call
9
- [*required_params, *optional_params, "*", options].compact.join(", ")
10
- end
3
+ module Dry
4
+ module Initializer
5
+ module Builders
6
+ # @private
7
+ class Signature
8
+ def self.[](config)
9
+ new(config).call
10
+ end
11
11
 
12
- private
12
+ def call
13
+ [*required_params, *optional_params, "*", options].compact.join(", ")
14
+ end
13
15
 
14
- def initialize(config)
15
- @config = config
16
- @options = config.options.any?
17
- @null = config.null ? "Dry::Initializer::UNDEFINED" : "nil"
18
- end
16
+ private
19
17
 
20
- def required_params
21
- @config.params.reject(&:optional).map(&:source)
22
- end
18
+ def initialize(config)
19
+ @config = config
20
+ @options = config.options.any?
21
+ @null = config.null ? "Dry::Initializer::UNDEFINED" : "nil"
22
+ end
23
23
 
24
- def optional_params
25
- @config.params.select(&:optional).map { |rec| "#{rec.source} = #{@null}" }
26
- end
24
+ def required_params
25
+ @config.params.reject(&:optional).map(&:source)
26
+ end
27
+
28
+ def optional_params
29
+ @config.params.select(&:optional).map { |rec| "#{rec.source} = #{@null}" }
30
+ end
27
31
 
28
- def options
29
- "**__dry_initializer_options__" if @options
32
+ def options
33
+ "**__dry_initializer_options__" if @options
34
+ end
35
+ end
30
36
  end
31
37
  end
32
38
  end
@@ -1,7 +1,11 @@
1
- module Dry::Initializer
2
- # @private
3
- module Builders
4
- require_relative "builders/reader"
5
- require_relative "builders/initializer"
1
+ # frozen_string_literal: true
2
+
3
+ module Dry
4
+ module Initializer
5
+ # @private
6
+ module Builders
7
+ require_relative "builders/reader"
8
+ require_relative "builders/initializer"
9
+ end
6
10
  end
7
11
  end