rubiconmd / injectable

Opinionated and declarative Dependency Injection library for ruby.
https://rubygems.org/gems/injectable
MIT License
34 stars 5 forks source link

Increase proc compatibility (ampersand and triple-equal) #18

Closed rewritten closed 2 years ago

rewritten commented 4 years ago

This will allow constructs like

data.then(&MyService).tap(&MySideEffects)

and

case data
when MyValidator.new(**some_config), MyOtherValidator
  :ok
when MyValidator
  :so_and_so
else
  :nope
end
codeclimate[bot] commented 4 years ago

Code Climate has analyzed commit ab82fbbc and detected 0 issues on this pull request.

View more on Code Climate.

rewritten commented 4 years ago

Maybe overriding the class method :=== is too invasive, as this would break:

case my_service_instance
when MyServiceClass
  :something
when MyOtherServiceClass
  :something_else
else
  nil
end

Although, I don't see why one would branch on a service instance type...

rewritten commented 4 years ago

Procs also respond to square-brackets:

my_proc = ->(str) { str.upcase }
my_proc['asdf']
# => "ASDF"

but I know no one that uses it.

rewritten commented 4 years ago

Hold your horses, this will not work with inheritance (alias is scoped to the definition scope)

iovis commented 4 years ago

Hey man, thanks again for the proposal!

Unfortunately Iā€™m currently sick so it might take me a few days to come back to you, sorry about that!

Papipo commented 4 years ago

I like the proc thingy, not so sure about the triple equals, but still, I think that it would be better to implement those in separate PRs.

iovis commented 4 years ago

Hey man, thanks again for the proposal!

Unfortunately Iā€™m currently sick so it might take me a few days to come back to you, sorry about that!

Haven't forgotten about these, I'm very sorry for the wait. I finally recovered this week but I have some stuff that has piled on because of that downtime and has kept me from taking a look at these. I want to take a good look at all of these!

Also, hi @Papipo! šŸ‘‹

Papipo commented 4 years ago

Hi @iovis šŸ‘‹ . Maybe you got sick because you had to go to the office?

iovis commented 4 years ago

No office for us for a while haha