These are chat archives for dry-rb/chat

10th
Aug 2016
Piotr Solnica
@solnic
Aug 10 2016 01:56
@timriley still not there yet 100% but tons of improvements already done there: dry-rb/dry-component#27
Sergey Kukunin
@Kukunin
Aug 10 2016 02:01
guys. do you usually has a layer of data transformation between input request hash and hash that's passed to struct constructor. I mean, you definitely should run through input data via validator for schema, but I mean structure changes
in my entity I extracted :first_name, :middle_name and :last_name to separate struct PersonName. However I don't want to change external API format because of backward compatibility
is there better way then direct mapping like
new_attrs = {
  email: attrs[:email],
  phone: attrs[:phone],
  name: {
    first_name; attrs[:first_name]
  }
Tim Riley
@timriley
Aug 10 2016 02:10
@solnic I will look again!
meanwhile, I think I might’ve fixed a dry-v bug :dancers:
Piotr Solnica
@solnic
Aug 10 2016 02:10
@timriley pls take a look, I won’t be able to wrap it up until Friday but feedback is really needed
I’m pretty sure we can resolve all the known shortcomings with sharing deps between umbrella/sub-apps
re dry-v, that’s great - which one?
@timriley ^
Tim Riley
@timriley
Aug 10 2016 02:12
dry-rb/dry-validation#221
It was an array mutability issue
Piotr Solnica
@solnic
Aug 10 2016 02:13
ohhhh
Tim Riley
@timriley
Aug 10 2016 02:13
opts[:path] << path.last was the culprit
opts = opts.merge(path: opts[:path] + [path.last]) is the fix
Piotr Solnica
@solnic
Aug 10 2016 02:13
well, if the rest of the specs are passing, then it’s safe to release it
Tim Riley
@timriley
Aug 10 2016 02:13
in ErrorCompiler#visit_schema
mutable objects in ruby get the best of everyone, eventually :grimacing:
Piotr Solnica
@solnic
Aug 10 2016 02:14
actually, in this specific case it’s not that simple
Sergey Kukunin
@Kukunin
Aug 10 2016 02:14
one more proof for immutability (I know I'm annoying enough)
Tim Riley
@timriley
Aug 10 2016 02:16
@solnic specs are all green, I’ll make a bug fix release
Piotr Solnica
@solnic
Aug 10 2016 02:16
@timriley pls check if changelog is up-to-date
Tim Riley
@timriley
Aug 10 2016 02:16
Once I introduce a failing-then-passing test
Piotr Solnica
@solnic
Aug 10 2016 02:17
4:16am, oops…g’nite :zzz:
Tim Riley
@timriley
Aug 10 2016 02:17
gnight mate :)
Lonnie King
@lonnieking
Aug 10 2016 02:32
Hello! Is this the right place to ask about a problem that I'm having with validation messages?
Tim Riley
@timriley
Aug 10 2016 02:35
@lonnieking The best place is probably https://discuss.dry-rb.org/c/support/dry-validation, which’ll ensure you get the best answer :)
most people who frequent here will also check there
Lonnie King
@lonnieking
Aug 10 2016 02:35
Awesome! Thanks @timriley
Sergey Kukunin
@Kukunin
Aug 10 2016 06:49
is there a way to define custom coercion in dry-validator schema?
I actually filed a related issue today tho: dry-rb/dry-validation#231
Sergey Kukunin
@Kukunin
Aug 10 2016 06:55
@timriley thanks. that's exactly what I wanted
Theo Cushion
@theozaurus
Aug 10 2016 10:07

Hi, Just trying to figure out why this doesn’t work:

require 'dry/validation'

schema = Dry::Validation.Schema do
  required(:procedure_id).maybe
  required(:tasks).maybe

  rule(tasks_available: [:procedure_id, :tasks]) do |procedure_id, tasks|
    procedure_id.filled? ^ tasks.array?
  end
end

# Work fine
expect(schema.call(procedure_id: '1', tasks: nil)).to be_a_success
expect(schema.call(procedure_id: nil, tasks: ['f'])).to be_a_success
expect(schema.call(procedure_id: '1', tasks: [])).to be_a_failure

# Fails with 'tasks must be filled'
expect(schema.call(procedure_id: nil, tasks: [])).to be_a_success

Any ideas where the filled? rule is coming from for tasks?

Theo Cushion
@theozaurus
Aug 10 2016 10:32
Ah it looks like require(:tasks).maybe(:array?) resolves it. I think maybe assumes filled?. It would be cool to have a built in predicate some? (opposite of none?) so that the rule could read procedure_id.filled? ^ tasks.some?
require 'dry/validation'

schema = Dry::Validation.Schema do
  required(:procedure_id).maybe(:str?)
  required(:tasks).maybe(:array?)

  rule(tasks_available: [:procedure_id, :tasks]) do |procedure_id, tasks|
    procedure_id.filled? ^ tasks.array?
  end
end

# Work fine
expect(schema.call(procedure_id: '1', tasks: nil)).to be_a_success
expect(schema.call(procedure_id: nil, tasks: ['f'])).to be_a_success
expect(schema.call(procedure_id: '1', tasks: [])).to be_a_failure
Piotr Solnica
@solnic
Aug 10 2016 11:01
@theozaurus I plan to replace none? with nil? so that it’s less confusing
@timriley “morning” ;)
Andy Holland
@AMHOL
Aug 10 2016 11:20
Or "G'day" :p
Theo Cushion
@theozaurus
Aug 10 2016 11:24
@solnic makes sense
Piotr Solnica
@solnic
Aug 10 2016 11:25
I started work at 13:13, what could possibly go wrong today ;)
@theozaurus btw maybe and filled apply filled? under the hood, but maybe does none? | filled?
Andy Holland
@AMHOL
Aug 10 2016 11:26
lol cool :)
Piotr Solnica
@solnic
Aug 10 2016 11:47
@AMHOL just added proper validation to component’s .new
Andy Holland
@AMHOL
Aug 10 2016 11:48
Nice one :)
Theo Cushion
@theozaurus
Aug 10 2016 11:51
@solnic. Thanks, I think I assumed it was none? | !none?-> true (I guess that doesn’t make much sense) but meant that Some() or None() would result.
Piotr Solnica
@solnic
Aug 10 2016 11:52
@theozaurus yeah that’s a bit more tricky, as you can get an empty string and it’s still not nil but that’s not what you want :)
Theo Cushion
@theozaurus
Aug 10 2016 11:52
Damn those empty strings
Piotr Solnica
@solnic
Aug 10 2016 11:52
damn those html forms :)
Theo Cushion
@theozaurus
Aug 10 2016 11:57
Urghg I shudder just to think. Please don’t mention html form checkboxes.
Fran Worley
@fran-worley
Aug 10 2016 15:30

@solnic is this a bug/ not yet added enhancement of an experimental feature or am I missing the point?

  subject(:schema_with_object) do
    Dry::Validation.Schema do
      configure do
        option :form
        def data
          raise form.inspect # as a dynamic arg it returns nil
        end

        def some_predicate?
          raise form.inspect # when accessing the variable as a predicate it returns the object
        end
      end
    end
  end

Even nicer, is there a way to simply bypass dynamic args and call methods on an injected object e.g.
required(:status).filled(included_in? form.class::STATUS_CODES)

Piotr Solnica
@solnic
Aug 10 2016 15:33
@fran-worley def data; form.class::STATUS_CODES; end should work, pls report an issue with a repro script if it doesn’t
Fran Worley
@fran-worley
Aug 10 2016 15:36
Even better, got a failing test for you :)
Piotr Solnica
@solnic
Aug 10 2016 15:49
k thanks :)
Fran Worley
@fran-worley
Aug 10 2016 15:55
No worries, is it something to do with this being called before option variable has a value https://github.com/dry-rb/dry-validation/blob/master/lib/dry/validation.rb#L17 ?
Piotr Solnica
@solnic
Aug 10 2016 15:56
very likely
we gotta finalize this feature :(
move stuff to dry-logic etc
eeh so much work on so many fronts
Fran Worley
@fran-worley
Aug 10 2016 16:04
:smile: well we will get there, and when we do we will find a million other things to do and the circle will continue on...
Piotr Solnica
@solnic
Aug 10 2016 16:15
@fran-worley pretty much :)
Tim Riley
@timriley
Aug 10 2016 22:35
@solnic “morning” ;)
Piotr Solnica
@solnic
Aug 10 2016 22:36
@timriley that’s like 10 hours too late ;)
Tim Riley
@timriley
Aug 10 2016 22:36
well, it’s always morning for one of us
the sun never sets on the dry-rb empire
timriley @timriley goes to look at the dry-system changes
Jānis Miezītis
@janjiss
Aug 10 2016 22:42
This devise stuff does not go as expected
Piotr Solnica
@solnic
Aug 10 2016 22:48
@janjiss what’s up?
Jānis Miezītis
@janjiss
Aug 10 2016 22:49
I’m figuring out how to do the relations properly. They have few specs where you can do things like klass.create!(owner: owner)
The trick here is to know which key is a relation, but I think I have figured it out
Piotr Solnica
@solnic
Aug 10 2016 22:51
@janjiss we store all the info in relation name objects and association name objects, you should be able to figure it out
Jānis Miezītis
@janjiss
Aug 10 2016 22:51
I’m currently moving this stuff out of my project to original repo
Yes, I think so :)
Piotr Solnica
@solnic
Aug 10 2016 23:11
@timriley lemme know what you think, I’m still around
Tim Riley
@timriley
Aug 10 2016 23:17
@solnic cool, I’m just on a phonecall atm (ha ha! business!), but I’ll get back to looking afterwards.
Piotr Solnica
@solnic
Aug 10 2016 23:18
kkkk business time I get it