dry-bot on master
[devtools] sync (compare)
dry-bot on master
[devtools] sync (compare)
dry-bot on master
[devtools] sync (compare)
dry-bot on master
[devtools] sync (compare)
dry-bot on master
[devtools] sync (compare)
dry-bot on master
[devtools] sync (compare)
dry-bot on master
[devtools] sync (compare)
timriley on add-0-19-0-changelog
Expand on CHANGELOG (compare)
timriley on add-0-19-0-changelog
Add changelog entry for 0.19.0 Expand on CHANGELOG (compare)
timriley on default-settings-for-component-dirs
timriley on master
Allow custom system-wide defaul… (compare)
timriley on default-settings-for-component-dirs
Allow defaults to be configured… Move loader setting to componen… Apply default config regardless… and 6 more (compare)
reader: :private
as a pattern, then you would like new using
method in dry-initializer:Hey all, was upgrading to the 0.10 series from the 0.9 series and I'm getting errors in the schemas that use rules with custom predicates...
"ArgumentError: unique_npi_number? predicate arity is invalid"
configure do
def unique_npi_number?(id, org_uid, npi_number)
return true if npi_number.nil?
existing_provider = Provider.find(org_uid: org_uid, npi_number: npi_number)
if existing_provider && existing_provider[:provider_uid] != id
false
else
true
end
end
end
...
rule(unique_npi_number: [:id, :org_uid, :npi_number]) do |id, org_uid, npi_number|
npi_number.unique_npi_number?(npi_number, org_uid, id)
end
was working just fine on the 0.9 series
npi_number.unique_npi_number?(org_uid, id)
should do the trick
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