These are chat archives for dry-rb/chat

19th
Sep 2016
Piotr Solnica
@solnic
Sep 19 2016 00:22
@wafcio we shouldn’t show required(:name).value(:filled?) as required(:name).filled is a shorter equivalent, where did you see it exactly?
Kimmo Lehto
@kke
Sep 19 2016 07:05
great. "dry-monads-0.2.0 requires ruby version >= 2.1.0, which is incompatible with the..."
Kimmo Lehto
@kke
Sep 19 2016 07:15
every week our installs break because of dry dependencies, grr!
John Backus
@backus
Sep 19 2016 07:21
@kke Do you have a question or are you just venting? It shouldn't break your build if you lock it to your minor version. The gem is not 1.0 so there aren't any guarantees
Kimmo Lehto
@kke
Sep 19 2016 07:23
mostly venting.
John Backus
@backus
Sep 19 2016 07:27
Alrighty. I can't speak for the dry-rb organization since I'm not a core contributor but I'd recommend not venting in gitter/in a public forum with contributors. As far as I know everyone contributing to dry-rb things is doing so for free.
Kimmo Lehto
@kke
Sep 19 2016 07:27
yes and the gems are quite nice.
John Backus
@backus
Sep 19 2016 07:28
Glad you like them :smile:
Christopher Dennl-Ortega Arrieta
@cdennl
Sep 19 2016 09:34

@solnic I am trying to make a little standalone script but when i try to execute this:

require 'dry/validation/schema'

schema = Dry::Validation.Schema do
  required( :is_accepted ).filled( :bool? )
  optional( :comment ).maybe( :str?, size?: (5..2000) )

  rule( check_comment_on_reject: [ :is_accepted, :comment ] ) do |is_accepted, comment|
    is_accepted.false? > comment.filled?
  end
end

schema.( is_accepted: false, comment: nil ).inspect

I get this error:

christopher@debian-vm:~$ ruby dry-v.rb 
/usr/local/rvm/gems/ruby-2.3.1/gems/dry-logic-0.3.0/lib/dry/logic/predicate.rb:19:in `<class:Predicate>': undefined method `Equalizer' for Dry:Module (NoMethodError)
Did you mean?  equal?
    from /usr/local/rvm/gems/ruby-2.3.1/gems/dry-logic-0.3.0/lib/dry/logic/predicate.rb:11:in `<module:Logic>'
    from /usr/local/rvm/gems/ruby-2.3.1/gems/dry-logic-0.3.0/lib/dry/logic/predicate.rb:2:in `<module:Dry>'
    from /usr/local/rvm/gems/ruby-2.3.1/gems/dry-logic-0.3.0/lib/dry/logic/predicate.rb:1:in `<top (required)>'
    from /usr/local/rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:68:in `require'
    from /usr/local/rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:68:in `require'
    from /usr/local/rvm/gems/ruby-2.3.1/gems/dry-logic-0.3.0/lib/dry/logic/predicate_set.rb:1:in `<top (required)>'
    from /usr/local/rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:68:in `require'
    from /usr/local/rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:68:in `require'
    from /usr/local/rvm/gems/ruby-2.3.1/gems/dry-logic-0.3.0/lib/dry/logic/predicates.rb:5:in `<top (required)>'
    from /usr/local/rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:68:in `require'
    from /usr/local/rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:68:in `require'
    from /usr/local/rvm/gems/ruby-2.3.1/gems/dry-validation-0.9.5/lib/dry/validation/schema.rb:1:in `<top (required)>'
    from /usr/local/rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:127:in `require'
    from /usr/local/rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:127:in `rescue in require'
    from /usr/local/rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:40:in `require'
    from dry-v.rb:1:in `<main>'
Nikita Shilnikov
@flash-gordon
Sep 19 2016 09:46
@kke we had some issues with 2.0 support regarding required kw arguments and a few others. Since it's now EOL, we started to remove it from Travis configs, therefore we can't guarantee everything will work on 2.0. It's better to get a meaningful error about version incompatibility, than have a weird SyntaxError exception
also, imo, it's not a good idea to have relaxed dependencies when you're using ruby 2.0, I have Gemfile.lock in all of my commercial projects, this way I can be sure I'll have the same environment on every deploy
and, after all, upgrading to a fresher ruby version shouldn't be hard, it's pretty stable nowadays
Christopher Dennl-Ortega Arrieta
@cdennl
Sep 19 2016 09:50
@solnic solved it doesn't seem to be a dry-v error
@solnic seems to be reform ill investigate further
Christopher Dennl-Ortega Arrieta
@cdennl
Sep 19 2016 11:24
@solnic investigation yielded (like so often): own dumbness, I used ! (not), ... which is wrong :D
Michał Gutowski
@CucumisSativus
Sep 19 2016 18:16

Hey guys i'm pretty fresh to dry monads and i've got a question about fmap. Lets suppose i've got code like this:

      validate.fmap do |valid_attributes|
        form.save.fmap do |valid_postcard|
          mailer.send_postcard(to_email: email, postcard: valid_postcard).deliver_now
          valid_postcard
        end
      end

both validate and form.save returns Left or Right. Is there a way to chain both those functions so they return Left or Right at the end of the chain? Now, when form.save returns Left at the end of the day I have Right(Left(errors)).
Am I doing something wrong? Is there a way to make it chainable?

Nikita Shilnikov
@flash-gordon
Sep 19 2016 18:32
@CucumisSativus value combining will be probably added in future, but right now you can just do validate.bind instead of validate.fmap, this will give the result you want
Michał Gutowski
@CucumisSativus
Sep 19 2016 18:34
@flash-gordon yeah that's exactly what i was looking for. Thanks a lot!
Nikita Shilnikov
@flash-gordon
Sep 19 2016 18:34
np :)
Michał Gutowski
@CucumisSativus
Sep 19 2016 18:38
@flash-gordon would you mind if I put your name (site?) in special thanks in my blogpost?
Nikita Shilnikov
@flash-gordon
Sep 19 2016 19:04
@CucumisSativus I would not :) I don't have a site, you can add a gh link or twitter if you wish https://twitter.com/NikitaShilnikov
oh, well, that preview again
Michał Gutowski
@CucumisSativus
Sep 19 2016 19:10
i'll let you know once I publish it :)
Jānis Miezītis
@janjiss
Sep 19 2016 21:43
Hey folks, how would one deep copy Dry Container instance? :)
I want inherited object to have container with same values:
    def inherited(subclass)
      subclass.instance_variable_set(:"@container", Marshal.load(Marshal.dump(_container)))
    end
It works this way, just woundering if there is a better way to do it
Jānis Miezītis
@janjiss
Sep 19 2016 21:49
Well, I think this is better:
    def inherited(subclass)
      subclass_container = Dry::Container.new
      _container.each_key do |k|
        subclass_container.register(k, _container.resolve(k).clone)
      end
      subclass.instance_variable_set(:"@container", subclass_container)
    end