Dry-struct vs. dry-initializer

I’m unsure how conceptually dry-struct and dry-initializer are different.

What are the core use cases for each? In which situation would you use which one?

My current task is writing an API client, and I’m not sure which of the two to reach to, as both seem to support initialization from hashes.

dry-struct is meant to be used for representing data, whereas dry-initializer is meant to be used whenever you need more complex initialization logic. ie in rom-rb, dry-initializer is used extensively for defining object options with default values.

Want I actually need is to parse an json-api response into structs/poros. It feels like neither lib is a solution to that on it’s own - meaning some sort of–let’s say–recursive parsing to change all the direction (:data, :relationships) into attributes and collections.

Would you agree? Would you see another piece from the dry toolbox for that?

Correct

No, there’s nothing specific to parsing json-api responses. I plan to build something once I have an excuse to use json-api (FWIW).

1 Like