Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
Fran Worley
@fran-worley
We need message types again like with size don't we...
Ralf Schmitz Bongiolo
@mrbongiolo
When an array is used, then the messages receives a list, when a range is used then it receives list_left and list_right, but the key to lookup is always the same: errors.included_in?
I guess so
changing my yml to this:
    included_in?:
      arg:
        default: "tamanho tem que ser %{list}"
        range: "tamanho tem que estar entre: %{list_left} - %{list_right}"
Fran Worley
@fran-worley
Any luck?
Ralf Schmitz Bongiolo
@mrbongiolo
yep, it worked
I'll update the default errors.yml and send a PR
Fran Worley
@fran-worley
Thanks can up change excluded_from aswell?
Ralf Schmitz Bongiolo
@mrbongiolo
ok
shouldn't we get rid of exclusion? and inclusion? keys already?
Fran Worley
@fran-worley
They have to stay as the predicates are just deprecated
I probably wouldn't bother updating them as people should just migrate to the new predicate names.
Ralf Schmitz Bongiolo
@mrbongiolo
Ok, no problem
Ralf Schmitz Bongiolo
@mrbongiolo
@solnic dynamic arguments doesn't work with rules?
Piotr Solnica
@solnic
@mrbongiolo you mean rule API?
Ralf Schmitz Bongiolo
@mrbongiolo
Yes @solnic
I was trying to use something like: rule() { year.gteq?(current_year) and having that current_year defined in the configure block, but it said that the it couldn't find the predicate
Piotr Solnica
@solnic
yes it’s not supported yet
Ralf Schmitz Bongiolo
@mrbongiolo
Ah ok
John Backus
@backus
@hectorsq thanks
Piotr Solnica
@solnic
@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
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

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
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