These are chat archives for dry-rb/chat

2nd
Jun 2016
Nikita Shilnikov
@flash-gordon
Jun 02 2016 00:03
my pleasure :)
panigrah
@panigrah
Jun 02 2016 02:23
@timriley is there a dry injection for dummies tutorial? I would like to learn about what it is conceptually and how/when to use it.
Pablo Herrero
@pabloh
Jun 02 2016 02:28
@timriley , do you need dry-container (or dry-component) in order to use dry-injection at its fullest?
@pabloh dry-auto_inject is designed to work with a container, yeah
dry-component makes it easier to populate your container with objets (see the second article in my list of links just above)
panigrah
@panigrah
Jun 02 2016 04:09
thanks @timriley . If I had to summarize within 120 chars; It is a different way to extend existing objects/classes at run-time - The alternatives to this are to subclass, extend and reopen classes.
Tim Riley
@timriley
Jun 02 2016 05:30
It’s more about making object composition easy.
via dependency injection
Piotr Solnica
@solnic
Jun 02 2016 10:05
@timriley :clap:
@timriley are you planning to work on dry-component too?
Tim Riley
@timriley
Jun 02 2016 10:07
@solnic thanks! Component is next on my list. I'll release the injection related changes and then I want to look at what else I can improve.
I also want to think about app generators next week. I'm beginning to think that dry-web et al isn't suited to providing its own generators a la rails or hanami because it's not an integrated, opinionated stack. I think we could almost embrace the idea of "skeletons" or "stacks" as the way someone might generate a new dry-web app.
Piotr Solnica
@solnic
Jun 02 2016 10:08
would be nice to improve the structure in component, I like the system-and-components idea in clojure’s component lib, we could have something similar
Tim Riley
@timriley
Jun 02 2016 10:09
You'd opt to pick a stack/skeleton and then it would provide its own appropriate generators.
Piotr Solnica
@solnic
Jun 02 2016 10:09
I hate generators :D
Tim Riley
@timriley
Jun 02 2016 10:09
I'd like to hear/learn more about that idea.
Piotr Solnica
@solnic
Jun 02 2016 10:09
understand the value but personally I really don’t like them
Tim Riley
@timriley
Jun 02 2016 10:09
Yeah. This is why I can help you by working on them ;p
Piotr Solnica
@solnic
Jun 02 2016 10:10
yeah so the idea is simple, you’ve got components and a system that is has many components
Tim Riley
@timriley
Jun 02 2016 10:10
yep, makes sense
Piotr Solnica
@solnic
Jun 02 2016 10:10
so you could have a persistence system in your app, that consists of sequel and rom components
Luca Guidi
@jodosha
Jun 02 2016 10:10
@timriley @solnic In my experience, people want to know where to put things.
Piotr Solnica
@solnic
Jun 02 2016 10:10
each component is being booted by a system
@jodosha yeah, I get that :)
Tim Riley
@timriley
Jun 02 2016 10:11
Right. So a more formal approach to what we kind of have with our "boot" stuff atm, except built around whole components?
Piotr Solnica
@solnic
Jun 02 2016 10:12
yeah, it’s about making things organized better
Tim Riley
@timriley
Jun 02 2016 10:12
I would like that
Piotr Solnica
@solnic
Jun 02 2016 10:12
system(:persistence).boot! triggers loading and booting of its components
we just miss an explicit concept of a system
then you could share systems across apps…
they would be contained
Tim Riley
@timriley
Jun 02 2016 10:13
Right! Yeah, I like this. Atm it is awkward that our "top level" in dry-web is a component like everything else. It felt like it needed to be a bit different
Piotr Solnica
@solnic
Jun 02 2016 10:13
this really boils down to managing state in an app :)
Tim Riley
@timriley
Jun 02 2016 10:13
Haha, right
Piotr Solnica
@solnic
Jun 02 2016 10:14
db connections, http clients, all this stuff
Tim Riley
@timriley
Jun 02 2016 10:14
Hmmm, so should I investigate that clojure lib, watch that talk? I feel like I need to research some more.
Piotr Solnica
@solnic
Jun 02 2016 10:14
yeah it’s worth exploring, good news is - ruby is better suited to handle this stuff :)
Tim Riley
@timriley
Jun 02 2016 10:15
(This might need to be a medium-term thing - before RDRC I'd like to see if I can just smooth some rough corners in what we already have)
Piotr Solnica
@solnic
Jun 02 2016 10:15
yep
Tim Riley
@timriley
Jun 02 2016 10:15
Since there's not that long until then.
Cool. Well, I'll write up some notes about that on Sun or Mon :)
Piotr Solnica
@solnic
Jun 02 2016 10:16
another good example of a system would be http routing
basically entire http front-end can be contained within a system
Tim Riley
@timriley
Jun 02 2016 10:17
Yeah, that feels better
Piotr Solnica
@solnic
Jun 02 2016 10:17
ie hanami router + rack + middlewares == http system
Tim Riley
@timriley
Jun 02 2016 10:17
It shouldn't be some exceptional thing
Piotr Solnica
@solnic
Jun 02 2016 10:17
you just plug it into your app, the top-level system
Tim Riley
@timriley
Jun 02 2016 10:17
And that http system would depend on the app's system?
Piotr Solnica
@solnic
Jun 02 2016 10:17
another one, view rendering, also a system
no it shouldn’t know about the app’s system
it’s plugged into it
I think, thinking out loud :)
the integration point is the app’s container, which provides the app’s API to the http front-end
that, we already have, it’s just about making this more formal with better vocabulary :)
and an explicit object representation
Tim Riley
@timriley
Jun 02 2016 10:20
Hmm, right
Yeah, I get this
(The role of the container to connect things)
Piotr Solnica
@solnic
Jun 02 2016 10:22
it’s gonna be really cool to build a tool that looks at your setup and generates a visual representation of what happens when a request comes in :D
rack middlewares => final routing end-point => application end-point => specific objects that process data => perrsistence operations => db result => app result => http response
Oskar Szrajer
@gotar
Jun 02 2016 10:24
NewRelic^2 ;]
Piotr Solnica
@solnic
Jun 02 2016 10:24
right, this would be taken to the next level
esp with monitoring capabilities
Tim Riley
@timriley
Jun 02 2016 10:25
Oh man, Michael at Icelab would love this
Piotr Solnica
@solnic
Jun 02 2016 10:25
:)
Oskar Szrajer
@gotar
Jun 02 2016 10:28
idea for product - $$$
Hannes Nevalainen
@kwando
Jun 02 2016 14:09
@timriley more customizable / less restrictive auto_registration for dry-component would be nice, read that you were going to spend some quality time with dry-component =)
Worth a watch if anyone hasn't seen it yet
Piotr Solnica
@solnic
Jun 02 2016 14:27
@kwando if you don’t like default behavior just register your objects yourself
I wouldn’t want dry-component to turn into a highly customizable object construction framework
Hannes Nevalainen
@kwando
Jun 02 2016 14:27
@solnic I already got my own registration strategies
some of them is rather app specific though
Maciej Mensfeld
@mensfeld
Jun 02 2016 14:33
@solnic will there be a strict mode for dry-validations? I mean now I can pass a field that I haven't declared and it is there
Piotr Solnica
@solnic
Jun 02 2016 14:36
yes there will be a predicate which checks that
Maciej Mensfeld
@mensfeld
Jun 02 2016 14:37
I really need that for what I do ;) (and all the other magic you guys work on :D)
Piotr Solnica
@solnic
Jun 02 2016 14:37
@kwando this is not a DI/IoC framework and it won’t be, for complex object construction strategies we could create an interface for integration with external libs that handle that
personally I’m not interested in such a thing
Hannes Nevalainen
@kwando
Jun 02 2016 14:41
well, I ditched dry-component and rolled my own instead
Piotr Solnica
@solnic
Jun 02 2016 14:42
is it OSS?
and did you try to use it in a rails app or dry-web stack or something else?
Hannes Nevalainen
@kwando
Jun 02 2016 14:43
no it is not, it will be if I ever get to extract it from this app though =)
Piotr Solnica
@solnic
Jun 02 2016 14:43
we can have a way of registering custom handlers
but this would be external, so dry-component would have its own simple one (the existing stuff) and you could configure your own
Hannes Nevalainen
@kwando
Jun 02 2016 14:44
really enjoying how omakase the dry ecosystem is =)
Piotr Solnica
@solnic
Jun 02 2016 14:44
yeah man it’s omakase and you consume it with really sharp knifes :laughing:
Hannes Nevalainen
@kwando
Jun 02 2016 14:44
:laughing:
lol
Nikita Shilnikov
@flash-gordon
Jun 02 2016 14:47
it would be great if dry-component supported namespaces. This PR seems to be abandoned dry-rb/dry-component#6 :(
this was a deal breaker for me
Piotr Solnica
@solnic
Jun 02 2016 14:51
@flash-gordon it will support it
nobody had the time to take care of this, that’s all
Chase Gilliam
@Ch4s3
Jun 02 2016 15:31
I'm hitting a place where dry-validation-rails is going to be very useful soon. Where are we in that discussion?
Oskar Szrajer
@gotar
Jun 02 2016 15:48
it's only me, who have odd feeling when every gem need another one with -rails to support it, why not to just use dry-validation ?
Chase Gilliam
@Ch4s3
Jun 02 2016 15:50
I understand the sentiment. I think the idea was to give rails users an easier on-ramp for dry-rb, but I think @solnic can explain the rationale much better
Nikita Shilnikov
@flash-gordon
Jun 02 2016 16:00
@solnic that's why I mentioned it ;) Personally I didn't do anything about it because I don't know how it should be implemented
Piotr Solnica
@solnic
Jun 02 2016 16:13
Rails needs integration. And I don't want it to be part of main code bases
Chase Gilliam
@Ch4s3
Jun 02 2016 16:14
I'm trying to build something in my application and see if I can extract a sensible integration...
I'm including a dry-validation schema class on my models and checking it before saving. It works, but I'm not sure how happy I am with it.
Jeff Dickey
@jdickey
Jun 02 2016 16:41
Hi, guys; I'm having trouble with a Types::Strict::DateTime initialisation. When I use the "raw" Gem-supplied types to define everything, all is well; when I use a self-defined module constant, I get a NoMethodError running what looks like the exact same code. Gist with short single-source-file demo code here
Initialising with DateTime.now works when using Types::Strict::DateTime.default { DateTime.now }; it does not work when attempting to use a constant defined as Types::Strict::DateTime.default { DateTime.now }
Nikita Shilnikov
@flash-gordon
Jun 02 2016 18:24
@jdickey try DateTimeOrNow = Types::Strict::DateTime.default { ::DateTime.now }
in Types module you have a clash with Types::DateTime constant
Piotr Solnica
@solnic
Jun 02 2016 19:04
@rusilko heyyy sorry for this late reply, so in a nutshell: let's start with strong-params replacement, this is basically a schema that defines which keys are required and optional and what the types should be. Once we have that, along with some railitie that sets things up for you, we can think about what to do with model validation, I think the next natural would be to move validation out from AR models and provide some smooth integration with AM (although that is, IIRC, covered by gems like reform, so maybe makes no sense to go that far). All this stuff should go to a separate gem dry-validation-rails which provides Dry::Validation::Rails namespace with all the needed APIs. /cc @Ch4s3
oh and yes, we could create a separate channel for dry-validation, it's probably the biggest gem we have with adoption growing fast...
@gotar apologies for my rough reply, I was...driving :P anyhow, re keeping rails stuff separate - this will speed up development, ie I don't use rails (I guess you know that already :)) so I don't want to deal with rails-related code when working on OSS, that's pretty much it, it adds friction to dev cycles that I really don't like, and don't have time/energy to deal with this
one minor benefit is also that it screams "look how many gems need rails-specific code just to make them usable with rails"
at least I see some value in this kind of manifestation (maybe not the right word)
Ralf Schmitz Bongiolo
@mrbongiolo
Jun 02 2016 19:36
@mensfeld I'm not sure if I understood you correctly, but for what you what you should use the Sanitizer input_processor, it will ignore any fields that are not declared in your schema.
configure do
  config.input_processor = :sanitizer
end
Tomek Rusiłko
@rusilko
Jun 02 2016 20:16
@solnic hey, no probs. Thanks for clarifing things. So, pls set up a channel and lets start hacking away on it :) cc/ @Ch4s3
Chase Gilliam
@Ch4s3
Jun 02 2016 21:20
@rusilko sounds good. @solnic Do you want dry-validation-rails to live in dry-rb or somewhere else?
Piotr Solnica
@solnic
Jun 02 2016 21:35
@Ch4s3 dry-rb org :ok_hand:
Chase Gilliam
@Ch4s3
Jun 02 2016 22:08
@solnic I thought so. If you want to fire up a repo, I can start work this weekend.
John Backus
@backus
Jun 02 2016 23:57
require 'bundler/setup'
require 'dry/validation'

Dry::Validation.JSON do
  hash? do
    required(:data).schema do
      required(:foo).value(:int?)
    end
  end
end
/Users/johnbackus/.rvm/gems/ruby-2.3.1/bundler/gems/dry-types-ce8761715332/lib/dry/types/compiler.rb:80:in `merge': no implicit conversion of Dry::Types::Safe into Hash (TypeError)
  from /Users/johnbackus/.rvm/gems/ruby-2.3.1/bundler/gems/dry-types-ce8761715332/lib/dry/types/compiler.rb:80:in `each'
  from /Users/johnbackus/.rvm/gems/ruby-2.3.1/bundler/gems/dry-types-ce8761715332/lib/dry/types/compiler.rb:80:in `reduce'
  from /Users/johnbackus/.rvm/gems/ruby-2.3.1/bundler/gems/dry-types-ce8761715332/lib/dry/types/compiler.rb:80:in `merge_with'
  from /Users/johnbackus/.rvm/gems/ruby-2.3.1/bundler/gems/dry-types-ce8761715332/lib/dry/types/compiler.rb:67:in `visit_json_hash'
  from /Users/johnbackus/.rvm/gems/ruby-2.3.1/bundler/gems/dry-types-ce8761715332/lib/dry/types/compiler.rb:28:in `visit_type'
  from /Users/johnbackus/.rvm/gems/ruby-2.3.1/bundler/gems/dry-types-ce8761715332/lib/dry/types/compiler.rb:15:in `visit'
  from /Users/johnbackus/.rvm/gems/ruby-2.3.1/bundler/gems/dry-types-ce8761715332/lib/dry/types/compiler.rb:11:in `call'
  from /Users/johnbackus/.rvm/gems/ruby-2.3.1/bundler/gems/dry-validation-fa557778ff0f/lib/dry/validation/input_processor_compiler.rb:16:in `call'
  from /Users/johnbackus/.rvm/gems/ruby-2.3.1/bundler/gems/dry-validation-fa557778ff0f/lib/dry/validation/schema.rb:125:in `input_processor'
  from /Users/johnbackus/.rvm/gems/ruby-2.3.1/bundler/gems/dry-validation-fa557778ff0f/lib/dry/validation/schema.rb:148:in `default_options'
  from /Users/johnbackus/.rvm/gems/ruby-2.3.1/bundler/gems/dry-validation-fa557778ff0f/lib/dry/validation/schema.rb:46:in `new'
  from /Users/johnbackus/.rvm/gems/ruby-2.3.1/bundler/gems/dry-validation-fa557778ff0f/lib/dry/validation.rb:37:in `Schema'
  from /Users/johnbackus/.rvm/gems/ruby-2.3.1/bundler/gems/dry-validation-fa557778ff0f/lib/dry/validation.rb:46:in `JSON'
  from test.rb:36:in `<main>'
Should I open an issue?