Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove all Ruby code from the gem #230

Merged
merged 1 commit into from
Sep 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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