How to add dependency of a local gem to a rails plugin/engine, in .gemspec file

后端 未结 3 1170
自闭症患者
自闭症患者 2021-01-03 19:17

I had tried in this way:

 s.add_dependency \'gem\', :path => \'../gem\'

like add gem in the gemfile, but it doesn\'t work,

3条回答
  •  盖世英雄少女心
    2021-01-03 19:51

    Sometimes you want to embed one gem into another gem, nevermind why. You can reference one gempec from another to completely encapsulate a local gem.

    require "rubygems"
    
    embedded_gemspec = Gem::Specification::load("path/to/internal.gemspec")
    
    Gem::Specification.new do |spec|
      spec.name          = "gem_that_contains_another_gem"
      # spec.whatever,   = whole bunch of other info
    
      #                     our files               + other gem's files
      spec.files         = ['file1.rb', 'file2.rb'] + embedded_gemspec.files
    
      # our dependencies
      spec.add_dependency 'nokogiri'
      # other gem's dependencies
      embedded_gemspec.runtime_dependencies.each { |d| spec.add_dependency d }
    
    end
    

    EDIT: this appears to only work locally. If you try to install this gemspec from, say, a git repo, it won't know where to get embedded_gemspec (even though embedded_gemspec's dependencies come in just fine).

提交回复
热议问题