Skip to content

Commit

Permalink
Merge pull request #715 from dry-rb/zeitwerkify
Browse files Browse the repository at this point in the history
[changelog]

version: unreleased
changed: "Use Zeitwerk for auto-loading (via #715) (@solnic)"
  • Loading branch information
solnic authored Oct 8, 2022
2 parents 06c4fe8 + 3bb06b1 commit 3f89715
Show file tree
Hide file tree
Showing 17 changed files with 37 additions and 56 deletions.
15 changes: 9 additions & 6 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
27 changes: 24 additions & 3 deletions lib/dry/validation.rb
Original file line number Diff line number Diff line change
@@ -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
#
Expand All @@ -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"
Expand Down Expand Up @@ -56,5 +73,9 @@ def self.Contract(options = EMPTY_HASH, &block)
def self.macros
Macros
end

loader.setup

extend Macros::Registrar
end
end
3 changes: 0 additions & 3 deletions lib/dry/validation/config.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
# frozen_string_literal: true

require "dry/schema/config"
require "dry/validation/macros"

module Dry
module Validation
# Configuration for contracts
Expand Down
10 changes: 1 addition & 9 deletions lib/dry/validation/contract.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 0 additions & 7 deletions lib/dry/validation/contract/class_interface.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down
3 changes: 0 additions & 3 deletions lib/dry/validation/evaluator.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down
3 changes: 0 additions & 3 deletions lib/dry/validation/extensions/predicates_as_macros.rb
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
1 change: 0 additions & 1 deletion lib/dry/validation/macro.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# frozen_string_literal: true

require "dry/validation/constants"
require "dry/validation/function"

module Dry
module Validation
Expand Down
1 change: 0 additions & 1 deletion lib/dry/validation/macros.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# frozen_string_literal: true

require "dry/container"
require "dry/validation/macro"

module Dry
module Validation
Expand Down
5 changes: 0 additions & 5 deletions lib/dry/validation/message.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down
3 changes: 0 additions & 3 deletions lib/dry/validation/message_set.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down
3 changes: 0 additions & 3 deletions lib/dry/validation/messages/resolver.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
# frozen_string_literal: true

require "dry/validation/message"
require "dry/schema/message_compiler"

module Dry
module Validation
module Messages
Expand Down
3 changes: 0 additions & 3 deletions lib/dry/validation/result.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down
3 changes: 0 additions & 3 deletions lib/dry/validation/rule.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
# frozen_string_literal: true

require "dry/core/equalizer"

require "dry/validation/constants"
require "dry/validation/function"

module Dry
module Validation
Expand Down
1 change: 0 additions & 1 deletion lib/dry/validation/values.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# frozen_string_literal: true

require "dry/core/equalizer"
require "dry/schema/path"
require "dry/validation/constants"

Expand Down
4 changes: 2 additions & 2 deletions project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
1 change: 1 addition & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
rescue LoadError
end

require "yaml"
require "i18n"
require "dry/validation"

Expand Down

0 comments on commit 3f89715

Please sign in to comment.