Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
Tim Mertens
@tmertens
rule(some_rule: [:type]) do |type|
  type.included_in?(VALID_TYPES).then(
    required(:other_field).schema(SomeFeature.enabled? ? SchemaOne : SchemaTwo)
  )
end
except this will evaluate the feature flag when building the AST, not when evaluating the rule for a given set of inputs. For example, in testing I want to be able to test w/ the flag enabled and disabled, without having to reload constants due to load-time feature flag evaluation
Piotr Solnica
@solnic
@tmertens I believe this is not supported, maybe try with a validate block instead
Tim Mertens
@tmertens
@solnic yes, i did manage to get it working with a validate block but this fails when the schema is used by other schemas due to dry-rb/dry-validation#361
Dermot Haughey
@hderms
this seems like a use case Dry should support
the bug is a year old, is it going to be fixed or is it not recognized as a bug?
Piotr Solnica
@solnic
dry-v is being reworked at the moment
Pablo Crivella
@pablocrivella
Hi peeps, wanted to share this with you, https://github.com/InspireNL/jsonapi-types, it’s a gem i’m using as a dependency for other 2 gems (one for a jsonapi barebones client, and another with a bit more functionality on top of that). I decided to use mainly dry-rb gems, so i would really appreaciate feedback if you can find the time to take a look :), thanks for your work on all these amazing gems btw.
This gem i just shared is pretty much an implementation of the main http://jsonapi.org types, using dry-types gem
Gustavo Caso
@GustavoCaso
:clap: :clap:
Gustavo Caso
@GustavoCaso
I shame not to be there :cry:
Piotr Solnica
@solnic
I know right
😍
Gustavo Caso
@GustavoCaso
Yeah, we will have to settle with the videos of the conferences
this is a whole talk about "ducks and monads" which mentions dry-types
Gustavo Caso
@GustavoCaso
He has a well blogpost talking about monads and transaction
Igor S. Morozov
@Morozzzko
Yeah it didn’t turn out as I planned, but still

It’s good that people are actually asking about dry-rb gems and they want to introduce monads and dry-types in their code. People are wondering how to persuade their teams.

I’m glad to see people who are interested in that

Actually, quite a lot of folks wanted to see some real-life open-source projects which use those examples.

I’m thinking it would be great to put a list of open-source projects using each of the gems on the main page

Jaromír Červenka
@Cervajz
:+1:
Paweł Świątkowski
@katafrakt
Hello! I'm facing a weird problem with dry-monads (1.0.1) - it seems it does not load properly.
irb(main):001:0> require 'dry-monads'
=> true
irb(main):002:0> Dry::Monads::Result
NameError: uninitialized constant Dry::Monads::Result
    from (irb):2
    from /Users/pawel/.rbenv/versions/2.4.1/bin/irb:11:in `<main>'
irb(main):003:0> Dry::Monads::VERSION
NameError: uninitialized constant Dry::Monads::VERSION
    from (irb):3
    from /Users/pawel/.rbenv/versions/2.4.1/bin/irb:11:in `<main>'
irb(main):004:0> Dry::Monads.constants
=> []
Igor S. Morozov
@Morozzzko
You have to require each monad explicitly now. If you don’t want to do that, you can just require 'dry/monads/all'
Paweł Świątkowski
@katafrakt
oh, right, thanks
then the docs are a little outdated, I guess
Igor S. Morozov
@Morozzzko
Yes, seems so. Could you file an issue or a PR, please?
Paweł Świątkowski
@katafrakt
Sure. Thanks for your help!
Chris Richards
@cmrichards
Are people using result objects at the level of domain objects/methods? At the moment, i'm only using them for my outer layer objects, services, etc.
Igor S. Morozov
@Morozzzko
Yup
Nikita Shilnikov
@flash-gordon
@katafrakt @Morozzzko I fixed imports :sweat_smile:
Igor S. Morozov
@Morozzzko
That’s great! Thanks
Cedric Brancourt
@Electron-libre
Hi, I'am looking for examples of building dry-validation dynamic schema.
As solnic wrote that it was possilbe to build dry predicates and pass them to the schema builder , but I can't find any examples.
Thanks for your help
Cedric Brancourt
@Electron-libre
I tried somthing like this :
r = Dry::Logic::Rule::Predicate.new(Dry::Logic::Predicates[:key?]).curry(:foo)
 sc = Dry::Validation.Schema(rules: [r])
sc.call({}).errors
....
*** FrozenError Exception: can't modify frozen Array
Jonah
@jonahx
anyone know of a dry (or other) lib that provides lens capability for hashes? i was looking at Transproc Hash functions but I don’t see anything that would allow lens capability (ie, the “update” version of dig)
Jonah
@jonahx
Jonah
@jonahx

this gem allows you to make use of the dependency inversion principle, which would normally be ignored in idiomatic Ruby libraries in favour of hard-coded dependencies and/or wide interfaces.

what are wide interfaces?

Tim Riley
@timriley
Classes with too many methods
Jonah
@jonahx
why does injecting deps manually cause that?
i see the connection to hard-coded deps, but not the connection to wide interfaces?
Jonah
@jonahx

New question:
Would it be fair to say that this:

Import = Dry::AutoInject(MyContainer)

class CreateUser
  include Import["users_repository"]

  def call(user_attrs)
    users_repository.create(user_attrs)
  end
end

is syntactic sugar for this:

require 'users_repo'

class CreateUser

  attr_reader :users_repo

  def initialize(users_repo: UsersRepo.new)
    @users_repo = users_repo
  end

  def call(user_attrs)
    users_repo.create(user_attrs)
  end
end

Are there benefits beside the removal of boilerplate?

Tim Riley
@timriley
Yeah. In your second example it has to be UsersRepo.new
Jonah
@jonahx
right. fixed.
Tim Riley
@timriley
And if you did that, it would have to instantiate all of its dependencies in turn (presuming it has any)
Jonah
@jonahx
correct. they’d all have to be there in ctor
Tim Riley
@timriley
Auto-inject allows this to be lazy