These are chat archives for dry-rb/chat

26th
Feb 2018
Jonah
@jonahx
Feb 26 2018 00:15

@timriley, if I test by running an app.rb from the project root (ie, the dir containing system and domain), which looks like this:

require_relative 'system/container'

p Application.keys
puts Application.config.root.realpath

I get the error:

require_component': could not resolve require file for bot_dialogue (Dry::System::FileNotFoundError)

bot_dialogue.rb is the alphabetically first file in the domain directory, so this is some progress. It looks like this:

require 'import'

class BotDialogue
#stuff
end

It errors before it gets to the line puts Application.config.root.realpath in app.rb so I can’t answer your other question.

Tim Riley
@timriley
Feb 26 2018 00:22
@jonahx what is the directory that contains your “domain” dir?
Jonah
@jonahx
Feb 26 2018 00:22
@timriley the root of the project
Tim Riley
@timriley
Feb 26 2018 00:22
I think you should probably make that the value you pass to load_paths!
Your project seems to be structured differently to how most of us have used dry-system so this might be why you’re experiencing some hiccups
Jonah
@jonahx
Feb 26 2018 00:24
@timriley I’ll try that now. but for clarity it looks like this:
root
  application.rb
  domain
    bot_dialogue.rb
    bot_reply.rb
Tim Riley
@timriley
Feb 26 2018 00:26
@jonahx If you could push a skeleton of this structure up to a GH repo I’d also be happy to try sort it out for you too (if you’re still stuck after trying a few more things)
Jonah
@jonahx
Feb 26 2018 00:28
Cool, thanks. Let me make sure I understand this conceptually… Is config.root supposed to be the project root, or something else? And what is load_paths! supposed to specify?
Tim Riley
@timriley
Feb 26 2018 00:30
yes, the project root. and load_paths! is just a way of putting things on ruby’s $LOAD_PATH, relative to the project root
Jonah
@jonahx
Feb 26 2018 00:51
@timriley thanks, i was able to get it working based on that and putsing $LOAD_PATH until it worked
Tim Riley
@timriley
Feb 26 2018 00:52
@jonahx great!
what was your final working config?
Jonah
@jonahx
Feb 26 2018 01:32
@timriley like this:
require 'dry/system/container'

class Application < Dry::System::Container
  configure do |config|
    config.root = Pathname(File.dirname(__FILE__)).parent
    config.auto_register = ['domain', 'lib', 'use_cases']
  end

  load_paths!('domain', 'lib', 'use_cases')
end

Application.finalize!
Jonah
@jonahx
Feb 26 2018 01:41
new question: It looks like when I resolve auto-registered classes with #[] that new is automatically invoked on them. But I want the class itself to be returned, not the class called with new...
Jonah
@jonahx
Feb 26 2018 01:48

to ground that question a bit, consider the example from the docs:

Application.register('utils.logger', Logger.new($stdout))

Let’s say that logger had been auto-registered. How would you specify the $stdout when creating it? Or some object may need to configure it with a different output, at runtime. So I want the Logger class itself, so I can call Logger.new(<whatever i want>) myself.

Tim Riley
@timriley
Feb 26 2018 01:50
I can’t be around to help anymore, may I suggest you post to discourse.dry-rb.org?
Jonah
@jonahx
Feb 26 2018 01:52
sure, thanks @timriley
Lairan
@alex-lairan
Feb 26 2018 11:01

Hi ! :)

I try to use around in Dry-Transaction but I have troubles :s

This is my code:

class Containers::Transaction
  extend ::Dry::Container::Mixin

  register(:transaction) do |input, &block|
    puts "Before"
    ActiveRecord::Base.transaction do
      next block.(Failure(input))
    end
    puts "After"
  end
end
class User::Invitation::Send
  include Dry::Transaction(container: Containers::Transaction)

  around :transaction
  tee :model!
  step :persist!
  tee :mailer!
  step :email!

  .
  .
  .
end

And this give me

NoMethodError: undefined method `Failure' for Containers::Transaction:Class Did you mean? fail from /home/necros/.rvm/gems/ruby-2.3.6/gems/dry-configurable-0.7.0/lib/dry/configurable.rb:177:in `method_missing'

This happen with Success too.

Thanks for your help !

Oskar Szrajer
@gotar
Feb 26 2018 11:08
Failure is a part of monads you need to include them to call it directly
or call it using whole class namespace
Gustavo Caso
@GustavoCaso
Feb 26 2018 11:11
There is a handy module inside dry-transaction that might be helpful
It includes Monads::Result::Mixin and Dry::Matcher for the method call
Lairan
@alex-lairan
Feb 26 2018 11:22
Thanks ! It works :D