Questions tagged [dry-struct]

dry-struct is a gem built on top of dry-types which provides Typed structs and value objects.

dry-struct is a gem built on top of dry-types which provides virtus-like DSL for defining typed struct classes.

Code: https://github.com/dry-rb/dry-struct

Documentation: https://dry-rb.org/gems/dry-struct/

3 questions
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
0
votes
0 answers

Rails 7 create camelcase output for dry::struct object

I've to build a massive JSON file based on few different API calls. I want to use Dry::Struct To easily manipulate data like: obj = Test::DataStruct.new obj.send_envelope_description = 1 but expected output should be camelcase: #
mr_muscle
  • 2,536
  • 18
  • 61
0
votes
0 answers

Rails 7 dry-struct add attribute from method

I'm using dry-struct for non-model class Payout - it's basically structured hash response from API call. module Customer class Payout < Dry::Struct attribute :amount, Types::Integer attribute :reference, Types::String attribute :settlements,…
mr_muscle
  • 2,536
  • 18
  • 61