Include local gem in Rack app - ruby

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?

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.

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

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/**/*']

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.

requiring a custom gem

I forked https://github.com/evolve75/RubyTree and made a few changes for usage in an application. I also added a rubytree.gemspec (which was not present in the original repo) in order to install it with bundler using a Gemfile in my application:
gem 'rubytree', :git => 'git#github.com:anthonylebrun/RubyTree.git'
I do a bundle install in my app and everything goes smoothly but I'm not able to
require 'rubygems'
require 'tree'
and just have it work. Instead I get:
LoadError: no such file to load -- tree
So I suspect I may be setting up paths wrong? I'm no gemspec pro, I just threw it together by looking at another gem. Here it is:
Gem::Specification.new do |s|
s.platform = Gem::Platform::RUBY
s.name = 'rubytree'
s.version = '0.8.1'
s.summary = 'Tree data structure'
s.description = 'RubyTree allows you to create and manipulate tree structures in ruby'
s.required_ruby_version = '>= 1.8.7'
s.required_rubygems_version = ">= 1.3.6"
s.author = 'Anupam Sengupta'
s.email = 'anupamsg#gmail.com'
s.homepage = 'http://rubytree.rubyforge.org/'
s.files = ['lib/tree.rb']
s.require_path = ['lib']
end
Any ideas? If there's anything I can clarify, let me know too!
Have you tried this?
require 'rubygems'
require 'bundler/setup'
require 'tree'
Have you tried
require 'rubytree'
as well?

Resources