timriley on support-component-dirs-with-mixed-namespaces
Avoid freezing components Thes… Add dirs to load path so earlie… Extract Identifier; support mix… (compare)
timriley on support-component-dirs-with-mixed-namespaces
Fix space (compare)
timriley on support-component-dirs-with-mixed-namespaces
Support component dirs with mix… Add test Refactor component building int… and 30 more (compare)
dry-bot on master
[devtools] sync (compare)
thanks! it also works for optional(:my_number).maybe(inclusion?: 1..5)
BUT if I do the below
schema = Dry::Validation.Schema do
optional(:num).maybe(inclusion?: 1..5)
end
errors = schema.call(abc: '1', num: 6)
I get a NoMethodError. input.rb:86:in
options_for_inclusion?': undefined method join' for 0..5:Range (NoMethodError)
included_in?
dry-rb/dry-logic@e649fad
Range#include?
should work I think?
predicate(:included_in?) do |list, input|
list.include?(input)
end
predicate(:includes?) do |value, input|
input.include?(value)
end
input_value.included_in?(list)
vs input_value.includes?(value)
One more thing provided by @marshall-lee for initializer in our commercial project is the ar_param
or ar_option
.
It allows to set object dependency as either model or model id.
In Rails projects this proves to be very suitable (example below is over-simplified):
class DestroyUser
ar_param :user
def call
user.destroy
end
def self.call(*args)
new(*args).call
end
end
user_id = 1
user = User.find 1
# This methods are the same
DestroyUser.call user_id
DestroyUser.call user
Under the hood the method either gets an activerecord instance or finds its by id (or by another argument):
ar_param :user, find_by: :key
The question is what do you think about implementing this behaviour in a submodule of dry-initializer
(dry-initializer/rails
)?