These are chat archives for dry-rb/chat

5th
Jul 2016
Piotr Solnica
@solnic
Jul 05 2016 07:37
@selectport pls report an issue about it and I can add it in 0.8.1 :)
Fran Worley
@fran-worley
Jul 05 2016 07:41
@solnic should we delete this example? https://github.com/dry-rb/dry-validation/blob/master/examples/rule_ast.rb a) ast is wrong, b) both of the classes referenced have been moved to dry-logic c) even when you fix a&b it still doesn't work...
Piotr Solnica
@solnic
Jul 05 2016 08:14
@fran-worley yes we should
@fran-worley btw I partially rewrote error compiler :laughing:
Fran Worley
@fran-worley
Jul 05 2016 08:24
:) nice! dry-rb/dry-validation#185 can probably go then. Still think we are going to have to rename the tokens at some point though...
Scott Eckenrode
@selectport
Jul 05 2016 08:29
@solnic I opened (dry-rb/dry-validation#204) with failing spec added …let me know if you need more. thank you.
Piotr Solnica
@solnic
Jul 05 2016 08:29
@selectport oh thanks that’s very helpful
@fran-worley yeah I will revisit this PR once I’m done
@fran-worley we actually should be able to reduce dry-logic result ast a bit…specifically :input nodes could be removed probably
that’s for 0.9.0 though, I’m refactoring error compiler mostly because I couldn’t easily fix one bug
Fran Worley
@fran-worley
Jul 05 2016 08:32
I wasn't sure how you tell the difference between the 'input' parameter and others particularly when allowing custom predicates. Also I quite like being able to have the complete predicate, particularly when using it for my non-validation based use case.
If we didn't need the input arg then changing the ast would have been 100% simpler !!
Piotr Solnica
@solnic
Jul 05 2016 08:43
yeah it would have
I’m 90% sure we won’t need it at the end of the day
Fran Worley
@fran-worley
Jul 05 2016 08:44
So I've got until 0.9.0 to find a reason !
Piotr Solnica
@solnic
Jul 05 2016 08:44
but that’s too much to change at once, so I’m gonna do it step by step in two releases
I’m introducing a couple of new abstractions in 0.8.1 as part of this refactor, it won’t be exposed as public yet but it will be there :) so ie we will have messages set which stores message objects, and we have info about which are errors and which are hints
so in 0.9.0 we could have a result object that can give you errors and hints separately if you want
Fran Worley
@fran-worley
Jul 05 2016 08:47
clever. That should fix a load of the pending specs. The second point would be awesome. I can then actively use hints without any effort !
Piotr Solnica
@solnic
Jul 05 2016 08:52
it’s a classic example of primitive obsession biting you in an OO lang
Maciej Mensfeld
@mensfeld
Jul 05 2016 09:11
Hey :) once again (sorry to bother but dont know if it is doable witg dry-val)

@solnic is there a way to somehow validate hash keys? I would like to describe something like htis:

{ 1 => rand, 2 => rand } # etc

and create sme rules with dry-validations that will ensure that my keys are integer based and that inside there are float numbers as well

Fran Worley
@fran-worley
Jul 05 2016 11:23
@solnic No worries if not and I think I know the answer but is there any update on rule groups or such like? (see your comment here)
https://github.com/apotonick/reform/pull/347#issuecomment-204923689
Piotr Solnica
@solnic
Jul 05 2016 11:27
@mensfeld pls report an issue marked as question
Fran Worley
@fran-worley
Jul 05 2016 11:28
@solnic :clap: :sparkles: Yey!!
Piotr Solnica
@solnic
Jul 05 2016 11:39
@fran-worley I won’t have time for this in the near future, but would be nice to get it done prior 1.0
I don’t have any API ideas yet
Fran Worley
@fran-worley
Jul 05 2016 11:48
@solnic Famous last words but I'm happy to try and push this forward for 0.9
I like using groups to help to order my validations and ignore DB hitting checks like uniqueness if my basic ones like filled fail. I'm therefore wondering whether we could expand on the schema do .. end api to achieve this.
# If you could name your schemas
schema(:simples) do
# ...
end

schema(:scary_complex) do
# ...
end

# we could enable rules like:
schema(:simples).success?.then schema(:scary_complex)
Piotr Solnica
@solnic
Jul 05 2016 11:52
hmm
you can achieve the same thing with high lvl rules
Fran Worley
@fran-worley
Jul 05 2016 11:52
I wondered if that was possible
The thing I wasn't sure of was if you could check more than one thing easily. Take this example:
validation :default do
  required(:email).filled
  required(:current_password).filled
end

validation :authenticate_current_password, if: :default do
  configure do
    def account_authenticated?(value)
      form.model.authenticate(value)
    end
  end
  required(:current_password, &:account_authenticated?)
end
In that example I only validate the second schema if the first passes. Would you be able to support that somehow?
Piotr Solnica
@solnic
Jul 05 2016 11:57
well, we can make schemas work like rules
which was my idea from the beginning btw
so ie schema1.and(schema2) would work
Fran Worley
@fran-worley
Jul 05 2016 11:57
That would be perfect
Piotr Solnica
@solnic
Jul 05 2016 11:57
inorite :D
Fran Worley
@fran-worley
Jul 05 2016 11:58
or schema1.then(schema2)
Piotr Solnica
@solnic
Jul 05 2016 11:58
yes, any logic operation would work
schema1 | schema2
etc
I think we should be careful with adding more stuff to the DSL
schema is already quite complex
we now have a 3-step process which is quite a lot
Fran Worley
@fran-worley
Jul 05 2016 12:00
I completely agree. surely if done properly it should impact people just needing the basic form:
each do
  schema do
    required(:prefix).filled
    required(:value).filled
  end
end
Piotr Solnica
@solnic
Jul 05 2016 12:23
huh dry-v crossed 15k downloads, that’s quite a lot given that rom-rb has only 2 x more and it was released in 2013 :laughing:
Maciej Mensfeld
@mensfeld
Jul 05 2016 12:26
@solnic better marketing :D
Piotr Solnica
@solnic
Jul 05 2016 12:31
yeah and probably because more people would like to use a new validation lib as opposed to ditching their favorite orms ;)
Andy Holland
@AMHOL
Jul 05 2016 12:31
:p
Fran Worley
@fran-worley
Jul 05 2016 13:01
@solnic it's a pretty easy sell, and as it works happily with rails, along side ActiveModel::Validations people can try it out, gradually migrate etc. ROM probably takes a little more guts to dive into ...
Ralf Schmitz Bongiolo
@mrbongiolo
Jul 05 2016 13:03
Should I change my current rules required(:something).filled(:str?) to the new required(:something, :str).filled?
Piotr Solnica
@solnic
Jul 05 2016 13:18
@fran-worley probably yes ;)
@mrbongiolo these two are not equivalent
type specs are only used for coercion
you still need predicates to ensure that coercion succeeded
Piotr Solnica
@solnic
Jul 05 2016 13:44
@fran-worley lemme know if you’d like to experiment with dry-logic result ast reduction (removing :input nodes)…I’m gonna take a break from dry-rb after 0.8.1 release of dry-v to focus on rom-rb so I suspect I won’t be doing much dry-rb work in July
Ralf Schmitz Bongiolo
@mrbongiolo
Jul 05 2016 13:47
@solnic Ok, thanks for the explanation. So in the earlier versions the predicate :str? was doing type checking and coercion?
Piotr Solnica
@solnic
Jul 05 2016 13:48
@mrbongiolo coercion was inferred from type-checking predicates
I mean it still works like that
but we’re gonna remove it in 1.0.0
Ralf Schmitz Bongiolo
@mrbongiolo
Jul 05 2016 13:49
Ok!
Piotr Solnica
@solnic
Jul 05 2016 13:50
we just need to figure out a way to make it smooth in common cases with zero duplication in dsl
so ie infer predicates from type specs for common cases
I also want to experiment with a different approach where you use type-check schema separately from domain schema
the schemas as rules idea would help here
this is 1.0.0 material :)
I start to think we should be able to hit 1.0.0 for validation and types later this year, becoming more confident about this (slowly)
Fran Worley
@fran-worley
Jul 05 2016 14:03
@solnic I know exactly how to remove it and it will simplify things (we won't need to curry the rule for the result). I just worry that pulling it out leaves a hole in dry-logic. I get that dry-validation doesn't need it because it does input it's own way but what about other uses of dry-logic.
Piotr Solnica
@solnic
Jul 05 2016 14:06
@fran-worley oh we do want to curry args
and because we curry, we don’t need to add :input nodes anymore
Fran Worley
@fran-worley
Jul 05 2016 14:06
into the predicate or into the rule ?
Piotr Solnica
@solnic
Jul 05 2016 14:06
I mean that’s a theory for now
Fran Worley
@fran-worley
Jul 05 2016 14:09
sorry take this dry-validation ast:
[
  [:error, [:name, [:input, [:name, [:result, [nil, [:val, p(:key?, :name)]]]]]]],
  [:error, [:gender, [:input, [:gender, [:result, [nil, [:val, p(:key?, :gender)]]]]]]],
  [:error, [:age, [:input, [:age, [:result, [18, [:val, p(:gt?, 18)]]]]]]],
  [:error, [:email, [:input, [:email, [:result, ["", [:val, p(:filled?)]]]]]]],
  [:error, [:address, [:input, [:address, [:result, ["", [:val, p(:filled?)]]]]]]]
 ]
Piotr Solnica
@solnic
Jul 05 2016 14:10
[:error, [:name, [:result, [nil, [:val, p(:key?, :name)]]]]]
:result has info about the input for a rule, and its predicate has info about actual args
Fran Worley
@fran-worley
Jul 05 2016 14:11
Ahhh that makes more sense. You had me panicking that you wanted rid of the input in the predicate ast.[:predicate, [:key?, [[:name, nil], [:input, nil]]
Indeed I was thinking that the extra input could probably go when I made the original change. I'll take a look :)
Fran Worley
@fran-worley
Jul 05 2016 14:25
Is this enough? dry-rb/dry-logic@a12f874
Or do I need to also remove the key ? @solnic
Piotr Solnica
@solnic
Jul 05 2016 14:30
yeah rule name must go, first element in a node defines its type
Fran Worley
@fran-worley
Jul 05 2016 14:38
@solnic What about each rules? If you take the name away we don't seem to keep it anywhere (or doesn't that matter)?
[:input, [
  :nums, [
    :result, [
      [1, '3', 3],
        [:each, [
          [:el, [0, [:result, [1, [:val, [:predicate, [:str?, [[:input, 1]]]]]]]]],
                [:el, [2, [:result, [3, [:val, [:predicate, [:str?, [[:input, 3]]]]]]]]]
              ]]
            ]
          ]
]]

# would become:

[ :result, [
  [1, '3', 3],
  [:each, [
    [:el, [0, [:result, [1, [:val, [:predicate, [:str?, [[:input, 1]]]]]]]]],
    [:el, [2, [:result, [3, [:val, [:predicate, [:str?, [[:input, 3]]]]]]]]]
   ]]
]]
Piotr Solnica
@solnic
Jul 05 2016 14:39
we may want to tweak :result to include the name
[:result, [:nums, […]]]
so first arg is name, then the input value, then the elements array
Fran Worley
@fran-worley
Jul 05 2016 14:41
Yeah that's better:
[ :result, [[:nums, [1, '3', 3]], 
  [:each, [
    [:el, [0, [:result, [1, [:val, [:predicate, [:str?, [[:input, 1]]]]]]]]],
    [:el, [2, [:result, [3, [:val, [:predicate, [:str?, [[:input, 3]]]]]]]]]
   ]]
]]
Fran Worley
@fran-worley
Jul 05 2016 15:02
@solnic if you've got time can you check the updated specs? dry-rb/dry-logic@7dd5053
Joshua Wilcox
@joshuaswilcox
Jul 05 2016 17:33
after updating dry-transaction to 0.7 i get this in my code
undefined method `Right'
is there some upgrade steps that were not mentioned
Piotr Solnica
@solnic
Jul 05 2016 18:02
@joshuaswilcox I’m guessing you need to include Dry::Monads::Either::Mixin
or just do Dry::Monads.Right(…) explicitly
Joshua Wilcox
@joshuaswilcox
Jul 05 2016 18:21
hm, ok, i'll give that a try, i thought I saw it being included by the the transaction.rb already in the gem though
Joshua Wilcox
@joshuaswilcox
Jul 05 2016 19:53
yeah using Dry::Monads.Right() works
Nikita Shilnikov
@flash-gordon
Jul 05 2016 20:38
@joshuaswilcox we changed kleisli gem with dry-monads, the main difference is that we don't monkey patch Kernel so now you have to include Either::Mixin manually to add Right/Left methods
Joshua Wilcox
@joshuaswilcox
Jul 05 2016 20:38
Ah, ok, yeah I saw it was replaced, makes sense about the monkey patching as well, thanks
Piotr Solnica
@solnic
Jul 05 2016 21:39
uhm, I enabled caching for I18n thinking that maybe it’ll speed up ActiveModel::Validations and it basically made it 2 x slower O_o
Nikita Shilnikov
@flash-gordon
Jul 05 2016 21:42
lol
Piotr Solnica
@solnic
Jul 05 2016 21:45
it went from ~4x slower than dry-v to ~7.8x slower
and when I disabled caching in dry-v, it was ~2.5x slower
Joe Van Dyk
@joevandyk
Jul 05 2016 23:27
Is there a way in dry-types to automatically build fake objects for testing easily?
Say I have a User object with an array of addresses and I don't want to write factory methods
I just want to do User.build and it'll make a User object with all the fields populated