宝石到铁轨中的本地图书馆

发布于 2025-01-28 08:02:16 字数 138 浏览 1 评论 0原文

我的老板要求我写一颗宝石来包装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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

只想待在家 2025-02-04 08:02:16

我们经常为此使用服务对象方法,可以在此处找到 https://blog.appsignal.com/2020/06/17/usise-service-objects-in-ruby-on-on-rails.html < /a>

基本上,您将代码放入App/Services中,然后抽象所有配置和使用范围,以便您可以执行:

result = AppServices::SubscriptionService.new({
           subscription_params: {
             subscription: @subscription,
             coupon: params[:coupon],
             token: params[:stripeToken]
           } 
         }).call

因此您的代码可以在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.html

Basically you put your code in app/services and abstract all config and usage away so you can do:

result = AppServices::SubscriptionService.new({
           subscription_params: {
             subscription: @subscription,
             coupon: params[:coupon],
             token: params[:stripeToken]
           } 
         }).call

So your code could live in app/services/canvas/lib for example.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文