I have a Gemfile as part of rails app, which I am converting to a gem.
gem "jruby-openssl", "0.7.4"
gem "nokogiri"
gem 'xml-simple', :require => 'xmlsimple'
gem "httpclient"
How do I write, the .gemspec file, for the gem I create from this? The gemspec I wrote looks like this.
Gem::Specification.new do |s|
s.name = "my_gem"
s.platform = Gem::Platform::RUBY
s.authors = [""]
s.email = [""]
s.homepage = ""
s.summary = %q{MyGem}
s.description = %q{MyGem}
s.files = Dir["{app,lib,config,public,db}/**/*"] + ["Rakefile", "Gemfile"]
s.require_paths = ["lib"]
s.add_dependency 'nokogiri', '>= 1.5.0'
s.add_dependency('xml-simple')
s.add_dependency 'httpclient'
end
However, the xmlsimple object is not called, because, the add dependency cannot take the same parameters as a regular gem call. How do I write the gemspec to call xmlsimple like its done in the Gemfile ?
You can do:
s.add_dependency 'xml-simple'
Like you have already. However when requiring the library inside your application (perhaps inside lib/yourgem.rb
) you do:
require 'xmlsimple'
Instead of:
require 'xml-simple'
I found a gem that is using xml-simple which may be useful for your reference. https://github.com/stjohncj/RESTRack