These are chat archives for dry-rb/chat

Feb 2018
Drew Olson
Feb 06 2018 00:40
generic dry-monad question -- is there a way to "extract" the raw value of a monad? something like orElse for java's optional? or is the monadic type a point of no return?
Nikita Shilnikov
Feb 06 2018 00:42
it’s value_or
Spencer Goh
Feb 06 2018 05:48

I have a use case where I have a DB adapter (which has itself an injected DB client ). I'd like to do something like this.

class MyCustomObjectXRepo
  include Import['persistence.adapter', collection_name: 'object_x']
  def pending
    adapter.find(status: 'pending', created_by: current_user)

I'd like to be able to inject a new instance of the adapter but initialized for the specific collection_name. Is there a clean way to do with with dry-autoinject / dry-containers?
At the moment, I'm just injecting in a builder and constructing the adapter lazily instead, but doesn't feel clean to me

class MyCustomObjectXRepo
  include Import['persistence.adapter_builder']
  def adapter
    @adapter ||= adapter_builder.create(collection_name: 'object_x')
Spencer Goh
Feb 06 2018 05:55
also given that I'm using mongod, i thought it's overkill in this instance to use dry-rom-mongo, but is this is a false economy I wonder? So things I'm having to do are setup auto-registration of all my repos (which dry-rom does already), and then provide rich enough helper methods to talk to the underlying store... am I heading down a rabbit hole...
Piotr Solnica
Feb 06 2018 11:44
@dymaxionuk there's no dry-rom-mongo or dry-rom :) you probably meant rom-mongo which as mongodb adapter for rom, but it's not production ready yet
re injecting deps with options, it's not supported because the import module simply passes objects resolved from a container. This means you need to have them registered in the expected state
you could register adapters for specific collections and inject them explicitly via something like include Import['persistence.adapter.object_x']