Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
Andy Holland
@AMHOL
@solnic can you PM me your email, I'll add you as an owner so you can push to rubygems
Piotr Solnica
@solnic
piotr dot solnica at gmail
Andy Holland
@AMHOL
:+1: cheers
Added
Andy Holland
@AMHOL
released with dry-container and dry-configurable files
Oops, forgot the rubocop disable
Andy Holland
@AMHOL
@solnic not sure how far you got or what code you ended up with for the container stuff, but thinking sth like this would be better:
class Container
  extend Dry::Container::Mixin

  register('rom') do
    ROM.env
  end

  register('repositories.user') do
    resolve('rom').relation(:users)
  end
end

module ContainerResolution
  def self.extended(klass)
    klass.delegate :resolve, to: Container
  end

  def use(key, **options)
    method = options.fetch(:as, key)

    define_method(method) do
      resolve(key)
    end

    memoize(*keys) if options.fetch(:memoize, false)
  end
end

class UsersController
  extend ContainerResolution

  use 'repositories.user', as: :user_repository

  def index
    user_repository.all.to_a
  end
end
Just with the use 'sth', as: :sth_els, I like the namespaces with the string keys
Piotr Solnica
@solnic
oh that’s a neat idea
I already thought that this will grow fast so I dunno how to split it up
namespacing like that sounds really simple!
Andy Holland
@AMHOL
Yeah, not sure it adds much to the code, but it's definitely easier for humans to understand :)
Piotr Solnica
@solnic
that’s really cool, I think, we’ll see how it works :)
btw I did a sweet little thing for auto-injecting with Concord + Dry::Container
it looks like that, more or less:
class Foo
  extend AutoInject(:baz, :bar)

  def call
    bar.call(baz.call)
  end
end
which basically creates a module and sets up constructor with deps injected from a known container
and returns it, so Foo is extended with it
Andy Holland
@AMHOL
Cool, constructor injection is much better
What does AutoInject look like?
Piotr Solnica
@solnic
def AutoInject(*names)
  Module.new do |mod|
    mod.class_variable_set('@@names', names)

    def self.extended(klass)
      names = class_variable_get('@@names')

      klass.class_eval do
        include Concord.new(*names)

        def self.new(*args)
          names = ancestors.detect { |a| a.is_a?(Concord) }.names
          deps = names.map.with_index { |name, i| args[i] || SB.app.container.resolve(name) }
          super(*deps)
        end
      end
    end
  end
end
messy but works
I wrote it yesterday in anger
Andy Holland
@AMHOL
lol
Piotr Solnica
@solnic
:D
Andy Holland
@AMHOL
Nice
Piotr Solnica
@solnic
it removes helluva code from class definitions
Andy Holland
@AMHOL
You have stuff registered with call: false then?
Piotr Solnica
@solnic
and you can still easily track down what the deps are
I register them with blocks
no options
works
Andy Holland
@AMHOL
Ahh OK
Piotr Solnica
@solnic
container.register(:persistence) { Persistence.new(resolve(‘rom’)) }
things like that
Andy Holland
@AMHOL
Just with:
class Foo
  extend AutoInject(:baz, :bar)

  def call
    bar.call(baz.call)
  end
end
And the default resolver, it would call on resolution
Without the call: false option
Ahh, OK, thought you were registering procs because of the example
Piotr Solnica
@solnic
no just block syntax
btw I feel like I know enough to experiment with my custom rodakase
Andy Holland
@AMHOL
Cool, I'm not sure I like the roda-action stuff anymore, but the container would be useful
Be interesting to see what you come up with :)
Piotr Solnica
@solnic
@AMHOL actually I’m more interested in collaborating on something
it’s mostly putting pieces together but I’d prefer to collaborate and work together on something
Andy Holland
@AMHOL
@solnic Ahh, OK, more than happy to do that :smile:
Piotr Solnica
@solnic
there’s at least ~5 people who are interested in a roda-based stack
I’m not betting on lotus anymore no matter how much I love Luca and his work, it’s too OO for me :)
Andy Holland
@AMHOL
I've been thinking it would be nice to get some kind of roda skeleton setup, is that what you're thinking?
I don't mind OO, but I think Lotus is too Rails-like