Has much changed with the release of Bundler? Is there a template that can be used as a base? What are the best practices?
相关问题
- How to specify memcache server to Rack::Session::M
- Why am I getting a “C compiler cannot create execu
- reference to a method?
- ruby 1.9 wrong file encoding on windows
- gem cleanup shows error: Unable to uninstall bundl
相关文章
- Ruby using wrong version of openssl
- Difference between Thread#run and Thread#wakeup?
- how to call a active record named scope with a str
- “No explicit conversion of Symbol into String” for
- Segmentation fault with ruby 2.0.0p247 leading to
- How to detect if an element exists in Watir
- uninitialized constant Mysql2::Client::SECURE_CONN
- ruby - simplify string multiply concatenation
Telemachus's advice is good. If you follow it your gem will be setup to play nicely with bundler.
You might also try using jeweler. It's a gem that generates skeletons for gems. The default skeleton that it spits out complies with all of the conventions Telemachus mentioned and it will also do some nice things like add your favorite test framework or create a GitHub repository.
The simplest way it's to use bundler:
You may even use it in an existing project from the parent directory.
This rubygems guide provides information about the structure of a gem and then goes into detail about what should be included in your gemspec
You may find it easier to use bundler to create the folder structure of the gem for you:
bundle gem <gem_name>
my_gem$ bundle gem my_gem create my_gem/Gemfile create my_gem/Rakefile create my_gem/LICENSE.txt create my_gem/README.md create my_gem/.gitignore create my_gem/my_gem.gemspec create my_gem/lib/my_gem.rb create my_gem/lib/my_gem/version.rb Initializing git repo in /Users/keith/projects/my_gem/my_gem
When writing fat (binary) gems the structure is usually this:
lib/1.8/binary.so
lib/1.9/binary.so
lib/my_gem.rb
(this file simply chooses whichbinary.so
to load depending on ruby version)And for native extensions:
lib/ext/my_gem/my_sources.*
lib/my_gem.rb
I also usually put a
version.rb
file here:lib/my_gem/version.rb
and it simply contains something like:
Also, IMO, don't put any .rb files except the file you want people to use to load the gem, in the
lib/
directory. Instead put all auxiliary files inlib/my_gem/
Some posts that I have found useful:
Edit (2012-01-10): An excellent all-around guide to gem best practices is RubyGems Guides. I would highly recommend starting here now.
To summarize the key points:
lib/gem.rb
andlib/gem/
structure for code.bin
, any data files indata
and tests intest
orspec
.require
or depend upon files outside of the load path. (VERSION
files often seem to live in odd places in gems.)require 'rubygems'
.$LOAD_PATH
.require File.join(__FILE__, 'foo', 'bar')
, you're doing it wrong.