ruby: gem build... how do i include vendor directory in gem? - ruby

I run gem build mygem.gemspec and the vendor dir is not included. How do I include it in my gem? I am assuming that I need the vendor dir included if I want to package all the dependencies with my gem.
I think it has to do with Dir['vendor/**']... I know that is wrong.
My gemspec file:
lib = File.expand_path('../lib', __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'fpa/fix_filename/version'
Gem::Specification.new do |spec|
spec.name = "fpa-fix_filename"
spec.version = Fpa::FixFilename::VERSION
spec.authors = ["na"]
spec.email = ["na"]
spec.summary = %q{A Class to fix bad file names -- includes a binary for command line use.}
spec.description = %q{}
spec.license = "MIT"
spec.files = Dir['lib/fpa/**/*'] + Dir['bin/*'] + Dir['vendor/**']
spec.bindir = "bin"
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
spec.require_paths = ["lib"]
spec.add_runtime_dependency "micro-optparse", "~> 1.2.0"
spec.add_development_dependency "bundler", "~> 1.8"
spec.add_development_dependency "rake", "~> 10.0"
end

Did you tried like this ?
Dir['vendor/**/*']

Related

gemspec is broken, cli won't run

I keep running into a problem, this gemspec is invalid. Can someone please help me?
lib = File.expand_path("../lib", __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require "Practical/version"
Gem::Specification.new do |spec|
spec.name = "Practical"
spec.version = Practical::VERSION
spec.authors = ["'D'"]
spec.email = ["'#gmail.com'"]
spec.summary = %q{TODO: Write a short summary, because
RubyGems requires one.}
spec.description = %q{TODO: Write a longer description or delete
this line.}
spec.homepage = "TODO: Put your gem's website or public repo
URL here."
spec.license = "MIT"
# Prevent pushing this gem to RubyGems.org. To allow pushes either
set the 'allowed_push_host'
# to allow pushing to a single host or delete this section to allow
pushing to any host.
if spec.respond_to?(:metadata)
spec.metadata["allowed_push_host"] = "TODO: Set to
'http://mygemserver.com'"
spec.metadata["homepage_uri"] = spec.homepage
spec.metadata["source_code_uri"] = "TODO: Put your gem's public repo
URL here."
spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md
URL here."
else
raise "RubyGems 2.0 or newer is required to protect against "
"public gem pushes."
end
# Specify which files should be added to the gem when it is
released.
# The `git ls-files -z` loads the files in the RubyGem that have
been added into git.
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
`git ls-files -z`.split("\x0").reject { |f|
f.match(%r{^(test|spec|features)/}) }
end
spec.bindir = "exe"
spec.executables = spec.files.grep(%r{^exe/}) { |f|
File.basename(f) }
spec.require_paths = ["lib"]
spec.add_development_dependency "bundler", "~> 1.17"
spec.add_development_dependency "rake", "~> 10.0"
spec.add_dependency "nokogiri"`enter code here`
end
I'm not sure what changed. This worked a few months ago, but now it's broken. Basically, I'm stuck just getting this to run, the interpreter keeps telling me I have an error in my gemspec. I can't find it.

Require in gem don't work

I created gem with bundler and puts all my ruby files into '/lib' as documentation suggested.
But I have a problem, after build the gem which "rake build" command and install (gem install pkg/gem) I can't use it because:
LoadError: cannot load such file -- mygem/client
this is cause because in main file i try to require 'mygem/client.rb' which is in lib/mygem/client.rb
and it is doesn't work :/
This is my gemspec:
# coding: utf-8
lib = File.expand_path('../lib', __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'diggy/version'
Gem::Specification.new do |spec|
spec.name = "diggy"
spec.version = Diggy::VERSION
spec.authors = [""]
spec.email = [""]
spec.summary = %q{: Write a short summary, because Rubygems requires one.}
spec.description = %q{: Write a longer description or delete this line.}
spec.homepage = ""
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
# to allow pushing to a single host or delete this section to allow pushing to any host.
if spec.respond_to?(:metadata)
spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
else
raise "RubyGems 2.0 or newer is required to protect against " \
"public gem pushes."
end
spec.files = `git ls-files -z`.split("\x0")
spec.bindir = "exe"
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
spec.require_paths = ["lib"]
spec.add_development_dependency "bundler", "~> 1.14"
spec.add_development_dependency "rake", "~> 10.0"
end
Assuming your main file is named mygem.rb and is inside the lib folder, you should be able to require the file lib/mygem/client.rb with:
require 'mygem/client'
Notice that I didn't use the .rb extension.

Rubygem creation ... I have pushed a new gem but the Source Code link is missing

I created and pushed a new gem for the first time in several years. I am a newbie in the Gem business.
I followed the various instructions and the gem was successfully pushed. Here is the link to new gem:
https://rubygems.org/gems/yequel
The only problem is that the 'Source Code' link does not appear on the above page. I have attached the gemspec that was used to push the gem.
Please help me identify what I am missing.
Thanks ... Al
#----------------------------------------------------------------------------
# coding: utf-8
lib = File.expand_path('../lib', __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'yequel/version'
Gem::Specification.new do |spec|
spec.name = "yequel"
spec.version = Yequel::VERSION
spec.authors = ["Al Kivi"]
spec.email = ["al.kivi#vizi.ca"]
spec.summary = %q{Provides a sequel style ORM layer for YAML::Store}
spec.description = %q{Yequel provides a sequel style with basic features to access YAML::Store tables. Its target audience is application developers who require light weight alternative to SQL databases.}
spec.homepage = "https://rubygems.org/profiles/vizi_master"
spec.license = "MIT"
# Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
# delete this section to allow pushing this gem to any host.
#if spec.respond_to?(:metadata)
#spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
#else
#raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
#end
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
spec.bindir = "exe"
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
spec.require_paths = ["lib"]
spec.add_development_dependency "bundler", "~> 1.11"
spec.add_development_dependency "rake", "~> 10.0"
spec.add_runtime_dependency "hash_dot"
spec.add_runtime_dependency "will_paginate"
end
The Source link isn’t specified in the gemspec, only the homepage (which could point to a code repository).
If you want to set the the source link you need to do it on the Rubygems site. Sign into rubygems.org, and go to https://rubygems.org/gems/yequel/edit (there should be a link to this page from your gem’s page in the “Links” section, if you are signed in). From there you should be able to set the Source Code URL, along with a range of other URLs.

Problems with require in gem

I am trying to make a simple gem which has some modules. However, after I have built and installed the gem and try require it in a script I get an error:
from ...ruby-1.9.3-p429/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require': cannot load such file -- my_gem/some_class (LoadError)
And
from ...ruby-1.9.3-p429/gems/my_gem-0.0.1/lib/my_gem.rb:2:in `<top (required)>'
Line 2 in my_gem.rb is require "my_gem/some_class.
As far as I understand (from this question) the problem seems to be that the file I require isn't found.
What is going on? Why can't I require my own files inside the gem?
The files I want to require is "next to" the version.rb.
#File Structure
#
# root
# |->lib
# | |->my_gem.rb
# | |->my_gem
# | | |->some_class.rb
# | | |->some_class2.rb
# | | |->version.rb
The SomeClass looks like this:
module MyGem
class SomeClass
def self.someMethod
...
end
end
All I do in the script where I get the error is the following:
#!/usr/bin/ruby
require "rubygems"
require "my_gem"
Gemspec:
# coding: utf-8
lib = File.expand_path('../lib', __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'my_gem/version'
Gem::Specification.new do |spec|
spec.name = "my_gem"
spec.version = MyGem::VERSION
spec.authors = ["My Name"]
spec.email = ["my_email#gmail.com"]
spec.description = %q{A simple Ruby gem that fails.}
spec.summary = %q{Failing gem for Ruby.}
spec.homepage = "http://some.website.com"
spec.license = "MIT"
spec.files = `git ls-files`.split($/)
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
spec.require_paths = ["lib"]
spec.add_development_dependency "bundler", "~> 1.3"
spec.add_development_dependency "rake"
end
It looks like you have not added your class files to git, while your Gemspec file uses common pattern to specify files to be added to gem:
spec.files = `git ls-files`.split($/)
You have two options not to run into same trouble again:
Add all the files to version control before building a gem;
Use hand-written spec.files list in Gemspec.
Or, if you are using svn, you might want to change the spec.files to:
spec.files = `svn list`.split($/)
Hope it helps.

Include local gem in Rack app

I'm creating a rack app gem. I include my gem locallly in my gem file but I can't include it in my config.ru file.
novo.gemspec
# -*- encoding: utf-8 -*-
lib = File.expand_path('../lib', __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'novo/version'
Gem::Specification.new do |gem|
gem.name = "novo"
gem.version = Novo::VERSION
gem.authors = ["Tobias Sandelius"]
gem.email = ["tobias#sandeli.us"]
gem.description = %q{TODO: Write a gem description}
gem.summary = %q{TODO: Write a gem summary}
gem.homepage = ""
gem.files = `git ls-files`.split($/)
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
gem.require_paths = ["lib"]
end
config.ru
require 'novo'
# Set site root
NOVO_ROOT = Dir.pwd
run Novo::Dispatcher.new
I get the following error:
`require': cannot load such file -- novo (LoadError)
I'm missing something but don't know what?

Resources