These are chat archives for dry-rb/chat

16th
Apr 2016
Tim Cooper
@coop
Apr 16 2016 02:18
Thanks for the invite @AMHOL :)
Benjamin Klotz
@tak1n
Apr 16 2016 07:21
@AMHOL thx for the invite :)
@solnic little bit late but enjoy ur holidays, u really deserve it
Andy Holland
@AMHOL
Apr 16 2016 09:35
NP, thanks for all the help :smile:
Benjamin Klotz
@tak1n
Apr 16 2016 09:35
didn't help that much yet, but I hope thats going to change soon :P
Tim Riley
@timriley
Apr 16 2016 10:27
Thanks for the pings, @tak1n. I realise we’re all going to have to pick up our game with solnic on leave :)
Fran Worley
@fran-worley
Apr 16 2016 10:48
@timriley do you add tests for Deprecated methods?
Tim Riley
@timriley
Apr 16 2016 10:48
To test for the deprecation warning, you mean, @fran-worley?
Fran Worley
@fran-worley
Apr 16 2016 10:48
Yeah
Benjamin Klotz
@tak1n
Apr 16 2016 10:50
@timriley np :)
Tim Riley
@timriley
Apr 16 2016 10:50
@fran-worley if it’s relatively straightforward, I guess it would be nice. But if it looks like a lot of work, I think we’d be fine without it. We’d probably only keep these deprecations in for a single major release cycle anyway.
Fran Worley
@fran-worley
Apr 16 2016 10:52
I've not bothered as it doesn't appear to have been done in dry-v either...
Tim Riley
@timriley
Apr 16 2016 10:52
Fine by me :+1:
Fran Worley
@fran-worley
Apr 16 2016 11:11
@timriley we might have to bump the dry logic version to access the predicates in dry-v...
Tim Riley
@timriley
Apr 16 2016 11:11
@fran-worley good point! Want me to merge and release?
Fran Worley
@fran-worley
Apr 16 2016 11:12
That would be fab
Tim Riley
@timriley
Apr 16 2016 11:12
I’ll merge now. I worry that I don’t have RubyGems permissions...
I don’t have RubyGems permissons, sadly. I’ll ask solnic directly if he can share them with me.
Tim Riley
@timriley
Apr 16 2016 11:21
Done. We’ll have to wait for official releases. But you could probably add a line to dry-v’s Gemfile for the time being to make it load dry-logic from github master, if you wanted to press on in the short term, @fran-worley :)
Thanks for taking this on!
Fran Worley
@fran-worley
Apr 16 2016 11:22
Already done , working on it now.
Fran Worley
@fran-worley
Apr 16 2016 11:28
@timriley any ideas why this seems to imply a call to inclusion? https://github.com/dry-rb/dry-validation/blob/master/spec/integration/schema/using_types_spec.rb#L14
Tim Riley
@timriley
Apr 16 2016 11:29
Enum types check to see whether the passed value is one of those specified. It might be using inclusion from dry-logic?
Fran Worley
@fran-worley
Apr 16 2016 11:29
I was thinking that...
Tim Riley
@timriley
Apr 16 2016 11:31
Heh, well there you go. These 3 libs do make good use of each other! Though it does mean more work for you :grimacing:
Fran Worley
@fran-worley
Apr 16 2016 11:37
Done. Unfortunately dry-v only works with the new branch on dry-types and dry-logic from master
and that new branch on dry-types only works with dry-logic on master
Tim Riley
@timriley
Apr 16 2016 11:51
Np. We'll get it all sorted :)
Simon Schmid
@sled
Apr 16 2016 12:43
This message was deleted
Simon Schmid
@sled
Apr 16 2016 12:54
@fran-worley may I ask how you use Dry::Schema, I read somewhere you try to replace Reform with it?
Fran Worley
@fran-worley
Apr 16 2016 12:58
@sled I've not actually replaced it yet. Just thinking aloud really. I need to be able to to use the new version of dy-v but can't because Reform doesn't currently support it. Given the differences between the two libraries, largely to do with the ordering of processes I wondered whether I would be better off using dry-v and implementing my own persistance logic.
Simon Schmid
@sled
Apr 16 2016 13:00
same here :/
Fran Worley
@fran-worley
Apr 16 2016 13:01
That and the fact that I don't actually use the rest of trailblazer...
Simon Schmid
@sled
Apr 16 2016 13:02
yes it has a lot of strings attached to it but the concept is nice
are you using rails?
Fran Worley
@fran-worley
Apr 16 2016 13:04
Yup
Simon Schmid
@sled
Apr 16 2016 13:04
did you manage to get the form builder working with Dry::Schema?
Fran Worley
@fran-worley
Apr 16 2016 13:05
TBH Not started it yet, its sitting in my 'One day when I have a minute' pile...
Simon Schmid
@sled
Apr 16 2016 13:06
hehe it's a chicken and egg problem, if the schema fails, I can't instantiate my type, so I don't have an object to give to the form builder to render the form with the errors
Fran Worley
@fran-worley
Apr 16 2016 13:08
I'm looking at whether it would be better to render the form from the data rather than via an object. Obviously that requires re-writing the form builder...
Simon Schmid
@sled
Apr 16 2016 13:10
I'm thinking about using the AST of the schema to generate a PORO just with attr_readers
dan-klasson
@dan-klasson
Apr 16 2016 13:11
@fran-worley are you using the 2-2 branch of reform?
Fran Worley
@fran-worley
Apr 16 2016 13:12
Not yet, I'm looking at my options before I make a move.
dan-klasson
@dan-klasson
Apr 16 2016 13:13
supposedly that works with dry-v
Fran Worley
@fran-worley
Apr 16 2016 13:13
I know but if you read the thread there are some distinct differences in the libraries that means 2.2. will work but is not making the best use of the Dry-V library
Simon Schmid
@sled
Apr 16 2016 13:15
anybody got an idea why key(:email).required.filled works fine but required(:email).filled throws NoMethodError: undefined method 'filled' for [:val, [:predicate, [:required, [:email]]]]:Dry::Validation::Schema::Rule
Fran Worley
@fran-worley
Apr 16 2016 13:19
Are you using dry-v from master?
Simon Schmid
@sled
Apr 16 2016 13:19
0.7.4
Fran Worley
@fran-worley
Apr 16 2016 13:20
that new dsl hasn't been released yet so you'd need to upgrade dry-v to use it
Simon Schmid
@sled
Apr 16 2016 13:20
stupid me, was looking at the examples in the master branch ;)
Simon Schmid
@sled
Apr 16 2016 14:19
would it be possible to create a basic schema inferred from a type? :)
dan-klasson
@dan-klasson
Apr 16 2016 14:54
@fran-worley totally. i am so not using TRB in a production environment yet
Simon Schmid
@sled
Apr 16 2016 14:58
@dan-klasson are you using dry-* in production?
dan-klasson
@dan-klasson
Apr 16 2016 14:59
no
but intend to in the near future when TRB is ready
have to refactor this massive rails app. was thinking i'll start with cells first
Simon Schmid
@sled
Apr 16 2016 15:00
I also have to refactor a quite messy rails app, but decided to start from scratch
dry seems like a good choice, alternative is to roll my own
Christopher Dennl-Ortega Arrieta
@cdennl
Apr 16 2016 15:04
dry-v 0.7 works with reform 2.2 @fran-worley
Fran Worley
@fran-worley
Apr 16 2016 15:49
@cdennl yeah I know thanks :)
Soumya Ray
@soumyaray
Apr 16 2016 16:22
Hi everyone, is http://dry-rb.org/gems/dry-validation/error-messages/ still up-to-date? because calling Dry::Validation::Messages.load says its a private method.
Soumya Ray
@soumyaray
Apr 16 2016 16:35

I'm seeing people creating custom errors and calling messages on their schemas but not sure how thats working. Here's the code I'm playing with:

FileSchema = Dry::Validation.Schema do
  key(:filename).required(:no_path?)

  key(:document).required(:str?)

  configure do
    config.messages_file = 'custom_errors.yml'

    def no_path?(value)
      !(value =~ %r{/})
    end
  end
end

msgs = FileSchema.call(
  filename: 'path/file.txt',
  document: '---'
).messages

that last messages call creates a Dry::Validation::MissingMessageError: message for no_path? was not found, even though I can see my custom error message in the definition of FileSchema

Christopher Dennl-Ortega Arrieta
@cdennl
Apr 16 2016 16:36
how does custom_errors.yml look like?
@soumyaray
Soumya Ray
@soumyaray
Apr 16 2016 16:38
@cdennl: oops -- you made me check, and sure enough i forgot to put an errors: key in it :( it works now! :) many thanks
Christopher Dennl-Ortega Arrieta
@cdennl
Apr 16 2016 16:39
one point for my crystal ball :D you're welcome
Soumya Ray
@soumyaray
Apr 16 2016 16:41
last question before bed (far east over here): is there any way to contribute to the documentation like http://dry-rb.org/gems/dry-validation/error-messages/ and other help pages for dry-rb? they seem out-of-date or incomplete at places.
Christopher Dennl-Ortega Arrieta
@cdennl
Apr 16 2016 16:42
depends, the docs are ok if you use 0.7
and afaik they're working on 0.8
Fran Worley
@fran-worley
Apr 16 2016 16:44
@soumyaray there is a GitHub repo for the docs. Feel free to make a pull request. https://github.com/dry-rb/dry-rb.org
Soumya Ray
@soumyaray
Apr 16 2016 16:47
@fran-worley: thanks!

@cdennl: in the link above, it suggests that after defining custom error messages in a yaml file, to lookup error mesages using:

messages = Dry::Validation::Messages.load('/path/to/our/errors.yml')

and looking up the resulting messages structure. but that Messages.load method is now private. I might be misreading/misinterpreting it of course.

Christopher Dennl-Ortega Arrieta
@cdennl
Apr 16 2016 16:52
no it doesnt suggest it
it only demonstrates what happens internally
@soumyaray