These are chat archives for dry-rb/chat

22nd
Aug 2016
Nikita Shilnikov
@flash-gordon
Aug 22 2016 08:54
@solnic ping :)
Julien Blanchard
@julienXX
Aug 22 2016 09:07
Hello is it possible to have optional attributes (not optional values) in a Dry::Types::Struct? I can't find a way to do it.
Piotr Solnica
@solnic
Aug 22 2016 09:09
@julienXX constructor(:schema) should help, but we’ll be refining this in dry-struct so things will be more obvious there
@flash-gordon hey sorry, been super busy with logic/validation. re cache, dunno, the way we use it is rather minimalistic and that’d be a good start, just fetch_or_store at class/instance level :)
Julien Blanchard
@julienXX
Aug 22 2016 09:12
@solnic thanks! So something like https://gitter.im/dry-rb/chat?at=565af079c3d575114e6c9402 could work?
Nikita Shilnikov
@flash-gordon
Aug 22 2016 09:13
@solnic no worries, I'll open a pr to dry-t and we'll discuss it there
Piotr Solnica
@solnic
Aug 22 2016 09:13
:+1:
@julienXX wdym? that was a schema from dry-v :)
Julien Blanchard
@julienXX
Aug 22 2016 09:15
This message was deleted
Michał Pietrus
@blelump
Aug 22 2016 09:16
Hi @solnic , if you'll get some time, could you look at dry-rb/dry-system-rails#1 ?
Piotr Solnica
@solnic
Aug 22 2016 09:19
@blelump just left a comment in the pr
Piotr Solnica
@solnic
Aug 22 2016 10:25
@fran-worley hey, so, after lots of experimentation it turned out that merging results into rules turned out to be too expensive in terms of perf :crying_cat_face:
I made a mistake thinking that we were already currying all rules for results, this wasn’t the case - we were currying predicates (which sometimes are rules too, but not always). so by changing #call to return curried rules all the time, I added a lot of overhead :(
Fran Worley
@fran-worley
Aug 22 2016 10:28
@solnic do we need to curry all rules though? I'll be back in the office in an hour do you mind if I have a quick look before you revert?
Piotr Solnica
@solnic
Aug 22 2016 10:31
@fran-worley it’s hard to determine tbf
we need to curry so that predicates are filled with all args :)
the thing is - allocating a rule is MUCH more expensive than a simple result object
I’m quite positive we gotta stick to results now haha
I just need to come up with a simpler result api
prev was too messy
I tried to experiment with an approach where first we curry a rule, then call it to get a result, and assign that result to the curried rule (w/o creating a new instance), but that didn’t work, I’ll try again though
Fran Worley
@fran-worley
Aug 22 2016 10:35
Ok I bow to your better judgement. I'll take a look when I get in. I love the simplification but of course not if it is that expensive performance wise.
Piotr Solnica
@solnic
Aug 22 2016 10:38
I’ll give it another shot
Fran Worley
@fran-worley
Aug 22 2016 10:45
🌟 home in 30 so will dive in and see if I can come up with anything incite full!
Piotr Solnica
@solnic
Aug 22 2016 11:10
@fran-worley one thing we gotta try is to make rule/predicate quack the same wrt applying them and what they return
rule#call returns an applied rule, predicate#call returns true/false, and that’s what makes it hard to work with
Fran Worley
@fran-worley
Aug 22 2016 11:14
We could make predicate.call actually return the predicate. The only reason I made it return true/false was to maintain the functionality of procs
Piotr Solnica
@solnic
Aug 22 2016 11:27
@fran-worley maybe that’s a better direction dry-rb/dry-logic@066aade
and yeah, I think Predicate#call should return an applied predicate, which has the same interface as Rule wrt ast stuff, this way we would be able to get rid of this nasty respond_to?(:success) check
anyhow, I ran out of time, so I’ll pick this up again tomorrow. feel free to continue this experiment if you want :)
fwiw, this will probably work faster as it should create the same amount of objects as with prev result stuff
Fran Worley
@fran-worley
Aug 22 2016 11:32
Yeah I like where you are going with it. I'll take a look after lunch.
Piotr Solnica
@solnic
Aug 22 2016 11:36
truth is we need this common interface because there should not be any difference betwee a rule and a predicate wrt applying them
rules are basically predicates with logic operators
Fran Worley
@fran-worley
Aug 22 2016 11:38
I actually started going down this route last time, though I went the other way and added Predicate::Result.
Piotr Solnica
@solnic
Aug 22 2016 11:40
yeah I remember, this is sort-of similar, it’s just that we represent a result via applied predicate/rule
Fran Worley
@fran-worley
Aug 22 2016 11:45
Yeah this is much better :smile:
Aleksandar Radunović
@aradunovic
Aug 22 2016 13:43
Hi guys, I have a question about dry-system. It looks to me as if exceptions are swallowed during auto-registration. Namely, if something goes wrong during auto-registration (config.auto_register(‘lib’)) of some dependencies, they are just skipped (nothing is registered under those keys) and no exception is thrown (app boots normally).
Is this by intention or am I missing something?
Piotr Solnica
@solnic
Aug 22 2016 13:58
@aradunovic seems like a bug, could you report an issue with a sample reproduction?
Aleksandar Radunović
@aradunovic
Aug 22 2016 14:05
@solnic Sure. But before I make a fuss :smile: , I’m gonna tripple check this. Just to make sure I didn’t screw something up.
Piotr Solnica
@solnic
Aug 22 2016 14:16
@aradunovic no worries, if something confused you then it’s also a good reason to report that or at least discuss :)
Piotr Solnica
@solnic
Aug 22 2016 14:47
@aradunovic in the future version I’ll be adding detailed logging so you’ll be able to see booting process step-by-step in your terminal
Michał Pietrus
@blelump
Aug 22 2016 14:54
@solnic , I failed with adding a spec regarding that rake issue. With dummy app it always passes , even though I've downgraded to 4.2 which is my current setup. Further investigation is needed
Piotr Solnica
@solnic
Aug 22 2016 14:56
@blelump OK I’ll take a look
Aleksandar Radunović
@aradunovic
Aug 22 2016 15:00

@solnic ok, the auto-register issue is 100% my mess. I created another project with same setup and everything works fine.
On the other hand, there is something else. Here’s the code:

Container.finalize(:db) do |container|
  _unexisting_made_up_method
  use :logger
  require "sequel"

  Sequel.database_timezone = :utc
  Sequel.application_timezone = :local
  db = Sequel.connect(ENV["DB_URL"])
  db.loggers << logger

  container.register(:db, db)
end

Container.finalize!

this will not throw an error

Piotr Solnica
@solnic
Aug 22 2016 15:06
@aradunovic that’s a bug, pls report
Aleksandar Radunović
@aradunovic
Aug 22 2016 15:11
@solnic I first noticed this while I was following the docs and used uses instead of use for auto-booting the dependency. At the end, the Sequel broke with
NoMethodError: undefined method ‘info' for nil:NilClass, since :logger was nil.
Piotr Solnica
@solnic
Aug 22 2016 15:14
gotcha, gotta fix that
Aleksandar Radunović
@aradunovic
Aug 22 2016 15:17
Ok, I’ll create an issue with a more detailed example.
Michał Pietrus
@blelump
Aug 22 2016 17:02
@solnic , I've got a while to investigate it further. I am not sure, but I think the problem occurs because in my setup run_tasks_blocks fires before instance and hence the namespace method has been overridden by the Rake::DSL one. Actually, I'd propose to move these namespace and friends™ methods into singleton class, because it seems it causes the underlying issue, whereas it looks like it's just a convenient way to write Railties without class methods :smile: .
but anyway, I didn't recreate this with dummy app
Robin Bühler
@openscript
Aug 22 2016 21:14

Hi all! :-)
I've just started using dry-types and I'm amazed by it! I wonder, how I get the absolute value from a type instance.

For example I've the following type:

class Propeller < Dry::Types::Value
  constructor_type :schema
  attribute :diameter, Types::Maybe::Coercible::Int
  attribute :angle, Types::Coercible::Int
end

And I create an new instance with:

Propeller.new({diameter: 2}).to_h
{:diameter=>Some(2), :angle=>nil}

How do I get a hash with {:diameter=>2, ..} instead?

Some(2).to_s results in the string Some(2) is that wanted?
Nikita Shilnikov
@flash-gordon
Aug 22 2016 21:29
@openscript there is no predefined method to build such hash, to_h just gives you object's ivars as is
if you want to extract the a from Maybe you can call .value, not .to_s
so Some(2).value will return 2
you can check the docs for details http://dry-rb.org/gems/dry-monads/
you also may want to use Optional, not Maybe, depending on your requirements
that is Types::Optional::Coercible::Int
this way values won't be wrapped with a monad
Robin Bühler
@openscript
Aug 22 2016 21:38
@flash-gordon Thank you for your response. Optional suits my requirements very well. :-)
New page on the website is up.
Piotr Solnica
@solnic
Aug 22 2016 22:48
:tada: