Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
Kevin Ross
@rosskevin
my yield foo is not the best
Kevin Ross
@rosskevin
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
@rosskevin just define a class set it up and pass it to Schema() constructor function
Kevin Ross
@rosskevin
great, thanks!
John Backus
@backus
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
@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
@backus thanks, your post is very clear and well written. Sounds like there's some really good stuff in there.
Andy Holland
@AMHOL
Enumerable#sum, fantastic :laughing:
John Backus
@backus
@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
Well, enum#sum is not a good idea in general since enumerable is a pretty wide interface
John Backus
@backus
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
@backus :joy:
#rubydrama
@solnic that's what I was thinking too
Kiril Dokh
@dsounded
@solnic Well, ok, will wait for your solution, mate :)
Kevin Ross
@rosskevin
assuming option :model , -> { model }, is :auth_has_user? written correctly to fail if model.user.nil?
        validation do
          required(:email).filled
          required(:password).filled
          required(:jti).filled
          required(:iat).filled
          required(:exp).filled
          required(:sub).filled

          rule(auth_has_user?: [:email, :password]) do |email, password|
            email.filled?.then(password.filled?).then(!model.user.nil?)
          end
Kevin Ross
@rosskevin
nevermind, I don't think this should be written as a validation, more like the heart of the operation
Fran Worley
@fran-worley
@solnic are you around to chat about reform / dry-v integration? The way we do it now involves compiling 2 schemas for every validation block which a - crazy and b - makes it impossible to define & reuse configs
Piotr Solnica
@solnic
@fran-worley can you report a reform issue and describe it there? I’ll chime in
Fran Worley
@fran-worley
Will do
Piotr Solnica
@solnic
I’m trying to stay away from gitter until rom 2.0 is released
Kevin Ross
@rosskevin

here is my email predicate:

        def email?(value)
          !/[-a-z0-9_+\.]+\@([-a-z0-9]+\.)+[a-z0-9]{2,4}/i.match(value).nil?
        end

Used like required(:email).filled(:str?, :email?)
Can I just prepend str? && in the custom predicate and drop it from the usage?

Kevin Ross
@rosskevin
Any easy dry-validation magic for something like one_of i.e. one_of: [:a, :b]?
Fran Worley
@fran-worley
@rosskevin take a look at the dry validation site
There is a section on built in predicates. You want included_in
Kevin Ross
@rosskevin
ah, thanks for the pointer required(:sample).value(inclusion?: [1,3,5])
other point of confusion, when to use filled(..) vs value(..), for example this case^^^
Piotr Solnica
@solnic
@rosskevin filled prepends filled? & … predicate
so filled(:email?) == value(:filled?, :email?)
Kevin Ross
@rosskevin
so in the above, woulded we want required(:sample).filled(inclusion?: [1,3,5])
or is that redundant
Piotr Solnica
@solnic
probably redundant
Kevin Ross
@rosskevin
gotit, because an empty check is unnecessary at that point
Piotr Solnica
@solnic
don’t you want included_in?: [1, 3, 5] though?
oh wait, you don’t :)
Kevin Ross
@rosskevin
I was going to say it doesn't appear on the built-in predicates page
Piotr Solnica
@solnic
no wait, you do, we renamed inclusion to included_in
Kevin Ross
@rosskevin
ok
Piotr Solnica
@solnic
damn, gotta update the website docs
Kevin Ross
@rosskevin
I like the newer name