timriley on add-0-19-0-changelog
Add changelog entry for 0.19.0 (compare)
timriley on add-0-19-0-changelog
Add changelog entry for 0.19.0 (compare)
timriley on add-0-19-0-changelog
Add changelog entry for 0.19.0 (compare)
timriley on update-docsite-for-component-dirs
timriley on master
Reference dry-system without co… Use component_dirs config in do… Merge pull request #160 from dr… (compare)
timriley on update-docsite-for-component-dirs
Reference dry-system without co… Use component_dirs config in do… (compare)
timriley on master
Avoid freezing components Thes… Add dirs to load path so earlie… Extract Identifier; support mix… and 2 more (compare)
require "dry-struct"
require "dry-types"
module Types
include Dry::Types.module
end
class Answer < Dry::Struct
attribute :question_id, Types::String
class Select < self
attribute :value, Types::Hash.schema(id: Types::Int)
end
class Text < self
attribute :value, Types::String
end
end
class Survey < Dry::Struct
attribute :answers, Types::Array.member(Answer::Text | Answer::Select)
end
Survey.new(
answers: [
Answer::Select.new(question_id: 1, value: {id: 10}),
Answer::Text.new(question_id: 1, value: "foo")
]
)
#<Survey answers=[#<Answer::Text question_id=1 value={:id=>10}>, #<Answer::Text question_id=1 value="foo">]>
Problem here is, both answers came back as Answer::Text
.
.member(Answer::Select | Answer::Text)
, things blow up.
.member(Answer)
since Select and Text are subclasses of Answer.
params, options
? (i think you hinted this twice already)options
hash? that would all happen on the class-levelUserSchema.call({}).output
:)
you can use reform with dry-validation, it's pretty amazing
Great, OK then!
def initialize(params, options)
@options = options #this is the dependency hash
end
Schema#output
do?
validation = schema.call(params)
validation.success? ? validation.output : validation.messages
form.sync