These are chat archives for dry-rb/chat

22nd
Jan 2016
40 minutes of work, after all, wasn’t so bad :D
Tim Riley
@timriley
Jan 22 2016 10:53
neat!
Piotr Solnica
@solnic
Jan 22 2016 10:53
@fran-worley @mrbongiolo @AMHOL ^^ :D
Luca Guidi
@jodosha
Jan 22 2016 10:53
:clap: :sparkles:
Tim Riley
@timriley
Jan 22 2016 10:53
I wonder if when would read better than on
Piotr Solnica
@solnic
Jan 22 2016 10:53
that’s what Andy suggested
I agree
lemme rename
Fran Worley
@fran-worley
Jan 22 2016 10:54
@solnic :clap: Is it in a good enough state for me to try it out? Once you've renamed.
Piotr Solnica
@solnic
Jan 22 2016 10:54
@fran-worley gimme a sec, I gotta add option support too
and make it work with error messages
Fran Worley
@fran-worley
Jan 22 2016 10:55
No worries, just give me a shout. I'm around all day!
Piotr Solnica
@solnic
Jan 22 2016 10:55
thanks :)
I’m wondering how to provide name for the rule
we could infer default name and simply use the predicate for the right side
but often you will want a custom name
to provide a more detailed msg
Fran Worley
@fran-worley
Jan 22 2016 10:57
Could you pass in an option if you wanted a custom message?
Piotr Solnica
@solnic
Jan 22 2016 10:57
so I dunno, maybe sth like key(:login).required.when(:true?, :require_email_on_login) { .. }
Fran Worley
@fran-worley
Jan 22 2016 10:57
key(login: :my_message).required.on(:true?) do
  value(:email).filled?
end
Piotr Solnica
@solnic
Jan 22 2016 10:58
that won’t work
it’s too early to pass it there
Fran Worley
@fran-worley
Jan 22 2016 10:58
yeah and would stick it on login and not email
Piotr Solnica
@solnic
Jan 22 2016 10:58
yep
Fran Worley
@fran-worley
Jan 22 2016 10:59
key(:login).required.on(:true?) { key(email: :require_when_login, &:filled? }
Piotr Solnica
@solnic
Jan 22 2016 11:01
notice that the block uses value syntax
Fran Worley
@fran-worley
Jan 22 2016 11:01
Yeah I wondered about that.
Piotr Solnica
@solnic
Jan 22 2016 11:01
there’s a difference, value will apply any predicate to the value
keybuilds a rule for a key and expects the key to exist
that’s something to learn and remember
we could hide this but I think explicitness here is valuable
ie we could raise if somebody tries to use key(:foo) more than once
this kind of friendly behavior will be added later on, defo prior 1.0
remember that dry-v makes a distinction between rules for keys and rules for values under keys
and key(:foo, &:filled?) is basically Predicates[:key?].curry(:foo) & Predicates[:filled?]
Fran Worley
@fran-worley
Jan 22 2016 11:05
So to extend the validation for a key you have already declared use value. Also your suggestion looks good to me
Piotr Solnica
@solnic
Jan 22 2016 11:06
yes
Fran Worley
@fran-worley
Jan 22 2016 11:06
so I dunno, maybe sth like key(:login).required.when(:true?, :require_email_on_login) { .. }
Piotr Solnica
@solnic
Jan 22 2016 11:06
when you pass a block to key it builds a value-rule-builder and passes it to the block as an arg
and value syntax does the same
so basically key(:foo) { |value| value.oh_hai? } is the same as key(:foo) { value(:foo).oh_hai? }
Piotr Solnica
@solnic
Jan 22 2016 11:51
well, seems like macros are ready
gonna wait for travis and merge in if green
Fran Worley
@fran-worley
Jan 22 2016 11:51
Ok cool. I'll have a play this afternoon if it passes
Piotr Solnica
@solnic
Jan 22 2016 11:55
and it’s in master!! :D :dancers: :tada:
Fran Worley
@fran-worley
Jan 22 2016 11:55
@solnic :clap: I'll have a play and update my wiki guide
Piotr Solnica
@solnic
Jan 22 2016 11:56
@fran-worley btw I made the syntax more general for options, so you just pass in predicate names or predicate names with args
so ie key(:age).required(:int?, gt?: 18)
Fran Worley
@fran-worley
Jan 22 2016 11:57
@solnic Nice!
Piotr Solnica
@solnic
Jan 22 2016 11:58
oh, forgot to do the same with maybe…one sec
Piotr Solnica
@solnic
Jan 22 2016 12:08
ok so now key(:name).maybe(min_size?: 18) works too
Fran Worley
@fran-worley
Jan 22 2016 12:10
@solnic Fab :hatched_chick:
Piotr Solnica
@solnic
Jan 22 2016 12:10
lemme know how it works for you, or doesn’t :joy:
we should update wiki too, probably
Fran Worley
@fran-worley
Jan 22 2016 12:11
I'll have a look a the wiki later if you like.
Might do a dedicated guide on Macros
Piotr Solnica
@solnic
Jan 22 2016 12:11
that would be awesome yeah
Fran Worley
@fran-worley
Jan 22 2016 12:12
and rewrite my AMV one to use macros
Piotr Solnica
@solnic
Jan 22 2016 12:12
this time it’ll fit in these rows huh? :D
Fran Worley
@fran-worley
Jan 22 2016 12:12
That's the plan!
Piotr Solnica
@solnic
Jan 22 2016 12:12
w00t w00t
Fran Worley
@fran-worley
Jan 22 2016 12:56
@solnic What did you do with confirmation in the end?
can you call key(:password).confirmation instead of confirmation(:password)
Piotr Solnica
@solnic
Jan 22 2016 12:56
Not yet
Fran Worley
@fran-worley
Jan 22 2016 12:57
Ok good to know :)
Piotr Solnica
@solnic
Jan 22 2016 12:57
I could add that easily though
It would be more consistent like that actualyy
Fran Worley
@fran-worley
Jan 22 2016 13:00

I want to do

key(:password).maybe(min_size?: 6, :confirmation)

or

key(:password).maybe(min_size?: 6).when(:filled?) do
  value(:password_confirmation).confirmation
end
Luca Guidi
@jodosha
Jan 22 2016 13:11
Folks, how would you express this rule with dry-v: "Password (and confirmation) is only required if invited is false"?
Fran Worley
@fran-worley
Jan 22 2016 13:12
@jodosha @solnic correct but I think:
key(:invited).required(type: :bool?).when(value(:invited).false?) do
  key(:password).required 
  key(:password_confirmation).required
end
you might even be able to do key(:password, :password_confirmation).required Not sure...
Luca Guidi
@jodosha
Jan 22 2016 13:16
@fran-worley :smile: thank you
Fran Worley
@fran-worley
Jan 22 2016 13:16
@jodosha you'll need master for that to work, and it might need a little tweaking as its using the new Macro DSL
@jodosha actually this might be better
key(:password).maybe
key(:password_confirmation).maybe
key(:invited).required(type: :bool?).when(value(:invited).false?) do
  value(:password).filled?
  value(:password_confirmation).filled?
end
Piotr Solnica
@solnic
Jan 22 2016 13:19
Hold on. It is not quite like that.
Piotr Solnica
@solnic
Jan 22 2016 13:57
I gotta work a bit more on confirmation macro
@fran-worley @jodosha ^^ so please hold on a bit
Luca Guidi
@jodosha
Jan 22 2016 13:57
@solnic No pressure
Piotr Solnica
@solnic
Jan 22 2016 13:58
Class.new(Dry::Validation::Schema) do
  key(:password).maybe(min_size?: 6).confirmation

  key(:invite).maybe(:bool?).when(:false?) do
    value(:password).filled? & value(:password_confirmation).filled?
  end
end
this will work soon ^
or maybe this would be better:
Class.new(Dry::Validation::Schema) do
  key(:password).maybe(min_size?: 6)

  key(:invite).maybe(:bool?).when(:false?) do
    value(:password).confirmation
  end
end
Fran Worley
@fran-worley
Jan 22 2016 14:01
or potentially radical option Kill it entirely...
key(:password).maybe(min_size?: 6)
key(:password_confirmation).maybe
key(:invite).maybe(:bool?).when(:false?) do
  value(:password_confirmation).eql?(value(:password))
end
Luca Guidi
@jodosha
Jan 22 2016 14:01
@solnic Shouldn't the last be rule, instead of key?
Piotr Solnica
@solnic
Jan 22 2016 14:02
@fran-worley yeah…you just keep challenging me, aren’t you? :D
Fran Worley
@fran-worley
Jan 22 2016 14:03
@solnic Sorry... I have this habit of trying to run before I can walk. Just tell me to be quiet and the challenges will stop! :wink:
Piotr Solnica
@solnic
Jan 22 2016 14:03
it’s fine, no worries
Andy Holland
@AMHOL
Jan 22 2016 14:03
Would it not be better to just pass the value to when?
Could also allow for regex and stuff
Piotr Solnica
@solnic
Jan 22 2016 14:04
@AMHOL this is an abstract DSL, actual values are not passed to the block, it’s just an AST builder
Andy Holland
@AMHOL
Jan 22 2016 14:18
Ahh yeah lol
I'm gonna be quiet now
:laughing:
Ralf Schmitz Bongiolo
@mrbongiolo
Jan 22 2016 14:20
WOW
you're unstoppable!!
Fran Worley
@fran-worley
Jan 22 2016 14:40
@solnic Shouldn't the following include the filled? error message on password_confirmation or am I missing something?
schema = Class.new(Dry::Validation::Schema) do 
  key(:password).maybe(min_size?: 6)
  key(:password_confirmation).maybe
  key(:invite).maybe(:bool?).when(:false?) do 
    value(:password).filled? & value(:password_confirmation).filled? 
  end 
end

schema.new.call(invite: false, password: nil, password_confirmation: nil)
 => #<Dry::Validation::Schema::Result params={:invite=>false, :password=>nil, :password_confirmation=>nil} messages={:password=>[[{:value=>:password}, "password size cannot be less than 6"], nil]}>
Kris Leech
@krisleech
Jan 22 2016 14:49
Has anyone got any code which uses Dry::Container where the values are validated? Something like: https://gist.github.com/krisleech/e9e9127526b54bf58e4c
Hannes Nevalainen
@kwando
Jan 22 2016 14:56
@krisleech I would replace the reports array with an object with an internal array instead of exposing it like that
Kris Leech
@krisleech
Jan 22 2016 14:57
@kwando Thanks, so Configuration['reports'].register(...)?
Yep, much nicer.
I'm thinking it might be nice to have something like ValidatedArray.new(schema) so any items added to the collection are validated first with the given schema before being added.
Andy Holland
@AMHOL
Jan 22 2016 15:01
@krisleech you can do something like:
ReportsContainer = Dry::Container::Namespace.new('reports') do
  register('...') {}
end
module Oxygen
  class Configuration
    extend Dry::Container::Mixin
    import(ReportsContainer)
  end
end
# or
module Oxygen
  class Configuration
    extend Dry::Container::Mixin

    namespace('reports') do
      register('...') {}
    end
  end
end
Kris Leech
@krisleech
Jan 22 2016 15:03
@AMHOL ohh... nice, I'd didn't see this in the README, I need to dig deeper.
Andy Holland
@AMHOL
Jan 22 2016 15:03
There's also https://github.com/dryrb/dry-container#using-a-custom-registryresolver which could be useful for pre-registration checks and stuff
Kris Leech
@krisleech
Jan 22 2016 15:04
It's all in the README, so many dry-* repos :)
Andy Holland
@AMHOL
Jan 22 2016 15:04
:laughing:
Piotr Solnica
@solnic
Jan 22 2016 15:11
@fran-worley it’s not working yet...
still working on it
Fran Worley
@fran-worley
Jan 22 2016 15:11
Ah sorry. Got a bit overexcited :)
Piotr Solnica
@solnic
Jan 22 2016 15:11
there are a couple of missing pieces for grouprules, and confirmation is a group rule
it’s cool haha
Fran Worley
@fran-worley
Jan 22 2016 15:11
I think I may be forced to slow down anyway as the new macro thing doesn't seem to work at all via reform...
Piotr Solnica
@solnic
Jan 22 2016 15:12
btw a group rule is a rule that depends on values from multiple other rules, so its predicate will receive values from results of applying other rules
@fran-worley huh what? that is not expected, it doesn’t do anything else except building up standard rules
so the schema object itself remains the same
just like if you used the longer form
unless reform is doing something funny like decorating schema class or something I dunno
Fran Worley
@fran-worley
Jan 22 2016 15:13
Thats what I thought when I looked at the source, but I can call key(:name).required in the rails console via full schema without issue. via reform I get undefined method required on array
or words to that effect. I didn't dig too much into it though...
Piotr Solnica
@solnic
Jan 22 2016 15:15
@fran-worley seems like you need bundle update, maybe you’ve got old rev
I know why it’s happening, it was partially finished work from yesterday
make sure you’ve got latest stuff from master
Fran Worley
@fran-worley
Jan 22 2016 15:16
Yeah I checked that the commit refs are on the latest and it works in rails console using pure dry-v. Only breaks when using via validation groups in reform.
Piotr Solnica
@solnic
Jan 22 2016 15:16
this is very weird
maybe @mrbongiolo or @apotonick could help out
Fran Worley
@fran-worley
Jan 22 2016 15:17
I'll do some more digging later. As it works in pure dry-v it's either something to do with Reform or my use of it in reform!!
Either way, not really a dry-v issue
Piotr Solnica
@solnic
Jan 22 2016 15:18
sounds like it
Ralf Schmitz Bongiolo
@mrbongiolo
Jan 22 2016 15:22
does it make a difference if it's Dry::Validation::Schema::Form instead of just Schema?
https://github.com/apotonick/reform/blob/v2.1.0/lib/reform/form/dry.rb#L43 as the validation group in reform uses dry-v schema form
Piotr Solnica
@solnic
Jan 22 2016 15:25
@mrbongiolo it shouldn’t, it uses the same DSL
but it applies coercions prior applying rules
Ralf Schmitz Bongiolo
@mrbongiolo
Jan 22 2016 15:27
well, whenever the dry-v macros are "stable" I can check to make they work on reform validation
Piotr Solnica
@solnic
Jan 22 2016 15:28
@mrbongiolo sure, working on it
expect a release early next week
Ralf Schmitz Bongiolo
@mrbongiolo
Jan 22 2016 15:30
take your time, don't forget to eat :P
Fran Worley
@fran-worley
Jan 22 2016 15:31
and sleep!
:zzz:
Piotr Solnica
@solnic
Jan 22 2016 15:31
I never sleep, I wait
also, I’m hungry, thanks for the reminder :D
Andy Holland
@AMHOL
Jan 22 2016 15:38
:joy:
Do you ever get it when you need a pee but you're in the zone so sit there shaking your leg for half an hour?
Piotr Solnica
@solnic
Jan 22 2016 15:39
for half an hour? no
Andy Holland
@AMHOL
Jan 22 2016 15:39
Also the time you write the best code lol
Piotr Solnica
@solnic
Jan 22 2016 15:39
for 2 hours, yes
Andy Holland
@AMHOL
Jan 22 2016 15:39
haha
Piotr Solnica
@solnic
Jan 22 2016 15:39
same with being hungry
Andy Holland
@AMHOL
Jan 22 2016 15:39
I can't hold it for that long
Piotr Solnica
@solnic
Jan 22 2016 15:40
haha ;) yeah, priorities man
Fran Worley
@fran-worley
Jan 22 2016 15:40
Yeah but I can go for days without eating. Peeing however, not so much!
Piotr Solnica
@solnic
Jan 22 2016 15:40
it’s an interesting process, this whole ‘in the zone’ thing
so hard to get in, so hard to get out
Andy Holland
@AMHOL
Jan 22 2016 15:40
I haven't been there in a few months
It's weird with eating, sometimes I can go 2 days, sometimes I can't go 2 minutes
Fran Worley
@fran-worley
Jan 22 2016 15:41
I don't think I have since I moved into a flat with other human beings...
Andy Holland
@AMHOL
Jan 22 2016 15:41
lol
People are the worst :laughing:
Fran Worley
@fran-worley
Jan 22 2016 15:41
Particularly as they don't code. Like to get home at 6 and watch the telly till bad at 11pm
Piotr Solnica
@solnic
Jan 22 2016 15:41
such distraction
Fran Worley
@fran-worley
Jan 22 2016 15:41
Indeed!
Piotr Solnica
@solnic
Jan 22 2016 15:42
unless they are on gitter, then it’s fine :joy:
Andy Holland
@AMHOL
Jan 22 2016 15:42
:p
Fran Worley
@fran-worley
Jan 22 2016 15:43
Yeah. And I probably can't blame the people... Got a free roaming house rabbit and she is almost as distracting!
Andy Holland
@AMHOL
Jan 22 2016 15:43
I grew up in a 2 bed house with my mum and 3 brothers, so I used to be able to manage getting in the zone with a lot going on, but dunno why I haven't recently
Fran Worley
@fran-worley
Jan 22 2016 15:44
Hmm maybe your current work isn't inspiring/ challenging enough?
Piotr Solnica
@solnic
Jan 22 2016 15:44
few years ago the only way for me to code was to sit in a room, at a desk, with a comfy chair and a headset so I can’t hear people around me (or be alone at home)
it changed drastically
now I can code wherever, whenever
at an airport, in a coffeeshop, in a park, or at home, while kids are jumping on me at the same time
Fran Worley
@fran-worley
Jan 22 2016 15:46
So you evolved into a superior code being? Any advice on how you got to this magical place?
Piotr Solnica
@solnic
Jan 22 2016 15:46
lol :) it’s just that I got used to some things :)
like it doesn’t bother me that much when there are people talking near me anymore, I can still focus
the only exception is when I’m solving some really complex problems
Fran Worley
@fran-worley
Jan 22 2016 15:47
Like training police dogs ?
Piotr Solnica
@solnic
Jan 22 2016 15:47
but it’s not like that happens all the time, right?
going freelance was a huge change for me, because I started working in various places :)
I stopped going to the office etc
Fran Worley
@fran-worley
Jan 22 2016 15:48
Yeah thats my problem, I work 100% remotely at home.
and I'm not a superior code being.
Piotr Solnica
@solnic
Jan 22 2016 15:49
me too. altough I moved out with my home office to a different appartment where I don’t live, just work there
Andy Holland
@AMHOL
Jan 22 2016 15:49
#livinitlarge
Fran Worley
@fran-worley
Jan 22 2016 15:49
Ah maybe that's the ticket!
Andy Holland
@AMHOL
Jan 22 2016 15:50
Think you're right about work not inspiring me anymore TBH
Piotr Solnica
@solnic
Jan 22 2016 15:50
I was 100% successful at working from home until my second son was born and the older one was tall enough to open my office room doors lol
Andy Holland
@AMHOL
Jan 22 2016 15:50
lol
Get a lock :)
Piotr Solnica
@solnic
Jan 22 2016 15:51
that would only make him furious
Andy Holland
@AMHOL
Jan 22 2016 15:51
haha
Piotr Solnica
@solnic
Jan 22 2016 15:51
2-3 yo boys are not that patient
Andy Holland
@AMHOL
Jan 22 2016 15:52
Yep, me neither, that's why I don't plan on having to put up with any 2-3 YO kids :p
Piotr Solnica
@solnic
Jan 22 2016 15:52
haha
Andy Holland
@AMHOL
Jan 22 2016 15:53
I need :coffee:
Piotr Solnica
@solnic
Jan 22 2016 15:53
me too
and food
I’ll be back later today
:wave:
Fran Worley
@fran-worley
Jan 22 2016 15:53
Bye guys :wave:
Piotr Solnica
@solnic
Jan 22 2016 20:19
I’ve got good news and bad news
Fran Worley
@fran-worley
Jan 22 2016 20:19
go on...
Piotr Solnica
@solnic
Jan 22 2016 20:19
I made this work:
Class.new(Dry::Validation::Schema) do
  key(:left).maybe(:int?)
  key(:right).maybe(:int?)

  key(:compare).maybe(:bool?).when(:true?) do
    value(:left).gt?(value(:right))
  end
end
Fran Worley
@fran-worley
Jan 22 2016 20:20
Wow....
and the bad...
Piotr Solnica
@solnic
Jan 22 2016 20:20
the api will change
rule(:foo) syntax can go away, and the whole concept of group rules can go away
essentially, I’m gonna remove a lot of code
I guess it’s good news, too, after all :D
Fran Worley
@fran-worley
Jan 22 2016 20:21
so thats actually good right
Piotr Solnica
@solnic
Jan 22 2016 20:21
yeah…it’ll simplify things a lot...
Fran Worley
@fran-worley
Jan 22 2016 20:22
haha! you had me worried for a bit. I love the new API. You have saved yourself alot of time in not having to answer my questions about when to use rule vs key vs value etc.
Piotr Solnica
@solnic
Jan 22 2016 20:22
key/value will stay
these are crucial concepts
Fran Worley
@fran-worley
Jan 22 2016 20:22
I get key and value but I really struggled with rule...
Piotr Solnica
@solnic
Jan 22 2016 20:22
now I see that rule was basically me-not-understanding-things
Fran Worley
@fran-worley
Jan 22 2016 20:23
or no one else understanding you...
Piotr Solnica
@solnic
Jan 22 2016 20:23
this macro stuff helped me understand some stuff better :)
such stuff
:|
Fran Worley
@fran-worley
Jan 22 2016 20:24
haha well I'm glad I could contribute a bit anyway. Roughly how close are we to it being fairly stable?
Piotr Solnica
@solnic
Jan 22 2016 20:24
I need a couple of hours, but it’s Friday evening so...
I hope to wrap this up on Monday and release it
this will be a substantial improvement
Fran Worley
@fran-worley
Jan 22 2016 20:25
Oh of course. Please don't feel like I'm pressuring you. I was going to work on the wiki over the weekend but I'll wait
:)
Piotr Solnica
@solnic
Jan 22 2016 20:25
no worries
thanks for feedback, it was super helpful
Fran Worley
@fran-worley
Jan 22 2016 20:26
I should have some time next week to work on the docs.
Piotr Solnica
@solnic
Jan 22 2016 20:26
I wouldn’t even consider doing this if you didn’t asked about it :)
awesome collaboration :dancers:
Fran Worley
@fran-worley
Jan 22 2016 20:26
You're welcome its been fun. Haha well I hope more people than just me like it!!
Piotr Solnica
@solnic
Jan 22 2016 20:27
I think it’s awesome, it feels very natural
the only thing is to understand key/value difference and what these methods do
everything else will feel very natural and hopefully intutive
I mean, it’s pretty clear what value(:foo).eql?(value(:bar)) does, I think
Fran Worley
@fran-worley
Jan 22 2016 20:28
You got that working too? Amazing!
Piotr Solnica
@solnic
Jan 22 2016 20:28
confirmation macro will be a piece of cake with this :)
I did, that’s what I’m talking about all the time :D
but it’s a HUGE improvement, lots of code must be now removed or simplified
Fran Worley
@fran-worley
Jan 22 2016 20:29
It makes me wonder whether we even need a confirmation macro at all
Piotr Solnica
@solnic
Jan 22 2016 20:30
right, it’d be pure sugar
sugar on top of sugar
maybe not a very healthy diet ;)
Fran Worley
@fran-worley
Jan 22 2016 20:30
If there is a guide on how to apply the concepts.. The only people who would use it are AMV people and I can put the equiavlent in the guide
Piotr Solnica
@solnic
Jan 22 2016 20:30
right
Fran Worley
@fran-worley
Jan 22 2016 20:30
even less code :)
Fran Worley
@fran-worley
Jan 22 2016 20:46
I guess it's more chainable validations than high level rules now...
Piotr Solnica
@solnic
Jan 22 2016 20:47
not really, not sure how to call them, but it is a separate concept
they are applied on top of results
ugh, to the results
Ralf Schmitz Bongiolo
@mrbongiolo
Jan 22 2016 20:57
valueis only used inside a key block?
Piotr Solnica
@solnic
Jan 22 2016 20:57
yes
it’s not appending anything to rules by itself
@mrbongiolo I’m making lots of changes...
Ralf Schmitz Bongiolo
@mrbongiolo
Jan 22 2016 20:58
yeah I saw, just asking, I like the new API you presented
it's easier to understand than the rule + groups that you had together
Piotr Solnica
@solnic
Jan 22 2016 20:58
definitely
Tim Riley
@timriley
Jan 22 2016 22:29
I think rule and group going away is a positive outcome.