These are chat archives for dry-rb/chat

20th
Jul 2016
John Backus
@backus
Jul 20 2016 04:35
@hectorsq thanks
Piotr Solnica
@solnic
Jul 20 2016 16:33
@dsounded hey man, sorry for this late reply. Help is appreciated although I have to say that’s probably the worst task for a first contribution :) I’ll try to do it this Friday and hopefuly push a new release
Joe Van Dyk
@joevandyk
Jul 20 2016 16:54
what’s the best way to validate a hash that looks like this? { id: 550, name: "Arts", child: { id: 123, name: "Prints", child: { … } } ?
Kevin Ross
@rosskevin
Jul 20 2016 17:07

I'm trying to get a reusable schema initializer with my common options included, but can't quite get it right. Is there an easier option or can you spot the error in my syntax?

module Form
    module Validations
      require 'i18n'
      require 'dry-validation'

      def self.new_schema(options, &block)
        Dry::Validation.Schema(options) do
          configure do
            predicates(Predicates)
            config.messages = :i18n
          end

          yield(block)
        end
      end
    end
  end

yields NoMethodError: undefined method required for usage Validations.new_schema(build: false) { required(:user).filled(:str?) }

my yield foo is not the best
Kevin Ross
@rosskevin
Jul 20 2016 17:37
Got it. Still wondering if there are better ways:
      def self.new_schema(options, &block)
        Dry::Validation.Schema(options) do
          configure do
            predicates(Predicates)
            config.messages = :i18n
          end

          instance_eval &block
        end
      end
Piotr Solnica
@solnic
Jul 20 2016 17:54
@rosskevin just define a class set it up and pass it to Schema() constructor function
Kevin Ross
@rosskevin
Jul 20 2016 17:58
great, thanks!
John Backus
@backus
Jul 20 2016 18:37
Wrote up a pretty comprehensive post on new features in Ruby 2.4: https://blog.blockscore.com/new-features-in-ruby-2-4/
Not related to dry-rb but I wanted to share with people here
Piotr Solnica
@solnic
Jul 20 2016 21:43
@backus thanks for sharing. Very nice write up
Folks at work shared it too today and I was like "hey I know the author!" :)
Fran Worley
@fran-worley
Jul 20 2016 22:08
@backus thanks, your post is very clear and well written. Sounds like there's some really good stuff in there.
Andy Holland
@AMHOL
Jul 20 2016 22:28
Enumerable#sum, fantastic :laughing:
John Backus
@backus
Jul 20 2016 22:42
@solnic @fran-worley thanks! I'm glad you liked it
@AMHOL I'm predicting now that this will result in some rails-core vs. ruby-core conflict :smile: :worried:
Ruby core developer opening an issue saying ActiveSupport should change their implementation: rails/rails#24796
Rails contributor (schneems) asking ruby core to try to match ActiveSupport's implementation: https://bugs.ruby-lang.org/issues/12217#note-9
yikes
Piotr Solnica
@solnic
Jul 20 2016 23:13
Well, enum#sum is not a good idea in general since enumerable is a pretty wide interface
John Backus
@backus
Jul 20 2016 23:29
I think it seems fairly reasonable
The actual ruby core thread is basically like
We grepped through a ton of ruby gems and .inject(:+) is heavily used
might as well add #sum
Andy Holland
@AMHOL
Jul 20 2016 23:42
@backus :joy:
#rubydrama
@solnic that's what I was thinking too