Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
  • 19:07
    jjw starred dry-rb/dry-types
  • 18:13

    flash-gordon on master

    Remove unreachable method (compare)

  • 18:11

    flash-gordon on master

    Remove Dry::Types.type_keys It… (compare)

  • 18:09

    flash-gordon on master

    Remove unreachable code (compare)

  • 18:04

    flash-gordon on master

    Coverage for function.rb (compare)

  • 17:15

    flash-gordon on fix-maybe-call-safe

    (compare)

  • 17:15

    flash-gordon on master

    Fix behavior of Maybe#call_safe… Merge pull request #380 from dr… (compare)

  • 17:15
    flash-gordon closed #380
  • 17:13
    flash-gordon synchronize #380
  • 17:13

    flash-gordon on fix-maybe-call-safe

    Fix behavior of Maybe#call_safe… (compare)

  • 17:12
    flash-gordon opened #380
  • 17:11

    flash-gordon on fix-maybe-call-safe

    Fix behavior of Maybe#call_safe… (compare)

  • 17:00

    flash-gordon on fix-maybe-try

    (compare)

  • 17:00

    flash-gordon on master

    Fix behavior of Types::Maybe#try Merge pull request #379 from dr… (compare)

  • 17:00
    flash-gordon closed #379
  • 15:09

    flash-gordon on master

    Fix typo Merge pull request #67 from gru… (compare)

  • 15:09
    flash-gordon closed #67
  • 14:43
    flash-gordon opened #379
  • 14:43

    flash-gordon on fix-maybe-try

    Fix behavior of Types::Maybe#try (compare)

  • 14:30

    flash-gordon on master

    Lax coverage (compare)

Darcy Laycock
@Sutto
@solnic when do you get in?
Piotr Solnica
@solnic
@Sutto Sunday morning
we’re going to London first, spending the night, then jumping on a plane on Saturday again
Darcy Laycock
@Sutto
awesome - all sorted for when you get here?
Piotr Solnica
@solnic
I hope so :laughing:
Darcy Laycock
@Sutto
The Rubyconf AU organisers are usually pretty fantastic at having all basses covered haha
Piotr Solnica
@solnic
oh yes they are amazing
Tim Riley
@timriley
@solnic FYI: I’m working on updating the dry-web-roda generators
Pat Collins
@patcoll
If I want to validate a list of email addresses at a particular key, what would be the syntax to do that?
Jonah
@jonahx
I’m trying to create a custom form validation. I got the validation part working but not sure how to customize the coercion part automatically. Here’s what I have so far:
schema = Dry::Validation.Form do
  configure do
    def future_date?(value)
      Date.new < Date.parse(value)
    end
  end
  required(:date).filled(:future_date?)
end
Piotr Solnica
@solnic
@jonahx filled(:date?, :future_date?)
Jonah
@jonahx
@solnic ah, so simple. ty sir!
@solnic but say i needed to coerce to some custom object, MyCustomObj. is this easily possible too?
Piotr Solnica
@solnic
@jonahx why?
Jonah
@jonahx
@solnic, i’m not sure i understand the question. why do you coerce into built-in ruby objects like Date or Integer?
Piotr Solnica
@solnic
why you want to coerce to a custom object :)
Jonah
@jonahx
i’ll make an example, since my current example the above works well :). but say user enters a hex value for a color into a form. i want to validate it’s a valid hex value and coerce into a custom Color object that has some nice methods for working with colors, say.
Piotr Solnica
@solnic
do you need a color object for something else than the validation?
Jonah
@jonahx
yeah the “domain” code that uses the params is what would use it. So no, the Color wouldn’t be used within the validation.
Piotr Solnica
@solnic
@jonahx you can do this for more control http://dry-rb.org/gems/dry-validation/input-preprocessing/
explicit type specs will be default API in 1.0.0 btw
Jonah
@jonahx
@solnic thx for link i will reread that part. one more quick question is there a quick way to define error messages without going through a custom yaml file? eg, in this case i only need to define a single error message for this one custom future_date? method and i’d prefer to define it in code near where future_date itself is defined
I guess we should document this
Jonah
@jonahx
@solnic cool, ty. i was just in the midst of using pry to try to figure that out :), you saved me some minutes. i’d even recommend a chrome method over that , but that might be a micro-optimization
Jonah
@jonahx
@solnic I’m getting an uninitialized constanct Messages error:
schema = Dry::Validation.Form do
  configure do
    def future_date?(value)
      Date.today < value
    end
    def self.messages
      Messages.default.merge(
        en: { errors: { future_date?: 'Date must be in the future' } }
      )
    end
  end
  required(:date).filled(:date?, :future_date?)
end
i thought it was because i was in Form instead of Schema but Schema isn’t working for me either...
Jonah
@jonahx
@solnic finally got it working. not sure if it’s the best way or why the way in your spec didn’t work for me, but the following works:
schema = Dry::Validation.Form do
  configure do
    def future_date?(value)
      Date.today < value
    end
    def self.messages
      default_messages.merge(
        en: { errors: { future_date?: 'Date must be in the future' } }
      )
    end
  end
  required(:date).filled(:date?, :future_date?)
end
Piotr Solnica
@solnic
@jonahx IIRC we have include Dry::Validation in spec_helper there heh
which is probably a stupid idea
Jonah
@jonahx
@solnic do i have the Piotr stamp of approval on what I did above? :)
Piotr Solnica
@solnic
@jonahx does it work? :D
Jonah
@jonahx
@solnic it does! i think it would be better to merge on messages rather than default_messages, but you get infinite recursion doing that...
Piotr Solnica
@solnic
it’s tricky stuff
defo a focus for 1.0.0
(to improve it)
Jonah
@jonahx
ok thx. for my immediate purposes this is totally fine, so nbd
Piotr Solnica
@solnic
cool
I’m not a fan of defining user-facing things in code, hence I didn’t add any nice way of defining custom messages inside code
it’s possible, but I don’t like it
I get that people often just need the quick’n’dirty solution though
and adding a special yaml file is not always desirable
I just didn’t have the need for a different approach than a yaml file because my context has been always an app with locales, where I keep dry-v’s messages
Jonah
@jonahx
@solnic fair enough. i agree in most apps of any size at all a yaml file is a better way to go. i just happen to making literally a single page form tool
Piotr Solnica
@solnic
sure thing, I’m not against it, so if somebody can make it better, then great
fwiw hanami-validation has a way of defining messages along with a predicate definition
IIRC sth like predicate(:foo?, message: “oh noez”) do.. end
Jonah
@jonahx
@solnic meh, i prefer your tools :)
Piotr Solnica
@solnic
it’s based on dry-v (as its validation engine)
but thanks :D