我怎样才能让Ruby gem包复制文件到任意位置? [英] How can I make a Ruby gem package copy files to arbitrary locations?

查看:115
本文介绍了我怎样才能让Ruby gem包复制文件到任意位置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设你有一个软件包。你想让它成为宝石,因为宝石是在Ruby世界中分配任何事物的事实上的标准方式。宝石非常棒 - 对于图书馆来说。但对于真正的应用程序,Rubygems系统似乎缺乏。只有最近他们引入了一种将可执行​​文件标记为放置在全系统可执行文件路径中某处的方法。不幸的是,Ruby的宝石似乎仍然需要软件包的其他方面,即将配置文件放在/ etc或/ usr / share / doc下的文件中。或者是?我的问题是:

我可以将指令或代码放入gemspec中,将配置安装到/ etc中,并且在某些明智的,标准化的位置(如/ usr / share / DOC)?或者,也许,作为一种解决方法,可以运行安装后脚本来执行这些操作吗?



仅供参考: GemSpec规范



请注意,rubygems.org在这个写作。以下是该网页的Google缓存: http://74.125.95.132/search?q=cache:JwJO6slR4BwJ:www.rubygems.org/阅读/章节/ 20 + http://www.rubygems.org/read/chapter/20%23page85& hl = en& ct = clnk& cd = 1

如果您检查 repo中的specification.rb文件,然后向下滚动(搜索:section:必需的gemspec属性),您可以看到似乎是当前支持的属性。

解决方案

2015-11-11
这里是情况:RubyGems支持前后安装/卸载钩子作为 gem 命令的扩展。换句话说,这些钩子适用于所有已安装的宝石,并且不打算在特定的宝石中进行自定义。它们通常在 /usr/lib64/ruby/2.2.0/rubygems 中找到,名为 operating_system.rb >;或任何位置和版本的Ruby安装。钩子是这样使用的:

 #/usr/lib/ruby/xyz/rubygems/operating_system.rb 
Gem .pre_install执行|安装程序|
#做任何
结束

Gem.pre_uninstall do |安装程序|
#做任何
结束

Gem.post_install do |安装程序|
#做任何
结尾
。 。 。

深入了解API文档,似乎要使用特定于gem的外部活动,可以使用插件。请参阅: http://guides.rubygems.org/plugins/#executablehooks https://github.com/rvm/executable-hooks 为例。但是,这些都似乎通常影响RubyGem应用程序,而不是专门影响一个gem。而这些插件需要安装成宝石本身才能生效。



在我看来,gem特定的安装前和安装后挂钩是一个安全问题。安装系统级Gem的人有定义root特权,并且允许RubyGem在执行任何操作之外执行简单的安装库具有明显的安全隐患。



我正在检查Ruby (2015-11-10)。可能这些钩子仅适用于在不同平台上安装RubyGem的用户。



RubyGems现在(2015)支持 pre_install() post_install()作为以&块作为参数的方法。假设你可以做任何你想要的任何东西,只要你不返回 false 。返回 nil 是可以的,但是 false return会中止gem install。


Suppose you have a software package. You want to make it a gem, because gems are the de facto standard way to distribute anything in the Ruby world. Gems are great -- for libraries. But for real applications, the Rubygems system seems lacking. Only "recently" did they introduce a way to mark executables to be placed in somewhere in the system wide executable PATH. Unfortunately, Ruby gems still seems to be wanting in other aspects of software packaging, namely putting configuration files in places like /etc, or documentation under /usr/share/doc. Or is it? My question is:

Can I put instructions or code in a gemspec to have configuration installed into /etc, and documentation under some sensible, standardized place (like /usr/share/doc)? Or perhaps, as a workaround, can a post-install script be run to do these things?

For reference: the GemSpec specification.

Note that rubygems.org is down at the time of this writing. Here's the Google cache of that page: http://74.125.95.132/search?q=cache:JwJO6slR4BwJ:www.rubygems.org/read/chapter/20+http://www.rubygems.org/read/chapter/20%23page85&hl=en&ct=clnk&cd=1

If you examine the specification.rb file in the repo, and scroll down towards the end (search for ":section: Required gemspec attributes"), you can see what appear to be the currently supported attributes. I see nothing in there that looks like what I want.

解决方案

2015-11-11 Here is the situation: RubyGems supports the pre and post install/uninstall hooks as extensions to the gem command. In other words these hooks apply to all gems that are installed and are not meant to be customised in a specific gem. They are invoked in a file called operating_system.rb usually found in /usr/lib64/ruby/2.2.0/rubygems; or whatever location and version Ruby is installed. The hooks are employed thus:

# /usr/lib/ruby/x.y.z./rubygems/operating_system.rb
Gem.pre_install do | installer |
  # do whatever
end

Gem.pre_uninstall do | installer |
  # do whatever
end

Gem.post_install do | installer |
  # do whatever
end
. . .

Going deeper into the API documentation it appears that to employ external activities specific to a gem one has plugins available. See: http://guides.rubygems.org/plugins/#executablehooks and https://github.com/rvm/executable-hooks as an example. However, these all seem to affect the RubyGem application generally rather than one gem specifically. And such plugins need be installed as gems themselves to have effect.

It seems to me that gem specific pre and post install hooks are a security issue. Someone installing a system level Gem has by definition root privilege and allowing RubyGem to perform arbitrary actions outside of simply installing a library has obvious security implications.

I am checking with the Ruby folks on this (2015-11-10). It may be that these hooks are only for the use of people installing RubyGem itself on different platforms.

RubyGems now (2015) supports pre_install() and post_install() hooks as methods which take an &block as their arguments. Presumably you can do anything you want in either of these providing that you do not return false from either. Returning nil is OK but a false return will abort the gem install.

这篇关于我怎样才能让Ruby gem包复制文件到任意位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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