These are chat archives for dry-rb/chat

8th
Nov 2016
Ramon Tayag
@ramontayag
Nov 08 2016 01:34
How do I make initialization hash keys optional?
class Car < Dry::Struct
  attribute :brand_name, Types::String.optional
  attribute :model_number, Types::String.optional
end
Car.new(model_number: "81AC") # raises Dry::Struct::Error, ":brand_name is missing in Hash input"
Piotr Solnica
@solnic
Nov 08 2016 09:19
@ramontayag constructor_type :schema
Ramon Tayag
@ramontayag
Nov 08 2016 09:19
Thanks - not familiar with that macro. Will check it out.
Piotr Solnica
@solnic
Nov 08 2016 09:22
@ramontayag structs can use different hash schema types from dry-types, it's strict by default so all keys are expected to be present in attributes hash that's passed to .new
Ramon Tayag
@ramontayag
Nov 08 2016 11:30
Ok thanks for the explanation @solnic!
If anyone's interested, just putting this out there: https://github.com/imacchiato/dry-validation-matchers
Jeff Dickey
@jdickey
Nov 08 2016 15:42
@ramontayag That's Useful :smiley: