Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
Piotr Solnica
@solnic
I’ve NO IDEA how to use I18n
trying to figure it out from the API docs, w/o success
that’s just sad
Piotr Solnica
@solnic
def initialize
  @t = I18n.method(:t)
end

def lookup(predicate, arg)
  t.("errors.#{predicate}")
end
they see me callin, they hatin
Andy Holland
@AMHOL
:joy:
Piotr Solnica
@solnic
ok, I got it working, the same functionality is covered as with the built-in YAML messages
I need to…dry it up
there’s a bit of common, abstract functionality there
one interesting thing is that it is possible to provide error compiler that will convert our error representation to an AM-compatible structure so that in theory existing AM-based error message translations will work with it
ain’t gonna do it, just saying it’s possible ;)
Andy Holland
@AMHOL
:laughing:
Piotr Solnica
@solnic
Calculating -------------------------------------
ActiveModel::Validations
                       143.000  i/100ms
      dry-validation   927.000  i/100ms
-------------------------------------------------
ActiveModel::Validations
                          1.495k (± 7.3%) i/s -      7.579k
      dry-validation      9.429k (± 1.6%) i/s -     47.277k

Comparison:
      dry-validation:     9428.8 i/s
ActiveModel::Validations:     1494.6 i/s - 6.31x slower
this is AM+I18n-coercions vs dry-validation+I18n+coercions
Andy Holland
@AMHOL
:clap:
@solnic out of interest, how come you did class Messages::I18n rather than the usual nesting?
Piotr Solnica
@solnic
I really don’t know
I guess I’m inspired by current polish gov, so from now on “it’s just how it’s gonna be, because"
Andy Holland
@AMHOL
lol
Piotr Solnica
@solnic
the people want it, don’t you know
seriously though, just trying to avoid nesting
but it comes with the cost of having to require things in diff order
Andy Holland
@AMHOL
Yeah, I guess the loading errors come sparsely without Rails
Andy Holland
@AMHOL
@solnic 100 stars for dry-validation :D
Piotr Solnica
@solnic
I know, I wrote a script that notifies me via sms whenever it’s starred #noididnt
Andy Holland
@AMHOL
:joy:
I would've believed that you know
Too gullible
Luca Guidi
@jodosha
:100: :star2: :confetti_ball:
Piotr Solnica
@solnic
@jodosha :dancers:
Piotr Solnica
@solnic
@AMHOL thoughts on how to tackle complex error messages when you need more data than just input for a rule?
Andy Holland
@AMHOL
Not sure I understand fully, do you have an example?
Piotr Solnica
@solnic
ie you want to generate a message and provide a list of possible values that are dynamic, so you can’t hardcode it in the schema
basically every use case where a message needs data that come from some external source
Andy Holland
@AMHOL
I don't think we should do that
Piotr Solnica
@solnic
but it’s needed :)
Andy Holland
@AMHOL
lol
Piotr Solnica
@solnic
I told you I have all kinds of validation use cases :)
I have a couple of messages that need to do extra db lookups to provide meaningful feedback
Andy Holland
@AMHOL
What if there's a list of 500 values returned?
Piotr Solnica
@solnic
don’t get stuck on this silly example :)
it’s your job to construct that message, not dry-v's
but we need an interface to allow that
that’s what I’m asking
basically an equivalent of :message option in AM::V
with the exception of “option” part, because options in dsl are a horrible horrible idea (I’ll be repeating that all the time)
Andy Holland
@AMHOL
Shouldn't they be custom validations/integrations?
Piotr Solnica
@solnic
well, you could provide your own Messages implementation, subclass one of the built-in ones, and have a customized lookup (or whatever it’s gonna be called eventually)
Andy Holland
@AMHOL
Sorry, think I still don't understand exactly what you're asking :laughing:
Piotr Solnica
@solnic
@AMHOL you define a rule ie key(:book) { |book| book.publish? } and that predicate returns false when a system-level setting “publishing_turned_off” is set and it needs to set a message “sorry, but book publishing is turned off until %{date}” and date is retrieved from the database.