From 873142804c7617badf8d813bcac67ad143ed70e1 Mon Sep 17 00:00:00 2001 From: Peter Solnica Date: Sat, 8 Oct 2022 11:34:51 +0200 Subject: [PATCH] Zeitwerkify --- Gemfile | 15 ++++++----- lib/dry/validation.rb | 27 ++++++++++++++++--- lib/dry/validation/config.rb | 3 --- lib/dry/validation/contract.rb | 10 +------ .../validation/contract/class_interface.rb | 7 ----- lib/dry/validation/evaluator.rb | 3 --- .../extensions/predicates_as_macros.rb | 3 --- lib/dry/validation/macro.rb | 1 - lib/dry/validation/macros.rb | 1 - lib/dry/validation/message.rb | 5 ---- lib/dry/validation/message_set.rb | 3 --- lib/dry/validation/messages/resolver.rb | 3 --- lib/dry/validation/result.rb | 3 --- lib/dry/validation/rule.rb | 3 --- lib/dry/validation/values.rb | 1 - project.yml | 4 +-- 16 files changed, 36 insertions(+), 56 deletions(-) diff --git a/Gemfile b/Gemfile index bdd17c84..f0d96271 100644 --- a/Gemfile +++ b/Gemfile @@ -6,17 +6,20 @@ eval_gemfile "Gemfile.devtools" gemspec -if ENV["DRY_CONFIGURABLE_FROM_MAIN"].eql?("true") +gem "dry-core", github: "dry-rb/dry-core", branch: "main" +gem "dry-logic", github: "dry-rb/dry-logic", branch: "main" + +# if ENV["DRY_CONFIGURABLE_FROM_MAIN"].eql?("true") gem "dry-configurable", github: "dry-rb/dry-configurable", branch: "main" -end +# end -if ENV["DRY_SCHEMA_FROM_MAIN"].eql?("true") +# if ENV["DRY_SCHEMA_FROM_MAIN"].eql?("true") gem "dry-schema", github: "dry-rb/dry-schema", branch: "main" -end +# end -if ENV["DRY_TYPES_FROM_MAIN"].eql?("true") +# if ENV["DRY_TYPES_FROM_MAIN"].eql?("true") gem "dry-types", github: "dry-rb/dry-types", branch: "main" -end +# end group :test do gem "dry-monads", "~> 1.0" diff --git a/lib/dry/validation.rb b/lib/dry/validation.rb index d7b2dcf9..fd5e092b 100644 --- a/lib/dry/validation.rb +++ b/lib/dry/validation.rb @@ -1,8 +1,11 @@ # frozen_string_literal: true +require "zeitwerk" + +require "dry/core" +require "dry/schema" + require "dry/validation/constants" -require "dry/validation/contract" -require "dry/validation/macros" # Main namespace # @@ -13,7 +16,21 @@ module Dry # @api public module Validation extend Dry::Core::Extensions - extend Macros::Registrar + + def self.loader + @loader ||= Zeitwerk::Loader.new.tap do |loader| + root = File.expand_path("..", __dir__) + loader.tag = "dry-validation" + loader.inflector = Zeitwerk::GemInflector.new("#{root}/dry-validation.rb") + loader.push_dir(root) + loader.ignore( + "#{root}/dry-validation.rb", + "#{root}/dry/validation/schema_ext.rb", + "#{root}/dry/validation/{constants,errors,extensions,version}.rb" + ) + loader.inflector.inflect("dsl" => "DSL") + end + end register_extension(:monads) do require "dry/validation/extensions/monads" @@ -56,5 +73,9 @@ def self.Contract(options = EMPTY_HASH, &block) def self.macros Macros end + + loader.setup + + extend Macros::Registrar end end diff --git a/lib/dry/validation/config.rb b/lib/dry/validation/config.rb index 5c668a0f..0710fe07 100644 --- a/lib/dry/validation/config.rb +++ b/lib/dry/validation/config.rb @@ -1,8 +1,5 @@ # frozen_string_literal: true -require "dry/schema/config" -require "dry/validation/macros" - module Dry module Validation # Configuration for contracts diff --git a/lib/dry/validation/contract.rb b/lib/dry/validation/contract.rb index 77d4fc1a..98e1e422 100644 --- a/lib/dry/validation/contract.rb +++ b/lib/dry/validation/contract.rb @@ -2,17 +2,9 @@ require "concurrent/map" -require "dry/core/equalizer" require "dry/initializer" -require "dry/schema/path" - -require "dry/validation/config" require "dry/validation/constants" -require "dry/validation/rule" -require "dry/validation/evaluator" -require "dry/validation/messages/resolver" -require "dry/validation/result" -require "dry/validation/contract/class_interface" +require "dry/validation/schema_ext" module Dry module Validation diff --git a/lib/dry/validation/contract/class_interface.rb b/lib/dry/validation/contract/class_interface.rb index 6c035487..d6220130 100644 --- a/lib/dry/validation/contract/class_interface.rb +++ b/lib/dry/validation/contract/class_interface.rb @@ -1,13 +1,6 @@ # frozen_string_literal: true -require "dry/schema" -require "dry/schema/messages" -require "dry/schema/path" -require "dry/schema/key_map" - require "dry/validation/constants" -require "dry/validation/macros" -require "dry/validation/schema_ext" module Dry module Validation diff --git a/lib/dry/validation/evaluator.rb b/lib/dry/validation/evaluator.rb index 8a04585b..443531da 100644 --- a/lib/dry/validation/evaluator.rb +++ b/lib/dry/validation/evaluator.rb @@ -1,10 +1,7 @@ # frozen_string_literal: true require "dry/initializer" -require "dry/core/deprecations" - require "dry/validation/constants" -require "dry/validation/failures" module Dry module Validation diff --git a/lib/dry/validation/extensions/predicates_as_macros.rb b/lib/dry/validation/extensions/predicates_as_macros.rb index 5b94ac94..80cc8179 100644 --- a/lib/dry/validation/extensions/predicates_as_macros.rb +++ b/lib/dry/validation/extensions/predicates_as_macros.rb @@ -1,8 +1,5 @@ # frozen_string_literal: true -require "dry/schema/predicate_registry" -require "dry/validation/contract" - module Dry module Validation # Predicate registry with additional needed methods. diff --git a/lib/dry/validation/macro.rb b/lib/dry/validation/macro.rb index e5f6aa7f..ba003174 100644 --- a/lib/dry/validation/macro.rb +++ b/lib/dry/validation/macro.rb @@ -1,7 +1,6 @@ # frozen_string_literal: true require "dry/validation/constants" -require "dry/validation/function" module Dry module Validation diff --git a/lib/dry/validation/macros.rb b/lib/dry/validation/macros.rb index 8bbfa05d..ad8d3551 100644 --- a/lib/dry/validation/macros.rb +++ b/lib/dry/validation/macros.rb @@ -1,7 +1,6 @@ # frozen_string_literal: true require "dry/container" -require "dry/validation/macro" module Dry module Validation diff --git a/lib/dry/validation/message.rb b/lib/dry/validation/message.rb index ad22e2ce..0d7704df 100644 --- a/lib/dry/validation/message.rb +++ b/lib/dry/validation/message.rb @@ -1,10 +1,5 @@ # frozen_string_literal: true -require "dry/core/equalizer" - -require "dry/schema/constants" -require "dry/schema/message" - module Dry module Validation # Message message diff --git a/lib/dry/validation/message_set.rb b/lib/dry/validation/message_set.rb index a4ca0625..954e46e0 100644 --- a/lib/dry/validation/message_set.rb +++ b/lib/dry/validation/message_set.rb @@ -1,9 +1,6 @@ # frozen_string_literal: true -require "dry/schema/message_set" - require "dry/validation/constants" -require "dry/validation/message" module Dry module Validation diff --git a/lib/dry/validation/messages/resolver.rb b/lib/dry/validation/messages/resolver.rb index 968afc00..11739e5f 100644 --- a/lib/dry/validation/messages/resolver.rb +++ b/lib/dry/validation/messages/resolver.rb @@ -1,8 +1,5 @@ # frozen_string_literal: true -require "dry/validation/message" -require "dry/schema/message_compiler" - module Dry module Validation module Messages diff --git a/lib/dry/validation/result.rb b/lib/dry/validation/result.rb index 00b358d9..4b386f48 100644 --- a/lib/dry/validation/result.rb +++ b/lib/dry/validation/result.rb @@ -1,11 +1,8 @@ # frozen_string_literal: true require "concurrent/map" -require "dry/core/equalizer" require "dry/validation/constants" -require "dry/validation/message_set" -require "dry/validation/values" module Dry module Validation diff --git a/lib/dry/validation/rule.rb b/lib/dry/validation/rule.rb index 92aea7ee..4e1b8fb3 100644 --- a/lib/dry/validation/rule.rb +++ b/lib/dry/validation/rule.rb @@ -1,9 +1,6 @@ # frozen_string_literal: true -require "dry/core/equalizer" - require "dry/validation/constants" -require "dry/validation/function" module Dry module Validation diff --git a/lib/dry/validation/values.rb b/lib/dry/validation/values.rb index 588f6db4..11a68247 100644 --- a/lib/dry/validation/values.rb +++ b/lib/dry/validation/values.rb @@ -1,6 +1,5 @@ # frozen_string_literal: true -require "dry/core/equalizer" require "dry/schema/path" require "dry/validation/constants" diff --git a/project.yml b/project.yml index 49789a0e..4aa66435 100644 --- a/project.yml +++ b/project.yml @@ -12,7 +12,7 @@ gemspec: - rspec runtime_dependencies: - [concurrent-ruby, "~> 1.0"] - - [dry-core, "~> 0.5", ">= 0.5"] + - [dry-core, "~> 0.9", ">= 0.9"] - [dry-container, "~> 0.7", ">= 0.7.1"] - [dry-initializer, "~> 3.0"] - - [dry-schema, "~> 1.8", ">= 1.8.0"] + - [dry-schema, "~> 1.11", ">= 1.11.0"]