Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
  • Apr 05 17:01
    emaraschio starred dry-rb/dry-monitor
  • Apr 04 15:38
    nepalez closed #74
  • Apr 04 15:38
    nepalez commented #74
  • Apr 04 10:40
    qortex commented #400
  • Apr 04 08:47
    flash-gordon closed #400
  • Apr 04 08:47
    flash-gordon commented #400
  • Apr 03 21:18
    qortex starred dry-rb/dry-types
  • Apr 03 21:14
    qortex edited #400
  • Apr 03 21:14
    qortex labeled #400
  • Apr 03 21:14
    qortex opened #400
  • Apr 03 19:18
    landongrindheim commented #74
  • Apr 02 19:47
    kamilski81 starred dry-rb/dry-monads
  • Apr 02 17:26
    waleedasif322 starred dry-rb/dry-types
  • Apr 02 14:59
    sskylar starred dry-rb/dry-monads
  • Apr 02 13:51
    kirin121 starred dry-rb/dry-container
  • Apr 02 10:56

    davydovanton on performance-improvements-for-rack-monitorring

    (compare)

  • Apr 02 10:55

    davydovanton on master

    Improve memory allocation for R… Merge pull request #34 from dry… (compare)

  • Apr 02 10:55
    davydovanton closed #34
  • Apr 02 02:25
    DaiAoki starred dry-rb/dry-types
  • Apr 01 14:39
    davydovanton commented #34
Piotr Solnica
@solnic
Yep. One of the many use cases

validateallthethings

Whoops
Hannes Nevalainen
@kwando
markdown =P
Piotr Solnica
@solnic
Hashtag goes wrong ;)
Andy Holland
@AMHOL

hashtaggoeswrong

Chris Richards
@cmrichards
Hey solnic, thanks for all your work on Virtus
Piotr Solnica
@solnic
@cmrichards hey, my pleasure, although I’m no longer working on it ;)
Chris Richards
@cmrichards
I know, that's why I'm saying thanks!
Any idea when dry-data and dry-validation will be ready enough to use in place of Virtus?
@solnic
Piotr Solnica
@solnic
depends on what you need :)
I stopped using virtus already fwiw
philosophy is quite different than in virtus
so it requires a different approach
which is why it cannot be treated as a replacement
Chris Richards
@cmrichards
@solnic I use Virtus only for web forms in rails. I include activerecord validations. It works perfectly.
It's hard to imagine anything simpler
Piotr Solnica
@solnic
really? dry-data/validation is not just simpler but more powerful :D
Chris Richards
@cmrichards
Great, i'll try it.
Piotr Solnica
@solnic
I'm wrapping up stuff for dry-v 0.4.0
Chris Richards
@cmrichards
If I have a User class, "class User < Dry::Data::Struct", can you just do User.new(params[:user]) to create an instance?
Piotr Solnica
@solnic
it's gonna reach 1.0.0 once I figure out how to optimize errors, this part will need quite some work
Chris Richards
@cmrichards
It's not clear in the docs
Piotr Solnica
@solnic
yes, although structs are strict wrt hash input, it'll raise when keys are missing
it's not a replacement for virtus models
ie dry-v builds up a coercible hash using dry-d for Schema::Form, it does form coercions for you and symbolizes keys
there are different types of hashes in dry-d, so you have a strict one, a non-strict one, non-strict with symbolized-keys (that's the one that dry-v is using)
Piotr Solnica
@solnic
dry-d structs and values are meant to be used as your domain data types, strictness is encouraged too
not just wrt type primitives but also any possible constraints
there’s a lot tbd to improve errors coming from dry-d though, it’s a bit rough right now
Chris Richards
@cmrichards
So how would you do something simple like this in drd? https://gist.github.com/cmrichards/364920a5ffd6c49420c5
Piotr Solnica
@solnic
gimme a minute, I actually just added new features to dry-v to allow this
Piotr Solnica
@solnic
class BarcodeSchema < Dry::Validation::Schema::Form
  key(:barcode, &:filled?)
  key(:job_number) { |v| v.none? | v.int? }
  key(:sample_number) { |v| v.none? | v.int? }

  rule(:barcode_only) do
    rule(:barcode) ^ (rule(:job_number) | rule(:sample_number))
  end

  def self.messages
    Dry::Validation::Messages.default.merge(
      en: { errors: {
        barcode_only: 'Can only enter data into barcode OR job/sample fields, not both'
      }}
    )
  end
end
@cmrichards something like that will be possible starting from dry-v 0.4.0
I’m not sure if people will like using logic in the long term so maybe we can introduce higher-level macros, but I dunno, I kinda like it, forces you to think in terms of pure logic
Chris Richards
@cmrichards
I agree.
It looks pretty good
and you do BarcodeScheme.new(params[..]) ?
Piotr Solnica
@solnic
oh and typically you want to put error messages in a yaml file
uhm, actually this is not an equivalent of your example, seems like we need a negation support there
Chris Richards
@cmrichards
I get the idea though
Piotr Solnica
@solnic
ok cool :)
Chris Richards
@cmrichards
is there a "valid?" method or is that done differently?
Piotr Solnica
@solnic
no, it’s stateless
so it’s schema = MySchema.new and schema.call(params)
it returns a result object back with a ton of information
Chris Richards
@cmrichards
And the result object is a hash?
Piotr Solnica
@solnic
it’s a validation result object, it responds to #messages which gives you compiled error messages as a hash with access to string error messages and the input for each error
{:barcode_only=>[["Can only enter data into barcode OR job/sample fields, not both"], "123"]}
sth like that