These are chat archives for dry-rb/chat

Apr 2018
Apr 25 2018 06:31
How can I get an attribute that is both optional and default? I want to be able to leave it out, and when I do, it should have a default value.
Nikita Shilnikov
Apr 25 2018 07:59
@jonahx I think it's what dry-types/dry-struct does in master, check out the changelogs
Tiago Moraes
Apr 25 2018 16:57

when defining an enum without 0 as a valid value:

subject(:enum) { Dry::Types['integer'].enum(4, 5, 6) }

I expected that it would be invalid

expect(enum.try(0)).to be_failure

but it is actually valid because of inverted_mapping. I found this to be really confusing.
Should't this inverted behavior only happen when the mapping is defined explicitly?

subject(:enum) { Dry::Types['integer'].enum(4 => 0) }

At least when the values are all integers?

Nikita Shilnikov
Apr 25 2018 17:49
it always worked like that for integers but I think this behavior can be made configurable
well, try didn't work in prev version actually but fixed this :)
[] worked
I would say it's better not to have mapping by default
but this is a breaking change
Nikita Shilnikov
Apr 25 2018 18:24
@tiagoefmoraes I'll do what you suggested before the release, thanks for bringing it
Apr 25 2018 20:30

Any idea why I could be getting the error:

Attribute :authenticator_name has already been defined (Dry::Struct::RepeatedAttributeError)

when that is not the case?
My class looks like this:

    class Input < ::Dry::Struct
      attribute :authenticator_name, Types::NonEmptyString
      attribute :service_id,         Types::Coercible::String
      attribute :account,            Types::NonEmptyString
      attribute :username,           Types::NonEmptyString
      attribute :password,           Types::NonEmptyString
Nikita Shilnikov
Apr 25 2018 20:39
@jonahx most likely the file containing Input getting loaded twice
Apr 25 2018 20:41
@flash-gordon yep, rails was autoloading and there was a require statement somewhere. when i removed the require the error vanished.
Tiago Moraes
Apr 25 2018 21:23
@flash-gordon thanks!
Ryan Bigg
Apr 25 2018 23:15
in ur repos, submitting PRs: dry-rb/dry-core#25