简体   繁体   English

安装gem时添加文件

[英]Adding files when installing a gem

I'm writing a gem which needs a directory to store some config. 我正在写一个gem,它需要一个目录来存储一些配置。 I want to do this upon installation but I'm not sure how best to insert code into the installation process. 我想在安装时执行此操作,但是我不确定如何最好地在安装过程中插入代码。

By adding the code to the Rakefile and adding spec.extensions = ["Rakefile"] to my gemspec, I've achieved what I want to do but this method means the installation process tells me I'm building native extensions; 通过将代码添加到Rakefile并向我的gemspec添加spec.extensions = ["Rakefile"] ,我已经实现了我想要做的,但是这种方法意味着安装过程告诉我我正在构建本机扩展。 this is misleading. 这是误导。

Is there a built in way of doing this or via bundler? 是否有内置的方法或通过捆绑器? I'm assuming Bundler::GemHelper.install_tasks is close to what I'm after but I can't find helpful documentation. 我假设Bundler::GemHelper.install_tasks与我所Bundler::GemHelper.install_tasks的接近,但是我找不到有用的文档。

EDIT: My current Rakefile . 编辑:我当前的Rakefile

It seems like the RubyGems designers intentionally left the option to run a script during installation... so I would say that the accepted way is to do the directory creation in the application. 似乎RubyGems设计人员故意在安装过程中留下了运行脚本的选项...所以我要说,公认的方法是在应用程序中创建目录。

The unix way is for the application to create the directory (vi and git do this). Unix方式是为应用程序创建目录(vi和git为此)。

FileUtils.mkdir_p is handy... it will save you from having to check if the directory is already there. FileUtils.mkdir_p很方便...它将使您不必检查目录是否已存在。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM