宝石到铁轨中的本地图书馆
我的老板要求我写一颗宝石来包装API(画布)消费者的应用程序,我做到了,它起作用了,但是在最后一刻,他要求我不要使用宝石方法,而是创建它的模型。 。像原样一样包含所有内容,就像本地安装的库一样使用吗?最好的方法是什么?我的宝石取决于net_http适配器的法拉第
My boss asked me to write a gem to wrap an API (canvas) consumer for our app, I did it and it works, but in the last minute he asked me not to use the gem approach but to create a Model of it... I have a vague idea of creating the model for the endpoints and put the code in the controller, but the gem is highly "modularized" so to speak, modules requiring modules and classes inheriting from other classes... Is there some way to include everything just as it is and use like a locally installed library? What is the best approach? My gem depends on Faraday for net_http adapter
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我们经常为此使用
服务对象
方法,可以在此处找到 https://blog.appsignal.com/2020/06/17/usise-service-objects-in-ruby-on-on-rails.html < /a>基本上,您将代码放入
App/Services
中,然后抽象所有配置和使用范围,以便您可以执行:因此您的代码可以在
App/services/cansvas/canvas/lib 例如。
We often use the
Service object
approach for this, a good writeup can be found here https://blog.appsignal.com/2020/06/17/using-service-objects-in-ruby-on-rails.htmlBasically you put your code in
app/services
and abstract all config and usage away so you can do:So your code could live in
app/services/canvas/lib
for example.