-
-
Notifications
You must be signed in to change notification settings - Fork 188
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
type? should support any available class #223
Comments
This is working on master now. Closing... |
Hi! I'm experiencing the same problem, I believe. Here is the validation: require 'core/validation/form'
module App::Shared
module Validations
FormDataFile = Core::Validation.Form do
required(:filename).filled(:str?)
required(:type).filled(:str?)
required(:tempfile).value(type?: File) # { filled? & type?(File) }
optional(:head).filled(:str?)
end
end
end Note: Here is the part of a backtrace that may help:
|
I am using Dry validation with Reform, and I also experience this bug: module Admin::Coupon::Contract
class Create < Reform::Form
feature Dry
property :code
property :name
property :effective_from
property :effective_to
property :auto_apply, populator: :populate_auto_apply!
property :city
property :region
property :usage_limit, populator: :populate_usage_limit!
property :usage_maximum, populator: :populate_usage_maximum!
property :discount_type
property :discount_percentage
property :discount_amount
property :genre, populator: :populate_genre!
property :sub_genre, populator: :populate_sub_genre!
property :hyper_genre, populator: :populate_hyper_genre!
property :visibility
property :user_name, virtual: true
property :user, populator: :populate_user!
property :license_for_podcast
def populate_usage_limit!(fragment:, **)
self.usage_limit = fragment.to_i unless fragment.nil?
end
def populate_usage_maximum!(fragment:, **)
self.usage_maximum = fragment.to_i unless fragment.nil?
end
def populate_auto_apply!(fragment:, **)
self.auto_apply = true if fragment.eql? '1'
self.auto_apply = false if fragment.eql? '0'
end
def populate_genre!(fragment:, **)
self.genre = Genre.find(fragment) unless fragment.nil? or fragment.to_i == 0
end
def populate_sub_genre!(fragment:, **)
self.sub_genre = SubGenre.find(fragment) unless fragment.nil? or fragment.to_i == 0
end
def populate_hyper_genre!(fragment:, **)
self.hyper_genre = HyperGenre.find(fragment) unless fragment.nil? or fragment.to_i == 0
end
def populate_user!(fragment:, **)
self.user = User.find(fragment) unless fragment.nil? or fragment.to_i == 0
end
validation :default do
configure do
option :form
config.messages_file = 'config/errors.yml'
def discount_types
%w(percentage currency) + %i(percentage currency)
end
def visibility_types
%w(visible invisible) + %i(visible invisible)
end
def license_for_podcast_types
%w(yes no any) + %i(yes no any)
end
end
required(:code).filled(:str?, min_size?: 4, max_size?: 10)
required(:name).filled(:str?, max_size?: 255)
required(:effective_from).filled(:date?)
required(:effective_to).filled(:date?)
required(:auto_apply).filled(:bool?)
required(:city).maybe(:str?)
required(:region).maybe(:str?)
required(:usage_limit).filled(:int?, min_size?: 0, max_size?: 20000)
required(:usage_maximum).maybe
required(:discount_type).filled(:str?, included_in?: discount_types)
required(:discount_percentage).maybe
required(:discount_amount).maybe
required(:genre).maybe(type?: ::Genre)
required(:sub_genre).maybe(type?: ::SubGenre)
required(:hyper_genre).maybe(type?: ::HyperGenre)
required(:visibility).filled(:str?, included_in?: visibility_types)
required(:user).filled(type?: ::User)
required(:license_for_podcast).filled(:str?, included_in?: license_for_podcast_types)
end
end
end Full trace:
Using: dry-validation 0.10.7 |
I ran into this on Should this issue be bumped to a different newer milestone? /cc @flash-gordon |
@tylerhunt yeah, I think something like this should work module Types
include Dry::Types.module
end
Schema = Dry::Validation.Schema do
required(:foo).filled(Types::Instance(DateTime).constrained(lt: DateTime.now))
end |
@flash-gordon Your example works for certain built-in types like Here's a minimal case to reproduce: require 'dry-struct'
require 'dry-types'
require 'dry-validation'
module Types
include Dry::Types.module
end
class Custom < Dry::Struct
attribute :value, Types::Coercible::Integer
end
Dry::Validation.Params do
required(:custom).filled(Types.Instance(Custom))
end Should this case work, or are custom types like this not supported with |
This will work fine in the next release with the required(:custom).filled(type?: Custom) |
Given I have a class named
Acme::Catalog
When I use
required(:catalog).value(type?: Catalog)
withinmodule Acme
Then it should validate that
catalog.is_a? Acme::Catalog
Currently I get
Nothing registered with the key "acme.catalog" (Dry::Container::Error)
The text was updated successfully, but these errors were encountered: