We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
When you try to pass subsclasses of parent class to attribute, dry-struct doesn't parse them as subsclases.
Here is a code sample:
require 'dry/struct' module Types include Dry.Types() end Filter = Class.new(Dry::Struct) do attribute :filter_type, Types::String end PriceFilter = Class.new(Filter) do attribute :min_price, Types::String attribute :max_price, Types::String attribute :tick_size, Types::String end MaxPositionFIlter = Class.new(Filter) do attribute :max_position, Types::String end Response = Class.new(Dry::Struct) do attribute :filters, Types::Array.of(Filter) end Response.new(filters: [{filter_type: 'foo', min_price: '1', max_price: '2', tick_size: '3'}, {filter_type: 'bar', max_position: '4'}]) # current behavior: array of FIlter types => #<Response filters=[#<Filter filter_type="foo">, #<Filter filter_type="bar">]> Response = Class.new(Dry::Struct) do attribute :filters, Types::Array.of(PriceFilter | MaxPositionFIlter) end Response.new(filters: [{filter_type: 'foo', min_price: '1', max_price: '2', tick_size: '3'}, {filter_type: 'bar', max_position: '4'}]) # expected behavior: array of subclasses types => #<Response filters=[#<PriceFilter filter_type="foo" min_price="1" max_price="2" tick_size="3">, #<MaxPositionFIlter filter_type="bar" max_position="4">]>
The text was updated successfully, but these errors were encountered:
No branches or pull requests
Describe the bug
When you try to pass subsclasses of parent class to attribute, dry-struct doesn't parse them as subsclases.
To Reproduce
Here is a code sample:
My environment
The text was updated successfully, but these errors were encountered: