Hey there,
I’ve been using virtus for writing models that are populated by consuming an JSON API in the past and it’s been quite a good experience. As its README states, dry-types, dry-struct and dry-validation “should be considered as virtus’ successors, with better separation of concerns and better features”.
I’m giving Dry::Struct and Dry::Types a shot right now and I’m a bit baffled that Dry::Struct doesn’t include attribute setters. I already read that a Dry::Struct should be treated as immutable and that it is not designed to have its state mutated over time (https://github.com/dry-rb/dry-types/issues/106).
What’s your opinion on that, considering that virtus indeed has attribute setters?
I have to admin that I’m used to Active Record and its all-in-one-approach, so virtus having attribute setters is kind of familiar. Let’s say I’d want to write an JSON API client, when having to update a model, how would you do it? Always use the repository pattern, provide the new attributes as a hash and work with the result like this?
project_repository = ProjectRepository.new
project = project_repository.find(42)
updated_project = project_repository.update(project.id, {name: 'A New Name'})
Would love to read your thoughts!
Best regards, Tobias