本文介绍了用捆绑软件构建pry插件(gem)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

正如所述,pry的插件需要 pry - 前缀。
我已经尝试使用bundler构建:

  bundle gem pry-name 

但它搞砸了目录层次结构(创建2而不是1目录):

 创建pry-name / pry-name.gemspec 
创建pry-name / lib / pry / name.rb
创建pry-name / lib / pry / name / version .bb

在gemspec中它使用错误的目录结构:

  require'pry / name / version'

,并在同一个文件中运行这个git命令:

  spec.files =`git ls-files`.split $ / 

给出与上面相同的错误文件结构

有没有办法让 bundler将 - 识别为有效的文件名字符而不是/(目录分隔符)?

解决方案

根据Rubygems约定为nam如



请注意,如果您在 gem'pry-name' >使用 Bundler.require 的项目的Gemfile ,它也会在默认情况下使用约定,并尝试 require'pry / name'。



最好的解决方法是创建一个 lib / pry-name.rb 文件只包含 require'pry / name'。这使您的目录结构与Rubygems& Bundler约定,允许要求'pry / name'工作,同时允许 require'pry-name'工作。


As explained here pry's plugin require pry- prefix. I have tried building using bundler:

bundle gem pry-name

but it messed up directory hierarchies(creating 2 instead of 1 directory):

  create  pry-name/pry-name.gemspec
  create  pry-name/lib/pry/name.rb
  create  pry-name/lib/pry/name/version.rb

In the gemspec it is using wrong directory structure:

  require 'pry/name/version'

and in the same file it run this git command:

  spec.files         = `git ls-files`.split($/)

which gives, same as above, wrong structure of files

Is there way to tell bundler to recognize "-" as valid filename character not as "/"(directory separator)?

解决方案

bundle gem works according to the Rubygems convention for naming gems, as described at http://guides.rubygems.org/name-your-gem/

Note that if you include gem 'pry-name' in the Gemfile of a project that uses Bundler.require, it will use the convention there by default, too, and try to require 'pry/name'.

The best workaround is to create a lib/pry-name.rb file that just contains require 'pry/name'. This keeps your directory structure consistent with the Rubygems & Bundler convention, allowing require 'pry/name' to work, while also allowing require 'pry-name' to work.

这篇关于用捆绑软件构建pry插件(gem)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-17 03:23