Questions tagged [dry-rb]

dry-rb is a collection of next-generation Ruby libraries

dry-rb helps you write clear, flexible, and more maintainable Ruby code. Each dry-rb gem fulfils a common task, and together they make a powerful platform for any kind of Ruby application.

19 questions
4
votes
3 answers

How to validate date string with dry-validation gem?

I want to allow date formatted string with dry-validation gem, but I can't. class NewUserContract < Dry::Validation::Contract params do optional(:date).filled(:date) end end contract = NewUserContract.new contract.call(date: Date.today) #=>…
Junichi Ito
  • 2,438
  • 1
  • 23
  • 46
4
votes
2 answers

How to set default value for Dry::Validation.Params scheme?

I have next scheme Dry::Validation.Params do optional(:per_page).filled(:int?, lteq?: 1000) optional(:page).filled(:int?) end If I pass empty hash for validation I get empty output but I want to set default values for my data. I tried…
Roman Slobodzyan
  • 301
  • 2
  • 11
3
votes
1 answer

Automatically truncate a string

Taking the example from dry-validation: require "dry-validation" module Types include Dry::Types.module Name = Types::String.constructor do |str| str ? str.strip.chomp : str end end SignUpForm = Dry::Validation.Params do configure do …
Paulo Fidalgo
  • 21,709
  • 7
  • 99
  • 115
3
votes
2 answers

dry-struct How to conditionally validate one attribute?

I'm using dry-types and dry-struct and I would like to have a conditional validation. for the class: class Tax < Dry::Struct attribute :tax_type, Types::String.constrained(min_size: 2, max_size: 3, included_in: %w[IVA IS NS]) attribute…
Paulo Fidalgo
  • 21,709
  • 7
  • 99
  • 115
2
votes
0 answers

How to validate an array of different objects using dry-schema gem

Given I have such JSON object having an array of various objects like: { "array": [ { "type": "type_1", "value": 5 }, { "type": "type_2", "kind": "person" } ] } According to JSON schema validation, I can…
slip
  • 63
  • 6
2
votes
0 answers

Stubbing Dry::Matcher cases in Rails/RSpec

We are using Dry::Monads with Dry::Matchers in our app. We mostly consume monadic results at the controller level using the Dry::Matchers case syntax like so: ....call(foo: bar) do |result| result.success { |resource| render json: resource, status…
2
votes
0 answers

Inclusion filtering in postgresql on a enum type column

I have a postgres enum create_enum(:status_type, %i[requested approved]). I created a column in a table with a status_type :status, null: false. I am trying to filter with inclusion on it in ruby like this:…
geoko93
  • 45
  • 12
1
vote
1 answer

Ruby on Rails: dry-schema dry-validation not validating presence

module QleKinds class CreateParamsValidator < MyCustomClass define do required(:title).value(:filled?) end end end I'm using dry-validation and dry-schema in a rails application and implementing the advice to check how to check…
zasman
  • 446
  • 1
  • 8
  • 28
1
vote
1 answer

Dry::Web::Container yielding different objects with multiple calls to resolve

I'm trying write a test to assert that all defined operations are called on a successful run. I have the operations for a given process defined in a list and resolve them from a container, like so: class ProcessController def call(input) …
Christian
  • 45
  • 5
1
vote
1 answer

dry-validation: Case insensitive `included_in?` validation with Dry::Validation.Schema

I'm trying to create a validation for a predetermined list of valid brands as part of an ETL pipeline. My validation requires case insensitivity, as some brands are compound words or abbreviations that are insignificant. I created a custom…
Mr. Tim
  • 886
  • 8
  • 18
0
votes
0 answers

Dry-validation/Dry-schema uninitialized constant Dry::Schema::PredicateRegistry

I'm attempting to update the ruby version of an empty, stock API (which is forked to create new API) from Ruby 2.6.3 to Ruby 2.7.3 using TrailBlazer. Currently, I'm having issues with the Dry gems, specifically Dry-Validation (1.8.0), Dry-Schema…
0
votes
1 answer

Dependency injection issue in rails 7 & ruby 3.1

I have a simple rails app using dry-container & dry-auto_inject by dry-rb to inject a service on controller, this method working well on rails 6 & below and ruby 2.7 & below . A service I created under app/services/v1 module V1 class…
itx
  • 1,327
  • 1
  • 15
  • 38
0
votes
0 answers

Ruby - dry-rb - how to update an existing object's attributes?

Using dry-rb structs and types, I'm trying amend an object that has already been created, but can't seem to figure it out. [3] pry(main)> class User < Dry::Struct attribute :name, Types::String.optional attribute :age,…
magicfishy
  • 90
  • 8
0
votes
1 answer

Why is dry-struct initialization slow?

I have a Rails application that stores its configuration in 34 MySQL tables consisting of various objects and associations, for a total of about 900 records altogether. Up to recently the business logic was built on ActiveRecord, but performance was…
wiz
  • 606
  • 5
  • 9
0
votes
1 answer

How to mock dry-rb (used inf Reform contract) validation configure method

My problem is that I want to mock my custom validation method that returns some data from DB ( list of ids - to check if given id is in my DB ). So less talk, more code: in my Newsletter::Contract::Create class I have validation do configure do …
Adam Piotrowski
  • 674
  • 1
  • 7
  • 15
1
2