flash-gordon on main
Ignore compat.rb in Zeitwerk lo… Add more paths to loader exclus… Add spec to test eager loading and 1 more (compare)
obj.class == Time ? obj : coerce(obj, Time)
module Types
include Dry::Types(default: :nominal)
CompactArray = Types::Coercible::Array.constructor { |vs| vs.map(&:presence).compact.map }
SplittingCompactArray = Types::Coercible::Array.constructor do |vs|
vs
.flat_map { |v| v.is_a?(::String) ? v.split(',') : v }
.map(&:presence)
.compact
.map
end
end
Hey guys, I'm trying to wrap my head around the difference between
optional(:age).filled(:integer, gt?: 18)
optional(:age).maybe(:integer, gt?: 18)
To me this reads that age
is optional in both cases and that when the value is present it should be typecasted as integer and be greater than 18. I Feels like the two statements are identical - or am I missing something?
@lenart the latter one allows to pass NIL:
contract = MyContract.new
contract.call(age: nil, age2:nil)
#<Dry::Validation::Result{:age=>nil, :age2=>nil} errors={:age=>["must be filled"]}>
The optional keyword allows you to completely SKIP the key, so it would be valid for validator.call({})
because you can omit both of them. But if you pass any value, only one can be nil, and the other one needs to be present and castable to Integer.
include Dry::Transaction
class AdminService << ApplicationService
step :validation
step :check_active
step :privileges
def validation; end
def check_active; end
def privileges; and
end
class UserService << AdminService
step :validation
step :check_active
step :privileges
def privileges; and
end
class UserService << AdminService
def privileges; and
end