These are chat archives for dry-rb/chat

23rd
Apr 2016
Joe Van Dyk
@joevandyk
Apr 23 2016 02:28
So what's the latest on using dry-v and types in rails?
Andrew Kozin
@nepalez
Apr 23 2016 09:48
@solnic @AMHOL @timriley @marshall-lee & all: what do you think about this one: https://github.com/nepalez/dry-memoizer
(I keep extracting useful things from our current project)
Piotr Solnica
@solnic
Apr 23 2016 10:40
@nepalez do you know memoizable?
Andrew Kozin
@nepalez
Apr 23 2016 10:56
@solnic thanks! Yes, I do know it, but I dislike the DSL. As for me, let syntax is simpler and more readable in long computations.
tbh, I do not sure whether this let syntax sugar worth writing a special gem, I just try to extract it for a future.
Benjamin Klotz
@tak1n
Apr 23 2016 12:35

is there an easy way in dry-v to access the value for which a predicate returns false in the error message?
or do I have to write a custom error compiler for that?

basically:

  def custom_predicate(value)
     false
  end

   en:
    errors:
     custom_predicate: "{value} whatever"
Piotr Solnica
@solnic
Apr 23 2016 12:36
@tak1n IIRC we always pass value for interpolation, just try %{value} whatever
Benjamin Klotz
@tak1n
Apr 23 2016 12:37
@solnic works thx, and for predicates which have 2 args? :D
left, right?
Piotr Solnica
@solnic
Apr 23 2016 12:38
@tak1n left right is passed for ranges IIRC
lemme see (I forgot)
nah, we don’t pass in args by default. could be changed. please report an issue
@tak1n ^
Benjamin Klotz
@tak1n
Apr 23 2016 12:40
@solnic okay will do
panigrah
@panigrah
Apr 23 2016 14:47
@cdennl after you set messages to i18n, where is your custom file?
Christopher Dennl-Ortega Arrieta
@cdennl
Apr 23 2016 15:26
@panigrah config/locales/en/custom_dry_v_errors.yml
panigrah
@panigrah
Apr 23 2016 15:34
how does dry-v pickup the errors.yml file?
Christopher Dennl-Ortega Arrieta
@cdennl
Apr 23 2016 15:35
it doesnt, i18n does
and dry-v relies on i18n in this case
panigrah
@panigrah
Apr 23 2016 15:35
so the name of the file can be anything?
Christopher Dennl-Ortega Arrieta
@cdennl
Apr 23 2016 15:35
yes
you just have to set config.messages = :i18n to tell dry-v to rely on i18n
and assure that i18n is required before dry stuff
part of my initializer:
```
require 'i18n'
require 'cell/translation'
require 'reform/form/dry'
require 'disposable/twin/coercion'
panigrah
@panigrah
Apr 23 2016 15:38
ok. And all messages are directly under errors with the rule name?
errors:
    rule_name1?: "Rule has a problem" 
    rule_name2?: "Another rule problem" 
Christopher Dennl-Ortega Arrieta
@cdennl
Apr 23 2016 15:38
well common rules i put directly below errors if they are used in multiple contexts
otherwise i put them under a namespace below rules
en:
  errors:
    in_possession?:                         'is not in possession of deviation'
    is_conversion_correct?:                 'is incorrectly converted from P to $'
    not_blank?:                             'is blank'

    rules:
      auction:
        autobuy_amount_is_above_start_bid?: 'must be greater than start bid'
        currency_accepted?:                 'select at least one currency'
        is_conversion_correct?:             'is incorrectly converted from P to $'
      bid:
        is_no_self_bid?:                    'must not bid on own auction'
        is_running?:                        'is not running'
and then i set config.namespace = :whatever in the repsective validation group
panigrah
@panigrah
Apr 23 2016 15:40
aah okay.
I will try this out.
for now I have unique?: 'must be unique' directly under errors:. I did not make sure however to put the i18 before dry-v.
maybe thats why it isnt picking up.
Christopher Dennl-Ortega Arrieta
@cdennl
Apr 23 2016 15:42
and remember to restart the server then after adapting your initializer :)
panigrah
@panigrah
Apr 23 2016 15:44
no luck.
Dry::Validation::MissingMessageError: message for unique? was not found
Christopher Dennl-Ortega Arrieta
@cdennl
Apr 23 2016 15:45
mhh
all my statements are for drv-v 0.7.3
my config block looks like this:
```
configure do
        config.messages   = :i18n
        config.namespace  = :bid
        config.predicates = Dagavel::Predicates

        option :form

        def is_no_self_bid?( user )
          user.id != form.auction.user_id
        end

        def is_running?( auction )
          auction.is_running?
        end
      end
panigrah
@panigrah
Apr 23 2016 15:48

this is the yml file

en:
   hello: "Hello world"
   errors:
      unique? : "WTF"

and initializer has required i18n on top before dry-v and reform and configure block has the same

i have 0.7.4 dry-v. I will take a break for now
thanks for your help!
Christopher Dennl-Ortega Arrieta
@cdennl
Apr 23 2016 15:51
np
panigrah
@panigrah
Apr 23 2016 15:55
@cdennl i just realized - that the global setting that was suggested by AMHOL doesn't work in my case. But if I put config.messages_file into my validation block then it works.
Christopher Dennl-Ortega Arrieta
@cdennl
Apr 23 2016 15:56
messages_file or messages?
panigrah
@panigrah
Apr 23 2016 15:58
messages_file and messages shows me a different error - perhaps i have a problem with i18 setup
Piotr Solnica
@solnic
Apr 23 2016 15:59
You need to make sure i18n loads all your locale files
Christopher Dennl-Ortega Arrieta
@cdennl
Apr 23 2016 16:02
my initializer for i18n:
```
# tell the I18n library where to find your translations
I18n.load_path += Dir[Rails.root.join('config', 'locales', '**', '*.{rb,yml}')]

# set default locale to something other than :en
I18n.default_locale = :en
Pablo Herrero
@pabloh
Apr 23 2016 17:13
Sry if this was already asked, why dry-types depends on concurrent-ruby?
Hunter Madison
@hmadison
Apr 23 2016 17:15
Thread safety stuff iirc
Piotr Solnica
@solnic
Apr 23 2016 17:16
@pabloh we use concurrent::cache
Don Morrison
@elskwid
Apr 23 2016 17:31
is this the @solnic hugs chat?
Cause I have one I’d like to give him.
:heart:
Piotr Solnica
@solnic
Apr 23 2016 17:32
Heh. It's a dry-rb chat. But we can hug each other nevertheless ;)
Don Morrison
@elskwid
Apr 23 2016 17:33
I’ve been lurking around as I do and thought you could use some happy thoughts.