These are chat archives for dry-rb/chat

7th
Feb 2018
Drew Olson
@drewolson
Feb 07 2018 00:46
@flash-gordon that was exactly what i was looking for, thanks
Jonah
@jonahx
Feb 07 2018 21:59
Is there a less verbose way to do the following (i find myself repeating the module Types part in all of my classes…
module Ldap

  module Types
    include Dry::Types.module
  end

  class LogEntry < Dry::Struct
    # can type these more accurately later, if need arises
    attribute :timestamp, Types::Strict::String
    attribute :severity , Types::Strict::String
    attribute :message  , Types::Strict::String
  end

end
Jonah
@jonahx
Feb 07 2018 22:10
Looks like this works…
  class LogEntry2 < Dry::Struct
    include Dry::Types.module
    # can type these more accurately later, if need arises
    attribute :timestamp, Strict::String
    attribute :severity , Strict::String
    attribute :message  , Strict::String
  end
Tim Riley
@timriley
Feb 07 2018 22:53
@jonahx the example on http://dry-rb.org/gems/dry-struct/ is more or less how I do it
ie. Define a single types module that you can access from all over your app, then use that for the types in your struct definitions
This allows you to define common types that you can reuse from around your app
Jonah
@jonahx
Feb 07 2018 22:54
@timriley so you’re just requireing the 3 line types file wherever you need it?
Tim Riley
@timriley
Feb 07 2018 22:54
Yes
Jonah
@jonahx
Feb 07 2018 22:54
thanks
Tim Riley
@timriley
Feb 07 2018 22:55
And it’s never just 3 lines, I always end up with custom app-specific types in there
Jonah
@jonahx
Feb 07 2018 23:02
@timriley right, makes sense