1

I am trying to extract some code from a Ruby application into a gem for code reuse. In order to do that safely, I want to ensure there are no references to other code in the project by creating a virtual "fence". The only code inside the "fence" should be existing gems and the code I'm trying to gemify.

I'm thinking of doing that through some magic monkey patching that hooks into the method invocation logic and subsequently logs each method call.

Here is a visual representation of what I'm trying to achieve:

enter image description here

Some assumptions:

  1. the code to be gemified is much smaller than the total code in the project
  2. the project code can be modified, but still needs to be production-quality

I have already investigated using the solution recommended here:

How can I intercept method call in ruby?

However, this solution intercepts the method call on the receiver side and also requires extending code in every class in the project (well, except for in the classes to gemify).

Ideally I would like to at most extend all the classes to be gemified.

Community
  • 1
  • 1
Magne Land
  • 1,204
  • 1
  • 9
  • 7

0 Answers0