如何将数据保存在红宝石宝石中? [英] How to persist data in a ruby gem?

查看:79
本文介绍了如何将数据保存在红宝石宝石中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发用于rails应用程序的红宝石宝石. gem需要使用来自Web服务的实时数据来初始化".

I'm developing a ruby gem for use in rails app. The gem need to "initialize" using live data from a webservice.

但是此初始化过程很长,我想将初始化数据保存在某个地方.我应该在哪里保存它?

But this initialization is a long process, and i want to save the initialization data somewhere. Where should i save it?

我可以将其保存在父Rails应用程序数据库中,但是我需要创建表和迁移,这并不理想.

I could save it in the parent rails app database, but i would need to create tables and migrations, and this isn't ideal.

我正在考虑在gem文件夹中使用文本文件或redis数据库...这是一个好习惯吗?

I'm thinking of using a text file or redis database inside the gem folder... Is this a good practice?

谢谢.

推荐答案

ActiveSupport具有多个如果需要更大的灵活性,可以提供一个初始化程序,例如:

If you need more flexibility, you could provide an initializer, something like:

# config/initializers/my_gem.rb
MyGem.configure do |config|
  config.cache = Rails.cache
  config.cache_key = 'my-gem-initialization-data'
end

这篇关于如何将数据保存在红宝石宝石中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆