Next-gen ruby libs! » github.com/dry-rb » website: https://dry-rb.org » forum: https://discourse.dry-rb.org
Hello all! It’s been a while since I looked at ROM/dryrb…
I’m starting a greenfield app which requires a REST api, and thought of using Roda + ROM.
However, I have only seen passing tweets about dry-web :)
...and wonder what the status of it is?
Is it expected the API is fairly stable now? docs?
dry-web-roda new my_project
Is this not valid any more?:
TournamentTableSchema = Dry::Validation.JSON do
required(:type) { filled? > str? }
end
TournamentTablesSchema = Dry::Validation.JSON do
required(:_embedded).schema do
required(:tournament_results).each do
schema(TournamentTableSchema)
end
end
end
Raises an ArgumentError input_processor_compiler.rb:66:in
visit_implication': wrong number of arguments (given 2, expected 1) (ArgumentError)`
This works:
TournamentTableSchema = Dry::Validation.JSON do
required(:type).filled(:str)
end
TournamentTablesSchema = Dry::Validation.JSON do
required(:_embedded).schema do
required(:tournament_results).each do
schema(TournamentTableSchema)
end
end
end
So the error occurs when a block is given to required
in a sub schema.
filled? > str?
this is not correct (regardless of the crash, which is a bug) as it means that if it’s filled then it must be a string, if it’s not filled, then it’s valid too
required(:type).filled(:str?)
which means it a) must be filled b) it must be a string
constructor_type(:schema)
in Struct class
option :user_info, default: proc {map_user_info}
def map_user_info
user_info = UsersImport::Dtos::UserInfo.new()
end
dry-types
so much! making structs behave like a type with the same interface is AWESOME!
class Address < Dry::Types::Struct
attribute :street, Types::Strict::String
# other attributes
end
class Customer < Dry::Types::Struct
attribute :address, Address.optional
end
.constrained
as well as .constructor
for struct as well as for types
Address.maybe
actually creates a monad :)