Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
  • 06:15
    solnic commented #32
  • Mar 03 18:03
    nertzy starred dry-rb/dry-monads
  • Mar 03 12:56
    timriley synchronize #161
  • Mar 03 12:56

    timriley on add-0-19-0-changelog

    Add changelog entry for 0.19.0 (compare)

  • Mar 03 12:55
    timriley synchronize #161
  • Mar 03 12:55

    timriley on add-0-19-0-changelog

    Add changelog entry for 0.19.0 (compare)

  • Mar 03 12:50
    timriley review_requested #161
  • Mar 03 12:50
    timriley review_requested #161
  • Mar 03 12:50
    timriley review_requested #161
  • Mar 03 12:50
    timriley opened #161
  • Mar 03 12:49

    timriley on add-0-19-0-changelog

    Add changelog entry for 0.19.0 (compare)

  • Mar 03 11:39

    timriley on update-docsite-for-component-dirs

    (compare)

  • Mar 03 11:39

    timriley on master

    Reference dry-system without co… Use component_dirs config in do… Merge pull request #160 from dr… (compare)

  • Mar 03 11:39
    timriley closed #160
  • Mar 03 11:35
    timriley review_requested #160
  • Mar 03 11:35
    timriley opened #160
  • Mar 03 11:30

    timriley on update-docsite-for-component-dirs

    Reference dry-system without co… Use component_dirs config in do… (compare)

  • Mar 03 11:19

    timriley on master

    Avoid freezing components Thes… Add dirs to load path so earlie… Extract Identifier; support mix… and 2 more (compare)

  • Mar 03 11:19

    timriley on support-component-dirs-with-mixed-namespaces

    (compare)

  • Mar 03 11:19
    timriley closed #158
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
Chris Richards
@cmrichards
I see. So there will be more work needed for it to work with Rails form_for helpers?
I look forward to using it. For now I gotta go. Thanks.
This seems a bit like reform contracts?
the "reform" gem
Piotr Solnica
@solnic
reform will use it soon (or even already has support for it)
we collaborate with Nick a lot lately
Chris Richards
@cmrichards
excellent
Piotr Solnica
@solnic
btw the missing ingredient is this:
rule(:barcode_only) do
  rule(:barcode) ^ not(rule(:job_number) | rule(:sample_number))
end
notice not
I gotta add it, it’s gonna be useful in many places anyway
Chris Richards
@cmrichards
What's the ^?
Piotr Solnica
@solnic
xor
Chris Richards
@cmrichards
k
Piotr Solnica
@solnic
either side must be true to make it all true
Chris Richards
@cmrichards
I know my CS ;-)
Piotr Solnica
@solnic
:)
Chris Richards
@cmrichards
Although I didn't know it was a ruby operator until now!
Piotr Solnica
@solnic
hah yeah, it’s a native operator in ruby
true ^ true => false
true ^ false => true
Chris Richards
@cmrichards
yeah I just tried that