I'm writing a node module to be open sourced and there's a dependency on some Ruby code (see Can I include a Ruby Gem in a Node.js project? for details). I made a Ruby project that requires some gems and all of that works well. In my node_module, I want to interface it via exec
to the Ruby code.
我正在编写一个开放源代码的节点模块,并且依赖于一些Ruby代码(请参见我是否可以在节点中包含一个Ruby Gem)。js项目吗?详情)。我做了一个需要一些宝石的Ruby项目,所有这些都很好。在node_module中,我希望通过exec与Ruby代码进行接口。
But now there's Ruby dependencies as well. So can I somehow specify the Ruby version, and the gemset required to run my node package?
但是现在还有Ruby依赖项。那么我是否可以指定Ruby版本,以及运行节点包所需的gemset ?
Ambiguous question perhaps. I can clarify if anything is unclear.
模棱两可的问题。如果有什么不清楚的话,我可以澄清。
2 个解决方案
#1
2
I don't think you can/should specify the Ruby version to use when executing your code. That should be up the library consumer so choose. Since you want to execute your code with exec
, the library consumer will have the added responsbility of making ruby accessible to the node process. How that happens is not up to you as the library developer.
我认为您不应该在执行代码时指定要使用的Ruby版本。这应该由库使用者决定。由于您希望使用exec执行代码,因此库使用者将具有使节点进程能够访问ruby的附加响应性。如何实现这一点并不取决于您作为库开发人员。
As for dependencies/gemsets, just use bundler.
对于依赖项/gemsets,只需使用bundler。
#2
1
Maybe you could do something like this - without more information it's hard to say.
也许你可以做这样的事情——如果没有更多的信息,这很难说。
-
On the ruby side, build your gem to do whatever it needs to do and then add a rake task to it. How you build this rake task is obviously up to the demands of the project and how it will be used, but it will provide a way for you to interface from the outside.
在ruby端,构建您的gem来做它需要做的任何事情,然后向它添加一个rake任务。如何构建rake任务显然取决于项目的需求以及如何使用它,但它将为您提供一种从外部接口的方式。
-
In the 'middle' build a bash script that includes RVM - this way you can require a specific gemset/do specifc things before running the rake task. Another benefit is that if you want to change the gemset or other implementation details, you just change the bash script.
在“中间”构建一个包含RVM的bash脚本——通过这种方式,您可以在运行rake任务之前需要一个特定的gemset/do specifc。另一个好处是,如果希望更改gemset或其他实现细节,只需更改bash脚本。
-
On the node side, call the bash script. More info on that in this answer.
在节点端,调用bash脚本。更多关于这个答案的信息。
#1
2
I don't think you can/should specify the Ruby version to use when executing your code. That should be up the library consumer so choose. Since you want to execute your code with exec
, the library consumer will have the added responsbility of making ruby accessible to the node process. How that happens is not up to you as the library developer.
我认为您不应该在执行代码时指定要使用的Ruby版本。这应该由库使用者决定。由于您希望使用exec执行代码,因此库使用者将具有使节点进程能够访问ruby的附加响应性。如何实现这一点并不取决于您作为库开发人员。
As for dependencies/gemsets, just use bundler.
对于依赖项/gemsets,只需使用bundler。
#2
1
Maybe you could do something like this - without more information it's hard to say.
也许你可以做这样的事情——如果没有更多的信息,这很难说。
-
On the ruby side, build your gem to do whatever it needs to do and then add a rake task to it. How you build this rake task is obviously up to the demands of the project and how it will be used, but it will provide a way for you to interface from the outside.
在ruby端,构建您的gem来做它需要做的任何事情,然后向它添加一个rake任务。如何构建rake任务显然取决于项目的需求以及如何使用它,但它将为您提供一种从外部接口的方式。
-
In the 'middle' build a bash script that includes RVM - this way you can require a specific gemset/do specifc things before running the rake task. Another benefit is that if you want to change the gemset or other implementation details, you just change the bash script.
在“中间”构建一个包含RVM的bash脚本——通过这种方式,您可以在运行rake任务之前需要一个特定的gemset/do specifc。另一个好处是,如果希望更改gemset或其他实现细节,只需更改bash脚本。
-
On the node side, call the bash script. More info on that in this answer.
在节点端,调用bash脚本。更多关于这个答案的信息。