Skip to content

Commit

Permalink
Remove all Ruby code from the gem (#230)
Browse files Browse the repository at this point in the history
hanami-controller now implements its params validation entirely internally, meaning this gem now exists only to manage the dependency on dry-validation.
  • Loading branch information
timriley committed Sep 2, 2024
1 parent 18b41c4 commit 585f2e4
Show file tree
Hide file tree
Showing 15 changed files with 0 additions and 756 deletions.
1 change: 0 additions & 1 deletion hanami-validations.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ Gem::Specification.new do |spec|
spec.required_ruby_version = ">= 3.1"

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"
Expand Down
96 changes: 0 additions & 96 deletions lib/hanami/validations.rb
Original file line number Diff line number Diff line change
@@ -1,109 +1,13 @@
# frozen_string_literal: true

require "dry/validation"
require "delegate"
require "zeitwerk"

# @see Hanami::Validations
# @since 0.1.0
module Hanami
# @since 0.1.0
# @api private
module Validations
# @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

gem_loader.setup
require_relative "validations/version"

# @since 0.1.0
# @api private
def self.included(klass)
super
klass.extend(ClassMethods)
end

# @since 2.0.0
# @api private
class Result < SimpleDelegator
# @since 2.0.0
# @api private
def output
__getobj__.to_h
end

# @since 2.0.0
# @api private
def messages
__getobj__.errors.to_h
end
end

# Validations DSL
#
# @since 0.1.0
# @api private
module ClassMethods
# Define validation rules from the given block.
#
# @param blk [Proc] validation rules
#
# @since 0.6.0
# @api private
def validations(&blk)
@_validator = Dry::Validation::Contract.build { schema(&blk) }
end

# @since 2.0.0
# @api private
def _validator
@_validator
end
end

# Initialize a new instance of a validator
#
# @param input [#to_h] a set of input data
#
# @since 0.6.0
# @api private
def initialize(input)
@input = input
end

# Validates the object.
#
# @return [Hanami::Validations::Result]
#
# @since 0.2.4
# @api private
def validate
Result.new(
self.class._validator.call(@input)
)
end

# Returns a Hash with the defined attributes as symbolized keys, and their
# relative values.
#
# @return [Hash]
#
# @since 0.1.0
# @api private
def to_h
validate.to_h
end
end
end
40 changes: 0 additions & 40 deletions lib/hanami/validations/form.rb

This file was deleted.

10 changes: 0 additions & 10 deletions lib/hanami/validator.rb

This file was deleted.

24 changes: 0 additions & 24 deletions spec/unit/hanami/validations_spec.rb

This file was deleted.

27 changes: 0 additions & 27 deletions spec/unit/hanami/validator/custom_type_spec.rb

This file was deleted.

42 changes: 0 additions & 42 deletions spec/unit/hanami/validator/inheritance_spec.rb

This file was deleted.

29 changes: 0 additions & 29 deletions spec/unit/hanami/validator/json_spec.rb

This file was deleted.

66 changes: 0 additions & 66 deletions spec/unit/hanami/validator/macro_spec.rb

This file was deleted.

Loading

0 comments on commit 585f2e4

Please sign in to comment.