These are chat archives for dry-rb/chat

5th
Jul 2018
Jaromír Červenka
@Cervajz
Jul 05 2018 14:52
Hello :) I've updated gems today and all transactions are broken, due to the changes in dry-monads 1.0 :sweat_smile:
As .value does not exist anymore on Succes / Failure
Igor S. Morozov
@Morozzzko
Jul 05 2018 14:53
Update your dry-transactions too

Or, what version are you running? I was pretty sure I’m running the latest dry-t and dry-monads, and everything works pretty well

I’ve run into the value issue too, but it’s been fixed

Jaromír Červenka
@Cervajz
Jul 05 2018 14:54
‹master*!+1› »»»» bundle outdated                                           127|16:53:53
Fetching gem metadata from https://rubygems.org/.........
Fetching gem metadata from https://rubygems.org/.
Resolving dependencies....

Bundle up to date!
[~/P/P/R/v/api|2.5.1|2.7.15]
‹master*!+1› »»»» bundle update dry-transaction                               0|16:54:05
Fetching gem metadata from https://rubygems.org/.........
Fetching gem metadata from https://rubygems.org/.
Resolving dependencies...
Using rake 12.3.1
Using concurrent-ruby 1.0.5
Using i18n 1.0.1
Using minitest 5.11.3
Using thread_safe 0.3.6
Using tzinfo 1.2.5
Using activesupport 5.2.0
Using builder 3.2.3
Using erubi 1.7.1
Using mini_portile2 2.3.0
Using nokogiri 1.8.4
Using rails-dom-testing 2.0.3
Using crass 1.0.4
Using loofah 2.2.2
Using rails-html-sanitizer 1.0.4
Using actionview 5.2.0
Using rack 2.0.5
Using rack-test 1.0.0
Using actionpack 5.2.0
Using nio4r 2.3.1
Using websocket-extensions 0.1.3
Using websocket-driver 0.7.0
Using actioncable 5.2.0
Using globalid 0.4.1
Using activejob 5.2.0
Using mini_mime 1.0.0
Using mail 2.7.0
Using actionmailer 5.2.0
Using activemodel 5.2.0
Using arel 9.0.0
Using activerecord 5.2.0
Using mimemagic 0.3.2
Using marcel 0.3.2
Using activestorage 5.2.0
Using net-ssh 5.0.2
Using net-scp 1.2.1
Using sshkit 1.16.1
Using airbrussh 1.3.0
Using annotate 2.7.4
Using ansi 1.5.0
Using graphql 1.8.4
Using apollo-tracing 1.6.0
Using ast 2.4.0
Using awesome_print 1.8.0
Using bcrypt 3.1.12
Using msgpack 1.2.4
Using bootsnap 1.3.0
Using bundler 1.16.2
Using byebug 10.0.2
Using capistrano 3.11.0
Using capistrano-bundler 1.3.0
Using capistrano-passenger 0.2.0
Using capistrano-rails 1.4.0
Using capistrano-rbenv 2.1.3
Using with_advisory_lock 4.0.0
Using closure_tree 6.6.0
Using coderay 1.1.2
Using dry-configurable 0.7.0
Using dry-container 0.6.0
Using dry-core 0.4.7
Using dry-equalizer 0.2.1
Using dry-events 0.1.0
Using dry-inflector 0.1.2
Using dry-logic 0.4.2
Using dry-matcher 0.7.0
Using dry-monads 1.0.0
Using dry-transaction 0.13.0
Using dry-types 0.13.2
Using dry-validation 0.12.0
Using multipart-post 2.0.0
Using faraday 0.15.2
Using ffi 1.9.25
Using graphql-errors 0.2.0
Using graphql-guard 1.2.0
Using jaro_winkler 1.5.1 (x86_64-darwin-17)
Using jwt 2.1.0
Using rb-fsevent 0.10.3
Using rb-inotify 0.9.10
Using ruby_dep 1.5.0
Using listen 3.1.5
Using method_source 0.9.0
Using ruby-progressbar 1.9.0
Using minitest-reporters 1.3.0
Using thor 0.20.0
Using railties 5.2.0
Using sprockets 3.7.2
Using sprockets-rails 3.2.1
Using rails 5.2.0
Using minitest-spec-rails 5.4.0
Using nexmo 5.2.0
Using parallel 1.12.1
Using parser 2.5.1.0
Using pg 1.0.0
Using powerpack 0.1.2
Using pry 0.11.3
Using pry-rails 0.3.6
Using puma 3.11.4
Using rack-cors 1.0.2
Using rainbow 3.0.0
Using rein 3.5.0
Using rotp 3.3.1
Using unicode-display_width 1.4.0
Using rubocop 0.57.2
Using sentry-raven 2.7.4
Bundler attempted to update dry-transaction but its version stayed the same
Bundle updated!
[~/P/P/R/v/api|2.5.1|2.7.15]
‹master*!+1› »»»»                                                             0|16:54:16
[dry-types] Int type was renamed to Integer
[dry-types] Form types were renamed to Params
Loading development environment (Rails 5.2.0)
[1] pry(main)> reload!; aaa = Sessions::GenerateAuthToken.new.call({user: User.new})
Reloading...
=> Failure({:user=>["model must be persisted in the database"]})
[2] pry(main)> aaa.value
NoMethodError: undefined method `value' for Failure({:user=>["model must be persisted in the database"]}):Dry::Monads::Result::Failure
Did you mean?  value!
from (pry):2:in `__pry__'
[3] pry(main)>
dry-transaction 0.13.0
I figured I could use .value_or or .value! for the Success one, but I don't know what to do in case of Failure
As .value_or returns nil and .value! throws an exception
Igor S. Morozov
@Morozzzko
Jul 05 2018 14:58
Just to clarify: is the exception cased by your code, or is it a bug in dry-transaction?
use #failure to extract data from Failure
Jaromír Červenka
@Cervajz
Jul 05 2018 14:58
@Morozzzko Thanks! :)
the .value! exception is intended I suppose
Dry::Monads::UnwrapError: value! was called on Failure({:user=>["model must be persisted in the database"]})
Igor S. Morozov
@Morozzzko
Jul 05 2018 14:59
Yes, it’s intentional
Jaromír Červenka
@Cervajz
Jul 05 2018 14:59
so just to recap .value_for in case of Success and .failure for Failure one
Makes sense, as .value for Failure was kinda strange
@Morozzzko Thank you for your help :)
Igor S. Morozov
@Morozzzko
Jul 05 2018 15:00
There’s also #success
Jaromír Červenka
@Cervajz
Jul 05 2018 15:01
Even better!
Igor S. Morozov
@Morozzzko
Jul 05 2018 15:02
Since you need to extract data from the Failure, you could also pass an identity function to or_fmap to convert Failure(x) into Success(x) and then use value!
Dry::Monads.Failure("foo").or_fmap(&:itself).value!
“foo”
Jaromír Červenka
@Cervajz
Jul 05 2018 15:04
Ah I see. .failure works well now, but I'll check that
Grant Shangreaux
@gcentauri
Jul 05 2018 15:46
hi, just updated to dry-validation 0.12.0 and notice these warnings when i run rspec [dry-types] Int type was renamed to Integer [dry-types] Form types were renamed to Params does that imply they are in my codebase somewhere? i can't seem to find them if so
Nikita Shilnikov
@flash-gordon
Jul 05 2018 16:12
Grant Shangreaux
@gcentauri
Jul 05 2018 16:24
oh ok, so if i reinstall the gem should it disappear?
Nikita Shilnikov
@flash-gordon
Jul 05 2018 16:26
add/replace dry-validation in your Gemfile gem 'dry-validation', git: 'https://github.com/dry-rb/dry-validation', run bundle, run your tests/load your app and see if warnings gone
Grant Shangreaux
@gcentauri
Jul 05 2018 16:35
ah, i'm developing a gem so not using Gemfile. seems like harmless warnings, I can wait for a patch
also, i am putting custom predicates in their own module. is it recommended to write unit tests for these predicates? it feels a bit redundant
Piotr Solnica
@solnic
Jul 05 2018 16:42
nah, feels like an overkill
Grant Shangreaux
@gcentauri
Jul 05 2018 17:01
haha, well from @solnic i will take it ;) by the way, thanks for all the inspiring work from everyone at dry-rb! my interest in ruby has jumped up a whole bunch from beginning to work with your libraries
Piotr Solnica
@solnic
Jul 05 2018 17:03
ahh thanks for sharing that here :)
Grant Shangreaux
@gcentauri
Jul 05 2018 18:18

so, I've used dry-types to declare some Enums like

Stuff = Types::Strict::Symbol.enum(:FOO, :BAR, :BAZ)

in a validation schema i've resorted to using something like

required(:stuff).value(included_in?: Stuff.values)

in order to get the error message i want out of it. is there a better way? not that this is difficult by any means, i'm just curious if I am missing something

Grant Shangreaux
@gcentauri
Jul 05 2018 19:42

sorry for the 'flood' of questions. I have a sticky situation, that probably needs refactoring, but i'm wondering...

I have a nested hash in my input params, and the required/optional keys change depending on the value of one particular key that indicates its "type". writing high level rules to validate that seems convoluted, so I thought about making separate schemas for each possible configuration. can i conditionally validate this nested hash with an appropriate schema, or is this an issue that should be refactored and broken down differently?

Grant Shangreaux
@gcentauri
Jul 05 2018 20:08
seems like the thing to do is probably validate the presence and type of the nested param and then in the business logic pull it out and validate it in a separate step on its own.