These are chat archives for dry-rb/chat

22nd
Apr 2016
panigrah
@panigrah
Apr 22 2016 00:48

is there a change to the rules api in master? I have this bit failing;

    rule(destiny: [:red, :blue]) do |red, blue|
        red.filled? | blue.filled?
    end

with:
schema/value.rb:82:inrule': undefined method with' for true:TrueClass (NoMethodError)

nilobject
@nil0bject
Apr 22 2016 06:12

trying to use coercion. Why doesn’t

Types::Form::Bool['False']
=> "False"

return false?

:(
[17] pry(main)> LocalSearch::Types::Form::Bool['1']
=> true
[18] pry(main)> LocalSearch::Types::Form::Bool['0']
=> false
[19] pry(main)> LocalSearch::Types::Form::Bool['false']
=> false
[20] pry(main)> LocalSearch::Types::Form::Bool['False']
=> "False"
Fran Worley
@fran-worley
Apr 22 2016 06:32
@panigrah can you send the rest of your schema?
Tim Cooper
@coop
Apr 22 2016 06:41
@nil0bject these are the supported form boolean coercions - https://github.com/dry-rb/dry-types/blob/master/lib/dry/types/coercions/form.rb#L8-L10
panigrah
@panigrah
Apr 22 2016 11:12
whats the preferred location to store dry-v error file for custom messages in a rails app?
dan-klasson
@dan-klasson
Apr 22 2016 11:13
@panigrah probably config/locales/en/errors.yml
dan-klasson
@dan-klasson
Apr 22 2016 11:22
@nil0bject why would it? this is not python ;)
Christopher Dennl-Ortega Arrieta
@cdennl
Apr 22 2016 11:23
@panigrah name of the file doesn't matter as long as this file contains an 'errors' key
below the language
panigrah
@panigrah
Apr 22 2016 11:40
@cdennl i was looking for the correct location to place this file in. @dan-klasson - dry-v is searching for custom error messages (for the unique?) test. Am adding it to config/locales.
Fran Worley
@fran-worley
Apr 22 2016 11:41
You have to specify where your file is in the config
panigrah
@panigrah
Apr 22 2016 11:44
thanks @fran-worley was looking to see where in the dir structure I should have this. will follow dan's suggestion. Is there a way to override the global location? i don't want to add this to every configure block in every schema.
Fran Worley
@fran-worley
Apr 22 2016 11:45
@panigrah I guess you could create a base schema class with your error config and inherit from that. I am pretty sure there is no global method currently
Tim Riley
@timriley
Apr 22 2016 11:46
I bet “no global method” would be by design :)
Fran Worley
@fran-worley
Apr 22 2016 11:47
@timriley I'm sure but it would be lovely not to be able to declare it once... I include the message config line in every schema (and I have quite a number...)
And they reference the exact same files.
Tim Riley
@timriley
Apr 22 2016 11:47
Couldn’t you do what you suggest above and create a base schema class?
panigrah
@panigrah
Apr 22 2016 11:48
thank you @fran-worley
Fran Worley
@fran-worley
Apr 22 2016 11:48
Yeah I'm sure provided you can extend the base config block
Plus I use Reform which defines its own schema class...
panigrah
@panigrah
Apr 22 2016 11:53
@fran-worley i am using this with reform, which just passes the block over to dry-v - would i need to monkey patch it to override the base schema class?
Tim Riley
@timriley
Apr 22 2016 11:54
@fran-worley yep, looking over the code, I think it would be no problem to have a base schema class with a configure do; config.messages = “…”; end and then other schemas inheriting from that base and providing their own configure blocks too.
Fran Worley
@fran-worley
Apr 22 2016 11:54
@timriley good to know
@panigrah not sure about Reform 2.2 but on 2.1 you would. It's one of my dislikes.
Andy Holland
@AMHOL
Apr 22 2016 12:33
@panigrah @fran-worley it's just using dry-configurable so global configuration would be:
Dry::Validation::Schema.configure do |config|
  config.messages_file = '/path/to/my/errors.yml'
end
dan-klasson
@dan-klasson
Apr 22 2016 12:34
@AMHOL yeah, that looks perfect. @panigrah stick that in config/initializers/trailblazer.rb
Fran Worley
@fran-worley
Apr 22 2016 12:39
@AMHOL that is really useful. That should definitely go in the docs.
Andy Holland
@AMHOL
Apr 22 2016 12:40
:+1:
Simon Schmid
@sled
Apr 22 2016 12:40
Andy Holland
@AMHOL
Apr 22 2016 12:40
@sled that's for configuring a single schema
Simon Schmid
@sled
Apr 22 2016 12:40
ah you can configure it globally
:D
that's cool for an initializer
panigrah
@panigrah
Apr 22 2016 14:51

I have a custom validation "unique?" for a rule called "name" - my error.yaml file is below

en:
  errors:
     unique?: "Value must be unique"

I continue to get

`Dry::Validation::MissingMessageError: message for unique?`
the error file is setup per AMHOL's posting above
Piotr Solnica
@solnic
Apr 22 2016 14:53
What if you put it under name key?
Andy Holland
@AMHOL
Apr 22 2016 14:55
@panigrah I take it you restarted/reloaded after adding the initializer ?
Fran Worley
@fran-worley
Apr 22 2016 14:56
This message was deleted
Fran Worley
@fran-worley
Apr 22 2016 15:02

@panigrah if you're writing an error for a rule you need your messages to look something like this:

en:
  errors:
    #regular error messages

  rules:
    name:
      unique?: "the name name must be unique"

Look at the end of the example on http://dry-rb.org/gems/dry-validation/error-messages/

panigrah
@panigrah
Apr 22 2016 15:29
@fran-worley and @solnic - no luck. Will try to debug in the morning - am using master
Piotr Solnica
@solnic
Apr 22 2016 15:34
We've got specs which covers this type of usecases but not for i18n. Maybe sth there is happening. I'll investigate when I'm back home from holidays (tomorrow)
dan-klasson
@dan-klasson
Apr 22 2016 15:37
@solnic ha. i knew you couldn't stay away ;)
Pablo Herrero
@pabloh
Apr 22 2016 15:39
Hey anyone got any thoughts regarding: dry-rb/dry-constructor#5 ?
Piotr Solnica
@solnic
Apr 22 2016 15:40
@dan-klasson i did until yesterday
dan-klasson
@dan-klasson
Apr 22 2016 15:43
@solnic yeah that's a lot better than i anticipated :)
how was the vacation? all nice any sunny beaches?
Piotr Solnica
@solnic
Apr 22 2016 15:45
Got sun burned. So yes. Sunny
Simon Schmid
@sled
Apr 22 2016 15:46
they should build UV light into computer screens to prepare for holidays ;)
Piotr Solnica
@solnic
Apr 22 2016 15:46
Who would have thought that sun at 3000 meters mountain can harm you when you don't use any sunblocker
Simon Schmid
@sled
Apr 22 2016 15:47
never been skiing? :)
Piotr Solnica
@solnic
Apr 22 2016 15:52
I've been skiing since I was 3yo. I'm just a moron every now and then and forget about basic stuff :)
dan-klasson
@dan-klasson
Apr 22 2016 16:00
oh man growing up in Sweeeden. My class mates in public school could not believe that I actually went skiing in Austria given how brown my skin was. Not knowing anything about Austria, they thought it was more plausible that I was lying. Hilarious. Man I'm still pissed at my dad for letting me grow up with those rednecks.
Christopher Dennl-Ortega Arrieta
@cdennl
Apr 22 2016 16:06
@panigrah if you're using rails and i18n, don't specify the path but use config.message = :i18n
this is my custom file:
```
en:
  errors:
    is_conversion_correct?:                 'is incorrectly converted from P to $'
dan-klasson
@dan-klasson
Apr 22 2016 16:23
@jodosha just made a comment
Luca Guidi
@jodosha
Apr 22 2016 16:24
@dan-klasson ty!