Awesome post Fred! I've personally never felt the need to use a Proxy in my Ruby code, probably because I've never run into and/or requirements that called this necessity. Can you describe a real world use case where you've used this?
Fred is a software jack of all trades, having worked over the last 24 years at every stage of the SDLC and has authored [two books](https://www.amazon.co.uk/Fred-Heath/e/B08F3Q1H1M).
Thanks Luis! Yes, I often have to use proxies. A recent use-case I had was this: Our client was using an external CRM API in their server code. We had built a new, better API and the client wanted to gradually phase out the old API and use ours instead. They had a class along these lines:
classoldAPIFacadedefupdateUser#call oldAPI with @userendend
What I did was to give them a proxy:
ModuleAPIProxydefself.prepended...Proxy.class_evaldodefine_method(m)do|*args|if@user.region=='EMEA'# call our new APIelse# call old API super(*args)endendendend
Which they prepended at the end of the oldAPIFacade class.
I then kept removing conditions from the proxy until eventually all API calls were routed to our new API. It was a seamless, phased transition :)
That's awesome! Thank you for provide a real world example, made the blog post /concept much easier to understand. You should include it in the post itself
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Awesome post Fred! I've personally never felt the need to use a Proxy in my Ruby code, probably because I've never run into and/or requirements that called this necessity. Can you describe a real world use case where you've used this?
Thanks Luis! Yes, I often have to use proxies. A recent use-case I had was this: Our client was using an external CRM API in their server code. We had built a new, better API and the client wanted to gradually phase out the old API and use ours instead. They had a class along these lines:
What I did was to give them a proxy:
Which they prepended at the end of the oldAPIFacade class.
I then kept removing conditions from the proxy until eventually all API calls were routed to our new API. It was a seamless, phased transition :)
That's awesome! Thank you for provide a real world example, made the blog post /concept much easier to understand. You should include it in the post itself