dry-struct 1.4.0 → 1.5.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bf0892469a434b85578e7350f52039b85203dbd251ca5c4bd6b038373edc703e
4
- data.tar.gz: 263e3d2d4ce824be64210a27d074fb42126dde12d94e56290307d9ff08c0efad
3
+ metadata.gz: 4875bdb8501964e23c1a10b3074e4e271fb3313c626f1142fcd357e6946be19d
4
+ data.tar.gz: 1c73644bf0a068cb5c55e4dbb2ada2071446a83563f63e50fd3adb5043cac87d
5
5
  SHA512:
6
- metadata.gz: '08ea5f7780bac10495f93a5043c5e100fc9386688920e4e7fd1b2304ceaeb8f37853f6ed70f5d5a69b1d7a30c0340450f8ce41fba91e812e00cf6a008f9c2de0'
7
- data.tar.gz: da176db2c5d8127ea7ef6a088edf7f8f4d18c74e65d96e7f6a80dd9822c0baefdfa1dd7eb6d607ac077c033d64dcddb0ca6c1498eb411c4cd94ea96e23c701b4
6
+ metadata.gz: 0eab727ee4057dc0c22864cae090cf968cf726d5670b853edac1fcd5f3ba3e9411994e94b6e333de1a3f55c2cc50a9dcaa266a6e704e63e365289280d04f46d4
7
+ data.tar.gz: 0e906ceeec35489db1b5884b45f137019a687ae8fbd1a7c22451350b742ab914c7cf46c1dad5e852994dac9acafb314b32d6118b59cd4bb9f097596f1e112187
data/CHANGELOG.md CHANGED
@@ -1,5 +1,24 @@
1
1
  <!--- DO NOT EDIT THIS FILE - IT'S AUTOMATICALLY GENERATED VIA DEVTOOLS --->
2
2
 
3
+ ## 1.5.1 2022-10-17
4
+
5
+
6
+ ### Fixed
7
+
8
+ - Fixed issues with auto-loading `Extensions` module (issue #183 fixed via #184) (@solnic)
9
+
10
+
11
+ [Compare v1.5.0...v1.5.1](https://github.com/dry-rb/dry-struct/compare/v1.5.0...v1.5.1)
12
+
13
+ ## 1.5.0 2022-10-15
14
+
15
+
16
+ ### Changed
17
+
18
+ - Use zeitwerk for auto-loading (@flash-gordon)
19
+
20
+ [Compare v1.4.0...v1.5.0](https://github.com/dry-rb/dry-struct/compare/v1.4.0...v1.5.0)
21
+
3
22
  ## 1.4.0 2021-01-21
4
23
 
5
24
 
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-2022 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,3 +1,4 @@
1
+ <!--- this file is synced from dry-rb/template-gem project -->
1
2
  [gem]: https://rubygems.org/gems/dry-struct
2
3
  [actions]: https://github.com/dry-rb/dry-struct/actions
3
4
  [codacy]: https://www.codacy.com/gh/dry-rb/dry-struct
@@ -10,19 +11,19 @@
10
11
  [![CI Status](https://github.com/dry-rb/dry-struct/workflows/ci/badge.svg)][actions]
11
12
  [![Codacy Badge](https://api.codacy.com/project/badge/Grade/961f5c776f1d49218b2cede3745e059c)][codacy]
12
13
  [![Codacy Badge](https://api.codacy.com/project/badge/Coverage/961f5c776f1d49218b2cede3745e059c)][codacy]
13
- [![Inline docs](http://inch-ci.org/github/dry-rb/dry-struct.svg?branch=master)][inchpages]
14
+ [![Inline docs](http://inch-ci.org/github/dry-rb/dry-struct.svg?branch=main)][inchpages]
14
15
 
15
16
  ## Links
16
17
 
17
- * [User documentation](http://dry-rb.org/gems/dry-struct)
18
+ * [User documentation](https://dry-rb.org/gems/dry-struct)
18
19
  * [API documentation](http://rubydoc.info/gems/dry-struct)
19
20
 
20
21
  ## Supported Ruby versions
21
22
 
22
23
  This library officially supports the following Ruby versions:
23
24
 
24
- * MRI >= `2.5`
25
- * jruby >= `9.2`
25
+ * MRI `>= 2.7.0`
26
+ * jruby `>= 9.3` (postponed until 2.7 is supported)
26
27
 
27
28
  ## License
28
29
 
data/dry-struct.gemspec CHANGED
@@ -1,36 +1,38 @@
1
1
  # frozen_string_literal: true
2
- # this file is managed by dry-rb/devtools project
3
2
 
4
- lib = File.expand_path('lib', __dir__)
3
+ # this file is synced from dry-rb/template-gem project
4
+
5
+ lib = File.expand_path("lib", __dir__)
5
6
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
6
- require 'dry/struct/version'
7
+ require "dry/struct/version"
7
8
 
8
9
  Gem::Specification.new do |spec|
9
- spec.name = 'dry-struct'
10
+ spec.name = "dry-struct"
10
11
  spec.authors = ["Piotr Solnica"]
11
12
  spec.email = ["piotr.solnica@gmail.com"]
12
- spec.license = 'MIT'
13
+ spec.license = "MIT"
13
14
  spec.version = Dry::Struct::VERSION.dup
14
15
 
15
16
  spec.summary = "Typed structs and value objects"
16
17
  spec.description = spec.summary
17
- spec.homepage = 'https://dry-rb.org/gems/dry-struct'
18
+ spec.homepage = "https://dry-rb.org/gems/dry-struct"
18
19
  spec.files = Dir["CHANGELOG.md", "LICENSE", "README.md", "dry-struct.gemspec", "lib/**/*"]
19
- spec.bindir = 'bin'
20
+ spec.bindir = "bin"
20
21
  spec.executables = []
21
- spec.require_paths = ['lib']
22
+ spec.require_paths = ["lib"]
22
23
 
23
- spec.metadata['allowed_push_host'] = 'https://rubygems.org'
24
- spec.metadata['changelog_uri'] = 'https://github.com/dry-rb/dry-struct/blob/master/CHANGELOG.md'
25
- spec.metadata['source_code_uri'] = 'https://github.com/dry-rb/dry-struct'
26
- spec.metadata['bug_tracker_uri'] = 'https://github.com/dry-rb/dry-struct/issues'
24
+ spec.metadata["allowed_push_host"] = "https://rubygems.org"
25
+ spec.metadata["changelog_uri"] = "https://github.com/dry-rb/dry-struct/blob/main/CHANGELOG.md"
26
+ spec.metadata["source_code_uri"] = "https://github.com/dry-rb/dry-struct"
27
+ spec.metadata["bug_tracker_uri"] = "https://github.com/dry-rb/dry-struct/issues"
27
28
 
28
- spec.required_ruby_version = ">= 2.5.0"
29
+ spec.required_ruby_version = ">= 2.7.0"
29
30
 
30
31
  # to update dependencies edit project.yml
31
- spec.add_runtime_dependency "dry-core", "~> 0.5", ">= 0.5"
32
- spec.add_runtime_dependency "dry-types", "~> 1.5"
32
+ spec.add_runtime_dependency "dry-core", "~> 0.9", ">= 0.9"
33
+ spec.add_runtime_dependency "dry-types", "~> 1.6"
33
34
  spec.add_runtime_dependency "ice_nine", "~> 0.11"
35
+ spec.add_runtime_dependency "zeitwerk", "~> 2.6"
34
36
 
35
37
  spec.add_development_dependency "bundler"
36
38
  spec.add_development_dependency "rake"
@@ -1,18 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "weakref"
4
- require "dry/core/class_attributes"
5
- require "dry/core/inflector"
6
- require "dry/core/descendants_tracker"
7
-
8
- require "dry/struct/errors"
9
- require "dry/struct/constructor"
10
- require "dry/struct/sum"
11
4
 
12
5
  module Dry
13
6
  class Struct
14
7
  # Class-level interface of {Struct} and {Value}
15
- module ClassInterface
8
+ module ClassInterface # rubocop:disable Metrics/ModuleLength
16
9
  include Core::ClassAttributes
17
10
 
18
11
  include Types::Type
@@ -49,8 +42,12 @@ module Dry
49
42
  # end
50
43
  # end
51
44
  #
52
- # Language.schema
53
- # # => #<Dry::Types[Constructor<Schema<keys={name: Constrained<Nominal<String> rule=[type?(String)]> details: Language::Details}> fn=Kernel.Hash>]>
45
+ # Language.schema # new lines for readability
46
+ # # => #<Dry::Types[
47
+ # Constructor<Schema<keys={
48
+ # name: Constrained<Nominal<String> rule=[type?(String)]>
49
+ # details: Language::Details
50
+ # }> fn=Kernel.Hash>]>
54
51
  #
55
52
  # ruby = Language.new(name: 'Ruby', details: { type: 'OO' })
56
53
  # ruby.name #=> 'Ruby'
@@ -67,10 +64,12 @@ module Dry
67
64
  # end
68
65
  # end
69
66
  #
70
- # Language.schema
67
+ # Language.schema # new lines for readability
71
68
  # => #<Dry::Types[Constructor<Schema<keys={
72
69
  # name: Constrained<Nominal<String> rule=[type?(String)]>
73
- # versions: Constrained<Array<Constrained<Nominal<String> rule=[type?(String)]>> rule=[type?(Array)]>
70
+ # versions: Constrained<
71
+ # Array<Constrained<Nominal<String> rule=[type?(String)]>
72
+ # > rule=[type?(Array)]>
74
73
  # celebrities: Constrained<Array<Language::Celebrity> rule=[type?(Array)]>
75
74
  # }> fn=Kernel.Hash>]>
76
75
  #
@@ -151,7 +150,7 @@ module Dry
151
150
  Core::Deprecations.warn(
152
151
  "Dry::Struct.attribute? is deprecated for checking attribute presence, "\
153
152
  "use has_attribute? instead",
154
- tag: :'dry-struct'
153
+ tag: :"dry-struct"
155
154
  )
156
155
 
157
156
  has_attribute?(args[0])
@@ -247,7 +246,7 @@ module Dry
247
246
 
248
247
  # @param [Hash{Symbol => Object},Dry::Struct] attributes
249
248
  # @raise [Struct::Error] if the given attributes don't conform {#schema}
250
- def new(attributes = default_attributes, safe = false, &block)
249
+ def new(attributes = default_attributes, safe = false, &block) # rubocop:disable Style/OptionalBooleanParameter
251
250
  if attributes.is_a?(Struct)
252
251
  if equal?(attributes.class)
253
252
  attributes
@@ -481,10 +480,10 @@ module Dry
481
480
  keys.each do |key|
482
481
  next if instance_methods.include?(key)
483
482
 
484
- class_eval(<<-RUBY)
485
- def #{key}
486
- @attributes[#{key.inspect}]
487
- end
483
+ class_eval(<<-RUBY, __FILE__, __LINE__ + 1)
484
+ def #{key} # def email
485
+ @attributes[#{key.inspect}] # @attributes[:email]
486
+ end # end
488
487
  RUBY
489
488
  end
490
489
  end
@@ -1,8 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "weakref"
4
- require "dry/types/compiler"
5
-
6
3
  module Dry
7
4
  class Struct
8
5
  class Compiler < Types::Compiler
@@ -11,7 +11,7 @@ module Dry
11
11
  column_value = @attributes[column_name]
12
12
  pp.breakable " "
13
13
  pp.group(1) do
14
- pp.text column_name
14
+ pp.text column_name.to_s
15
15
  pp.text "="
16
16
  pp.pp column_value
17
17
  end
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "dry/struct/compiler"
4
-
5
3
  module Dry
6
4
  class Struct
7
5
  # @private
@@ -14,7 +12,8 @@ module Dry
14
12
  end
15
13
 
16
14
  # @param [Symbol|String] attr_name the name of the nested type
17
- # @param [Dry::Struct,Dry::Types::Type::Array,Undefined] type the superclass of the nested struct
15
+ # @param [Dry::Struct,Dry::Types::Type::Array,Undefined] type the superclass
16
+ # of the nested struct
18
17
  # @yield the body of the nested struct
19
18
  def call(attr_name, type, &block)
20
19
  const_name = const_name(type, attr_name)
@@ -1,8 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "dry/types/sum"
4
- require "dry/types/printer"
5
-
6
3
  module Dry
7
4
  class Struct
8
5
  # A sum type of two or more structs
@@ -46,9 +43,9 @@ module Dry
46
43
  protected
47
44
 
48
45
  # @private
49
- def try_struct(input)
46
+ def try_struct(input, &block)
50
47
  left.try_struct(input) do
51
- right.try_struct(input) { yield }
48
+ right.try_struct(input, &block)
52
49
  end
53
50
  end
54
51
  end
@@ -1,11 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "ice_nine"
4
- require "dry/core/deprecations"
5
4
 
6
5
  module Dry
7
6
  class Struct
8
- extend Core::Deprecations[:'dry-struct']
7
+ extend Core::Deprecations[:"dry-struct"]
9
8
 
10
9
  # {Value} objects behave like {Struct}s but *deeply frozen*
11
10
  # using [`ice_nine`](https://github.com/dkubb/ice_nine)
@@ -3,6 +3,6 @@
3
3
  module Dry
4
4
  class Struct
5
5
  # @private
6
- VERSION = "1.4.0"
6
+ VERSION = "1.5.1"
7
7
  end
8
8
  end
data/lib/dry/struct.rb CHANGED
@@ -1,16 +1,13 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "weakref"
4
+
5
+ require "dry/core"
3
6
  require "dry/types"
4
- require "dry/core/equalizer"
5
- require "dry/core/extensions"
6
- require "dry/core/constants"
7
- require "dry/core/deprecations"
8
7
 
9
- require "dry/struct/version"
10
- require "dry/struct/errors"
11
8
  require "dry/struct/class_interface"
12
- require "dry/struct/hashify"
13
- require "dry/struct/struct_builder"
9
+ require "dry/struct/errors"
10
+ require "dry/struct/version"
14
11
 
15
12
  module Dry
16
13
  # Constructor method for easily creating a {Dry::Struct}.
@@ -88,14 +85,28 @@ module Dry
88
85
  extend Core::Extensions
89
86
  include Core::Constants
90
87
  extend ClassInterface
91
- extend Core::Deprecations[:'dry-struct']
88
+ extend Core::Deprecations[:"dry-struct"]
92
89
 
93
90
  class << self
94
91
  # override `Dry::Types::Builder#prepend`
95
92
  define_method(:prepend, ::Module.method(:prepend))
93
+
94
+ def loader
95
+ @loader ||= ::Zeitwerk::Loader.new.tap do |loader|
96
+ root = ::File.expand_path("..", __dir__)
97
+ loader.tag = "dry-struct"
98
+ loader.inflector = ::Zeitwerk::GemInflector.new("#{root}/dry-struct.rb")
99
+ loader.push_dir(root)
100
+ loader.ignore(
101
+ "#{root}/dry-struct.rb",
102
+ "#{root}/dry/struct/{class_interface,errors,extensions,printer,value,version}.rb",
103
+ "#{root}/dry/struct/extensions"
104
+ )
105
+ end
106
+ end
96
107
  end
97
108
 
98
- autoload :Value, "dry/struct/value"
109
+ loader.setup
99
110
 
100
111
  include ::Dry::Equalizer(:__attributes__, inspect: false, immutable: true)
101
112
 
@@ -159,8 +170,8 @@ module Dry
159
170
  result[key.name] = Hashify[self[key.name]] if attributes.key?(key.name)
160
171
  end
161
172
  end
173
+ # TODO: remove in 2.0
162
174
  alias_method :to_hash, :to_h
163
- # deprecate :to_hash, :to_h, message: "Implicit convertion structs to hashes is deprecated. Use .to_h"
164
175
 
165
176
  # Create a copy of {Dry::Struct} with overriden attributes
166
177
  #
@@ -183,7 +194,11 @@ module Dry
183
194
  # rom_n_roda.new(subtitle: '3rd edition')
184
195
  # #=> #<Book title="Web Development with ROM and Roda" subtitle="3rd edition">
185
196
  def new(changeset)
186
- new_attributes = self.class.schema.apply(changeset, skip_missing: true, resolve_defaults: false)
197
+ new_attributes = self.class.schema.apply(
198
+ changeset,
199
+ skip_missing: true,
200
+ resolve_defaults: false
201
+ )
187
202
  self.class.load(__attributes__.merge(new_attributes))
188
203
  rescue Types::SchemaError, Types::MissingKeyError, Types::UnknownKeysError => e
189
204
  raise Error, "[#{self}.new] #{e}"
@@ -197,16 +212,15 @@ module Dry
197
212
  "#<#{klass.name || klass.inspect}#{attrs}>"
198
213
  end
199
214
 
200
- if RUBY_VERSION >= "2.7"
201
- # Pattern matching support
202
- #
203
- # @api private
204
- def deconstruct_keys(_keys)
205
- attributes
206
- end
215
+ # Pattern matching support
216
+ #
217
+ # @api private
218
+ def deconstruct_keys(_keys)
219
+ attributes
207
220
  end
208
221
  end
209
222
  end
210
223
 
211
224
  require "dry/struct/extensions"
212
225
  require "dry/struct/printer"
226
+ require "dry/struct/value"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dry-struct
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.0
4
+ version: 1.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Piotr Solnica
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-01-21 00:00:00.000000000 Z
11
+ date: 2022-10-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dry-core
@@ -16,34 +16,34 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0.5'
19
+ version: '0.9'
20
20
  - - ">="
21
21
  - !ruby/object:Gem::Version
22
- version: '0.5'
22
+ version: '0.9'
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
26
26
  requirements:
27
27
  - - "~>"
28
28
  - !ruby/object:Gem::Version
29
- version: '0.5'
29
+ version: '0.9'
30
30
  - - ">="
31
31
  - !ruby/object:Gem::Version
32
- version: '0.5'
32
+ version: '0.9'
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: dry-types
35
35
  requirement: !ruby/object:Gem::Requirement
36
36
  requirements:
37
37
  - - "~>"
38
38
  - !ruby/object:Gem::Version
39
- version: '1.5'
39
+ version: '1.6'
40
40
  type: :runtime
41
41
  prerelease: false
42
42
  version_requirements: !ruby/object:Gem::Requirement
43
43
  requirements:
44
44
  - - "~>"
45
45
  - !ruby/object:Gem::Version
46
- version: '1.5'
46
+ version: '1.6'
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: ice_nine
49
49
  requirement: !ruby/object:Gem::Requirement
@@ -58,6 +58,20 @@ dependencies:
58
58
  - - "~>"
59
59
  - !ruby/object:Gem::Version
60
60
  version: '0.11'
61
+ - !ruby/object:Gem::Dependency
62
+ name: zeitwerk
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: '2.6'
68
+ type: :runtime
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
74
+ version: '2.6'
61
75
  - !ruby/object:Gem::Dependency
62
76
  name: bundler
63
77
  requirement: !ruby/object:Gem::Requirement
@@ -144,7 +158,7 @@ licenses:
144
158
  - MIT
145
159
  metadata:
146
160
  allowed_push_host: https://rubygems.org
147
- changelog_uri: https://github.com/dry-rb/dry-struct/blob/master/CHANGELOG.md
161
+ changelog_uri: https://github.com/dry-rb/dry-struct/blob/main/CHANGELOG.md
148
162
  source_code_uri: https://github.com/dry-rb/dry-struct
149
163
  bug_tracker_uri: https://github.com/dry-rb/dry-struct/issues
150
164
  post_install_message:
@@ -155,14 +169,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
155
169
  requirements:
156
170
  - - ">="
157
171
  - !ruby/object:Gem::Version
158
- version: 2.5.0
172
+ version: 2.7.0
159
173
  required_rubygems_version: !ruby/object:Gem::Requirement
160
174
  requirements:
161
175
  - - ">="
162
176
  - !ruby/object:Gem::Version
163
177
  version: '0'
164
178
  requirements: []
165
- rubygems_version: 3.1.4
179
+ rubygems_version: 3.1.6
166
180
  signing_key:
167
181
  specification_version: 4
168
182
  summary: Typed structs and value objects