dry-initializer 3.1.0 → 3.2.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 49644712268c1c8896eb7b9d067d5f3abf65789330d465f0acad780a4f50644e
4
- data.tar.gz: 102ef164a75b9d4849400753a21046d5753217806de6c8963476ef8fafeb780d
3
+ metadata.gz: be50d677121c471c7921e3ad842921e172fa29bef381290012a0f2a4a11980d9
4
+ data.tar.gz: 02cb06be56f166c3eacec5f29ecef2589611123467c23eccd912e44632b50f57
5
5
  SHA512:
6
- metadata.gz: '07780a5de808586056b92a3b9a2f1169f5fea4d7879abd1080fc27a7e6123b22d2a07878e9ca9203995c9f01c3e5a47b030b5dc7004d67a4a540413aabdb5890'
7
- data.tar.gz: e352bf6de1a4aae2cf183be62ef4f64a4c70daf0f329122b0d6cd00a7e6081767aa745e938ae4464e52d322bfb08ce943a3312b4f92e02d87c1b968edf0498c4
6
+ metadata.gz: 83c2f86f9a06c429cd53c4452e200ac85e889ca536140fa83fbeb488e11317d1c0f4585903542d865be713cd44f86a38b1647de096994ae801afa8fed912d117
7
+ data.tar.gz: 8af84416c708e34373d30810f8e04ca4249f0ee6f2ccff6d49dd4a4477112354370c71ce5263dc5c1ff276b107617156377ae186a9ffc53a453753f154695b7b
data/CHANGELOG.md CHANGED
@@ -1,5 +1,26 @@
1
1
  <!--- DO NOT EDIT THIS FILE - IT'S AUTOMATICALLY GENERATED VIA DEVTOOLS --->
2
2
 
3
+ ## 3.2.0 2025-01-01
4
+
5
+
6
+ ### Changed
7
+
8
+ - Set minimal supported Ruby version to 3.1 (@flash-gordon)
9
+ - Exclude block forwarding from `Root#initialize`. This helps
10
+ with tracking down calls that shouldn't pass a block in Ruby 3.4 (see #109) (@flash-gordon)
11
+
12
+
13
+ [Compare v3.1.1...v3.2.0](https://github.com/dry-rb/dry-initializer/compare/v3.1.1...v3.2.0)
14
+
15
+ ## 3.1.1 2022-01-19
16
+
17
+
18
+ ### Changed
19
+
20
+ - Improved error messages were rolled back, they created an implicit dependency on dry-types (@flash-gordon)
21
+
22
+ [Compare v3.1.0...v3.1.1](https://github.com/dry-rb/dry-initializer/compare/v3.1.0...v3.1.1)
23
+
3
24
  ## 3.1.0 2022-01-16
4
25
 
5
26
 
data/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2015-2021 dry-rb team
3
+ Copyright (c) 2015-2025 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,29 +1,21 @@
1
1
  <!--- this file is synced from dry-rb/template-gem project -->
2
2
  [gem]: https://rubygems.org/gems/dry-initializer
3
3
  [actions]: https://github.com/dry-rb/dry-initializer/actions
4
- [codacy]: https://www.codacy.com/gh/dry-rb/dry-initializer
5
- [chat]: https://dry-rb.zulipchat.com
6
- [inchpages]: http://inch-ci.org/github/dry-rb/dry-initializer
7
4
 
8
- # dry-initializer [![Join the chat at https://dry-rb.zulipchat.com](https://img.shields.io/badge/dry--rb-join%20chat-%23346b7a.svg)][chat]
9
-
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]
5
+ # dry-initializer [![Gem Version](https://badge.fury.io/rb/dry-initializer.svg)][gem] [![CI Status](https://github.com/dry-rb/dry-initializer/workflows/ci/badge.svg)][actions]
15
6
 
16
7
  ## Links
17
8
 
18
9
  * [User documentation](https://dry-rb.org/gems/dry-initializer)
19
10
  * [API documentation](http://rubydoc.info/gems/dry-initializer)
11
+ * [Forum](https://discourse.dry-rb.org)
20
12
 
21
13
  ## Supported Ruby versions
22
14
 
23
15
  This library officially supports the following Ruby versions:
24
16
 
25
- * MRI `>= 2.7.0`
26
- * jruby `>= 9.3` (postponed until 2.7 is supported)
17
+ * MRI `>= 3.1.0`
18
+ * jruby `>= 9.4` (not tested on CI)
27
19
 
28
20
  ## License
29
21
 
@@ -22,11 +22,11 @@ Gem::Specification.new do |spec|
22
22
  spec.require_paths = ["lib"]
23
23
 
24
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"
25
+ spec.metadata["changelog_uri"] = "https://github.com/dry-rb/dry-initializer/blob/main/CHANGELOG.md"
26
26
  spec.metadata["source_code_uri"] = "https://github.com/dry-rb/dry-initializer"
27
27
  spec.metadata["bug_tracker_uri"] = "https://github.com/dry-rb/dry-initializer/issues"
28
28
 
29
- spec.required_ruby_version = ">= 2.7.0"
29
+ spec.required_ruby_version = ">= 3.1.0"
30
30
 
31
31
  # to update dependencies edit project.yml
32
32
 
@@ -53,7 +53,7 @@ module Dry
53
53
 
54
54
  def required_reader
55
55
  "#{@val} = #{@opts}.fetch(:'#{@source}')" \
56
- " { raise KeyError, \"\#{self.class}: #{@definition} is required\" }"
56
+ " { raise KeyError, \"\#{self.class}: #{@definition} is required\" }"
57
57
  end
58
58
 
59
59
  def definition_line
@@ -72,23 +72,17 @@ module Dry
72
72
  return unless @type
73
73
 
74
74
  arity = @type.is_a?(Proc) ? @type.arity : @type.method(:call).arity
75
- type_call_params = \
76
- arity.equal?(1) || arity.negative? ? @val : "#{@val}, self"
77
-
78
- <<-COERCE
79
- begin
80
- unless #{@null} == #{@val}
81
- #{@val} = #{@item}.type.call(#{type_call_params})
82
- end
83
- rescue Dry::Types::ConstraintError => e
84
- raise Dry::Initializer::CoercionError.new(e, '#{@source}')
85
- end
86
- COERCE
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
87
81
  end
88
82
 
89
83
  def assignment_line
90
84
  "#{@ivar} = #{@val}" \
91
- " unless #{@null} == #{@val} && instance_variable_defined?(:#{@ivar})"
85
+ " unless #{@null} == #{@val} && instance_variable_defined?(:#{@ivar})"
92
86
  end
93
87
  end
94
88
  end
@@ -35,7 +35,7 @@ module Dry
35
35
 
36
36
  def undef_line
37
37
  "undef :__dry_initializer_initialize__" \
38
- " if private_method_defined? :__dry_initializer_initialize__"
38
+ " if private_method_defined? :__dry_initializer_initialize__"
39
39
  end
40
40
 
41
41
  def define_line
@@ -28,8 +28,8 @@ module Dry
28
28
 
29
29
  def undef_line
30
30
  "undef :#{@target} if method_defined?(:#{@target})" \
31
- " || private_method_defined?(:#{@target})" \
32
- " || protected_method_defined?(:#{@target})"
31
+ " || private_method_defined?(:#{@target})" \
32
+ " || protected_method_defined?(:#{@target})"
33
33
  end
34
34
 
35
35
  def attribute_line
@@ -109,7 +109,7 @@ module Dry
109
109
  def finalize
110
110
  @definitions = final_definitions
111
111
  check_order_of_params
112
- mixin.class_eval(code)
112
+ mixin.class_eval(code, "#{__FILE__}:#{__LINE__} class_eval")
113
113
  children.each(&:finalize)
114
114
  self
115
115
  end
@@ -140,11 +140,11 @@ module Dry
140
140
  def add_definition(option, name, type, block, **opts)
141
141
  opts = {
142
142
  parent: extended_class,
143
- option: option,
144
- null: null,
143
+ option:,
144
+ null:,
145
145
  source: name,
146
- type: type,
147
- block: block,
146
+ type:,
147
+ block:,
148
148
  **opts
149
149
  }
150
150
 
@@ -177,7 +177,7 @@ module Dry
177
177
  current
178
178
  elsif optional
179
179
  raise SyntaxError, "#{extended_class}: required #{current}" \
180
- " goes after optional #{optional}"
180
+ " goes after optional #{optional}"
181
181
  else
182
182
  optional
183
183
  end
@@ -18,11 +18,11 @@ module Dry
18
18
  def options
19
19
  {
20
20
  as: target,
21
- type: type,
22
- optional: optional,
23
- default: default,
24
- reader: reader,
25
- desc: desc
21
+ type:,
22
+ optional:,
23
+ default:,
24
+ reader:,
25
+ desc:
26
26
  }.compact
27
27
  end
28
28
 
@@ -19,7 +19,7 @@ module Dry
19
19
  check_certainty!(source, type, block)
20
20
  check_name!(target, block)
21
21
  type ||= build_nested_type(parent, target, block)
22
- {parent: parent, source: source, target: target, type: type, **options}
22
+ {parent:, source:, target:, type:, **options}
23
23
  end
24
24
  # rubocop: enable Metrics/ParameterLists
25
25
 
@@ -58,7 +58,6 @@ module Dry
58
58
 
59
59
  def build_struct(klass_name, block)
60
60
  # rubocop: disable Security/Eval
61
- # rubocop: disable Style/DocumentDynamicEvalDefinition
62
61
  eval <<~RUBY, TOPLEVEL_BINDING, __FILE__, __LINE__ + 1
63
62
  class #{klass_name} < Dry::Initializer::Struct
64
63
  end
@@ -12,7 +12,7 @@ module Dry
12
12
  check_if_callable! source, type
13
13
  check_arity! source, type, wrap
14
14
 
15
- {source: source, type: type, wrap: wrap, **options}
15
+ {source:, type:, wrap:, **options}
16
16
  end
17
17
 
18
18
  private
@@ -14,7 +14,7 @@ module Dry
14
14
  default = callable! default
15
15
  check_arity! default
16
16
 
17
- {default: default, optional: (optional | default), **options}
17
+ {default:, optional: (optional | default), **options}
18
18
  end
19
19
 
20
20
  private
@@ -38,8 +38,8 @@ module Dry
38
38
 
39
39
  def invalid!(default)
40
40
  raise TypeError, "The #{default.inspect} should be" \
41
- " either convertable to proc with no arguments," \
42
- " or respond to #call without arguments."
41
+ " either convertable to proc with no arguments," \
42
+ " or respond to #call without arguments."
43
43
  end
44
44
  end
45
45
  end
@@ -11,7 +11,7 @@ module Dry
11
11
  def call(target:, **options)
12
12
  ivar = "@#{target}".delete("?").to_sym
13
13
 
14
- {target: target, ivar: ivar, **options}
14
+ {target:, ivar:, **options}
15
15
  end
16
16
  end
17
17
  end
@@ -12,7 +12,7 @@ module Dry
12
12
  optional ||= default
13
13
  optional &&= !required
14
14
 
15
- {optional: !!optional, default: default, **options}
15
+ {optional: !!optional, default:, **options}
16
16
  end
17
17
  end
18
18
  end
@@ -16,7 +16,7 @@ module Dry
16
16
  else invalid_reader!(target, reader)
17
17
  end
18
18
 
19
- {target: target, reader: reader, **options}
19
+ {target:, reader:, **options}
20
20
  end
21
21
 
22
22
  private
@@ -27,7 +27,7 @@ module Dry
27
27
  check_ruby_name!(target)
28
28
  check_reserved_names!(target)
29
29
 
30
- {source: source, target: target, **options}
30
+ {source:, target:, **options}
31
31
  end
32
32
 
33
33
  private
@@ -15,7 +15,7 @@ module Dry
15
15
  def call(type: nil, wrap: 0, **options)
16
16
  type, count = unwrap(type, wrap)
17
17
 
18
- {type: type, wrap: count, **options}
18
+ {type:, wrap: count, **options}
19
19
  end
20
20
 
21
21
  private
@@ -9,7 +9,7 @@
9
9
  # - `:source` -- the name of source option
10
10
  # - `:target` -- the target name of the reader
11
11
  # - `:reader` -- if the reader's privacy (:public, :protected, :private, nil)
12
- # - `:ivar` -- the target nane of the variable
12
+ # - `:ivar` -- the target name of the variable
13
13
  # - `:type` -- the callable coercer of the source value
14
14
  # - `:optional` -- if the argument is optional
15
15
  # - `:default` -- the proc returning the default value of the source value
@@ -88,7 +88,7 @@ module Dry
88
88
  # @return [Hash<Symbol, Objct>] normalized set of options
89
89
  #
90
90
  def call(**options)
91
- options = {null: null, **options}
91
+ options = {null:, **options}
92
92
  pipeline.reduce(options) { |opts, dispatcher| dispatcher.call(**opts) }
93
93
  end
94
94
 
@@ -25,8 +25,8 @@ module Dry
25
25
  # @return [Module]
26
26
  # @yield proc defining params and options
27
27
  def define(procedure = nil, &block)
28
- config = Config.new(null: null)
29
- config.instance_exec(&(procedure || block))
28
+ config = Config.new(null:)
29
+ config.instance_exec(&procedure || block)
30
30
  config.mixin.include Mixin::Root
31
31
  config.mixin
32
32
  end
@@ -34,7 +34,7 @@ module Dry
34
34
  private
35
35
 
36
36
  def extended(klass)
37
- config = Config.new(klass, null: null)
37
+ config = Config.new(klass, null:)
38
38
  klass.send :instance_variable_set, :@dry_initializer, config
39
39
  klass.include Mixin::Root
40
40
  end
@@ -7,8 +7,8 @@ module Dry
7
7
  module Root
8
8
  private
9
9
 
10
- def initialize(...)
11
- __dry_initializer_initialize__(...)
10
+ def initialize(*args, **kwargs)
11
+ __dry_initializer_initialize__(*args, **kwargs)
12
12
  end
13
13
  end
14
14
  end
@@ -9,7 +9,7 @@ module Dry
9
9
  # @deprecated
10
10
  def self.extended(klass)
11
11
  warn "[DEPRECATED] Use Dry::Initializer instead of its alias" \
12
- " Dry::Initializer::Mixin. The later will be removed in v2.1.0"
12
+ " Dry::Initializer::Mixin. The later will be removed in v2.1.0"
13
13
  super
14
14
  end
15
15
 
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Dry
4
4
  module Initializer
5
- VERSION = "3.1.0"
5
+ VERSION = "3.2.0"
6
6
  end
7
7
  end
@@ -15,7 +15,6 @@ module Dry
15
15
  require_relative "initializer/config"
16
16
  require_relative "initializer/mixin"
17
17
  require_relative "initializer/dispatchers"
18
- require_relative "initializer/errors"
19
18
 
20
19
  # Adds methods [.[]] and [.define]
21
20
  extend DSL
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dry-initializer
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.1.0
4
+ version: 3.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vladimir Kochnev (marshall-lee)
8
8
  - Andrew Kozin (nepalez)
9
- autorequire:
9
+ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2022-01-16 00:00:00.000000000 Z
12
+ date: 2025-01-01 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
@@ -71,7 +71,6 @@ files:
71
71
  - lib/dry/initializer/dispatchers/unwrap_type.rb
72
72
  - lib/dry/initializer/dispatchers/wrap_type.rb
73
73
  - lib/dry/initializer/dsl.rb
74
- - lib/dry/initializer/errors.rb
75
74
  - lib/dry/initializer/mixin.rb
76
75
  - lib/dry/initializer/mixin/local.rb
77
76
  - lib/dry/initializer/mixin/root.rb
@@ -85,10 +84,10 @@ licenses:
85
84
  - MIT
86
85
  metadata:
87
86
  allowed_push_host: https://rubygems.org
88
- changelog_uri: https://github.com/dry-rb/dry-initializer/blob/master/CHANGELOG.md
87
+ changelog_uri: https://github.com/dry-rb/dry-initializer/blob/main/CHANGELOG.md
89
88
  source_code_uri: https://github.com/dry-rb/dry-initializer
90
89
  bug_tracker_uri: https://github.com/dry-rb/dry-initializer/issues
91
- post_install_message:
90
+ post_install_message:
92
91
  rdoc_options: []
93
92
  require_paths:
94
93
  - lib
@@ -96,15 +95,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
96
95
  requirements:
97
96
  - - ">="
98
97
  - !ruby/object:Gem::Version
99
- version: 2.7.0
98
+ version: 3.1.0
100
99
  required_rubygems_version: !ruby/object:Gem::Requirement
101
100
  requirements:
102
101
  - - ">="
103
102
  - !ruby/object:Gem::Version
104
103
  version: '0'
105
104
  requirements: []
106
- rubygems_version: 3.1.6
107
- signing_key:
105
+ rubygems_version: 3.3.27
106
+ signing_key:
108
107
  specification_version: 4
109
108
  summary: DSL for declaring params and options of the initializer
110
109
  test_files: []
@@ -1,22 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Dry
4
- module Initializer
5
- class CoercionError < ::StandardError
6
- def initialize(constraint_error, field)
7
- @constraint_error = constraint_error
8
- @field = field
9
- super(message)
10
- end
11
-
12
- # Ensure that the field name is in the error message
13
- def message
14
- if @constraint_error.message =~ /#{@field}/
15
- @constraint_error.message
16
- else
17
- "#{@constraint_error.message} for field :#{@field}"
18
- end
19
- end
20
- end
21
- end
22
- end