Use Zeitwerk for code loading (#225)
(Fix a Rubocop issue in the specs at the same time)
This commit is contained in:
parent
c0187a9b9c
commit
0808974079
|
@ -21,6 +21,7 @@ Gem::Specification.new do |spec|
|
|||
spec.required_ruby_version = ">= 3.0"
|
||||
|
||||
spec.add_dependency "dry-validation", ">= 1.10", "< 2"
|
||||
spec.add_dependency "zeitwerk", "~> 2.6.0"
|
||||
|
||||
spec.add_development_dependency "bundler", ">= 1.6", "< 3"
|
||||
spec.add_development_dependency "rake", "~> 13"
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require_relative "hanami/validations"
|
|
@ -2,14 +2,29 @@
|
|||
|
||||
require "dry/validation"
|
||||
require "delegate"
|
||||
require "zeitwerk"
|
||||
|
||||
module Hanami
|
||||
# @since 0.1.0
|
||||
module Validations
|
||||
class Error < StandardError; end
|
||||
# @since 2.0.0
|
||||
# @api private
|
||||
def self.gem_loader
|
||||
@gem_loader ||= Zeitwerk::Loader.new.tap do |loader|
|
||||
root = File.expand_path("..", __dir__)
|
||||
loader.tag = "hanami-validations"
|
||||
loader.inflector = Zeitwerk::GemInflector.new("#{root}/hanami-validations.rb")
|
||||
loader.push_dir(root)
|
||||
loader.ignore(
|
||||
"#{root}/hanami-validations.rb",
|
||||
"#{root}/hanami/validations/version.rb"
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
require "hanami/validations/version"
|
||||
require "hanami/validator"
|
||||
gem_loader.setup
|
||||
|
||||
class Error < StandardError; end
|
||||
|
||||
def self.included(klass)
|
||||
super
|
||||
|
|
|
@ -10,7 +10,7 @@ RSpec.describe Hanami::Validator do
|
|||
end
|
||||
|
||||
rule(:email) do
|
||||
key.failure("has invalid format") unless /\A[\w+\-.]+@[a-z\d\-]+(\.[a-z\d\-]+)*\.[a-z]+\z/i.match?(value)
|
||||
key.failure("has invalid format") unless /\A[\w+\-.]+@[a-z\d-]+(\.[a-z\d-]+)*\.[a-z]+\z/i.match?(value)
|
||||
end
|
||||
|
||||
rule(:age) do
|
||||
|
|
Loading…
Reference in New Issue