I have a small project that I'm working on and I would like the
executable to be put in the usr bin path and setup so that it can be
used as a command line utility automatically when installed using gem
install. How would I go about setting it up that way? I've been trying
to access the rubygems reference but it seems to be down.
Rake::GemPackageTask.new(spec) do |pkg|
pkg.need_tar = true
end
The part that says s.executables lists the files that will be
installed into the path. In this case, its calling the file named
the_executable, which would be in the bin subdirectory of the gem.
So, my directory structure would be
$ ls
README.txt bin/ pkg/
Rakefile lib/ test/
$ ls bin/
the_executable*
$ ls lib/
some_gem.rb
$ ls test/
test_some_gem.rb
Then to package it up, run rake gem. It will create a directory
called pkg, and place the gem in there.
Hope that is helpful.
Dusty Doris
···
On Dec 14, 12:57 am, Ch Ba <navo...@gmail.com> wrote:
I have a small project that I'm working on and I would like the
executable to be put in the usr bin path and setup so that it can be
used as a command line utility automatically when installed using gem
install. How would I go about setting it up that way? I've been trying
to access the rubygems reference but it seems to be down.
--
Posted viahttp://www.ruby-forum.com/.
That is exactly what I needed! Thanks a million Dusty. I was using a
.gemspec file and gem build foo.gemspec in order to gem it up, and even
though I included the executable it wasn't putting it in the bin. This
Rakefile is much more useful though, I need to learn more about them.
One more quick question if you don't mind, I had been executing the
executable from the base directory of the project, and using "require
'lib/foo.rb'. Obviously this no longer works, how would I access
"foo.rb" in it's new location after it is installed through a gem?
Sorry, I'm new to this whole gem thing =)
So, when you require rubygems, it will know how to find your new gem.
Then, when you require 'some_gem', it will look in the require_path
based off the root of your gem and automatically require some_gem.rb.
In this case it would be lib/some_gem.rb.
So, in the executable, you can simply require your gem.
Here is an example of what the executable could look like, assuming
you have a class method called do_something that is doing what you
need.
#!/usr/bin/env ruby
require 'rubygems'
require 'some_gem'
SomeGem.do_something
···
On Dec 14, 2:14 am, Ch Ba <navo...@gmail.com> wrote:
One more quick question if you don't mind, I had been executing the
executable from the base directory of the project, and using "require
'lib/foo.rb'. Obviously this no longer works, how would I access
"foo.rb" in it's new location after it is installed through a gem?
Sorry, I'm new to this whole gem thing =)
--
Posted viahttp://www.ruby-forum.com/.