These are chat archives for dry-rb/chat

6th
Aug 2018
Jan Stevens
@JanStevens
Aug 06 2018 07:18
Hello, I'm replacing Virtus in our API client with Dry Struct, now I'm trying to find a better pattern for the following usecase. We sometimes return in our API a limited representation of an object VS the full object, how can I easily represent this in Dry types / structs? I use to go for the NestedContract class and Contract then inherited from NestedContract and added another bunch of attributes.
class NestedContract < Dry::Struct
  attribute :id, Types::Coercible::Integer
  attribute :name, Types::Coercible::String
  attribute :description, Types::Coercible::String.optional
end

class Contract < NestedContract
  attribute :sign_date, Types::Coercible::Date
end
Jan Stevens
@JanStevens
Aug 06 2018 07:54
Another issue: How should I resolve circular references in my Schema? With Virtus you could use strings as a type and then call Virtus.finalize to load them in