These are chat archives for dry-rb/chat

1st
Jun 2017
Rafael George
@cored
Jun 01 2017 16:01
I have a question about dry-struct
I want to use it to define a new value object however looks like I need to use the attribute DSL method to actually define attributes
what will happen if the Types module doesn't have the type that I want to wrap inside this new struct?
the type is an active record model
my intention is to use dry-struct to define value objects in my code base; I've been doing that with struct however I see the value on having some type checks for structs and probably in the future I will be able to compose smaller structs into bigger ones
any thoughts ?
Nikita Shilnikov
@flash-gordon
Jun 01 2017 16:10
@cored you can use Types::Any.constrained(type: ARModel)
Rafael George
@cored
Jun 01 2017 16:11
what does that do ? @flash-gordon
so the actual syntax would be attribute Types::Any.constrained(type: ARModel) ?
Nikita Shilnikov
@flash-gordon
Jun 01 2017 16:11
builds a type with a single type-check
Rafael George
@cored
Jun 01 2017 16:12
oh I see
so I will be able to pass anything that conforms to an active record model interface?
I'm still deciding if dry-struct would be a good inclusion
the advantage that I see at this point is the deep freeze feature
Nikita Shilnikov
@flash-gordon
Jun 01 2017 16:13
re any model, yes is you do it like Dry::Types['any'].constrained(type: ApplicationRecord), or you can specify a concrete class Dry::Types['any'].constrained(type: UserRecord), depends on your needs
Rafael George
@cored
Jun 01 2017 16:14
the downside of the concrete type
is that I will create a dependency with the framework
something that I don't want directly I would like to depend on the protocol instead of the specific type definition
oh now that I see it
looks like I need to pass an actual type into the type: key
is that right @flash-gordon ?
Nikita Shilnikov
@flash-gordon
Jun 01 2017 16:18
yes, it'a just an .is_a? check
Rafael George
@cored
Jun 01 2017 16:20
gotcha
I'm getting an error
method missing is complaining about 'keys'