Skip to content

Commit

Permalink
dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
qrush committed Apr 30, 2011
1 parent 29e00c2 commit 17af0c9
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 3 deletions.
52 changes: 52 additions & 0 deletions patterns.md
Expand Up @@ -124,6 +124,49 @@ managing a complex version manifest for many gems.
Declaring dependencies
----------------------

Gems work with other gems. Here's some tips to make sure they're nice to each
other.

### Runtime vs. development

RubyGems provides two main "types" of dependencies: runtime and development.
Runtime dependencies are what your gem needs to work (such as
[rails](http://rubygems.org/gems/rails) needing
[activesupport](http://rubygems.org/gems/activesupport)).

Development dependencies are useful for when someone wants to make
modifications to your gem. Once specified, someone can run
`gem install --dev your_gem` and RubyGems will grab both sets of dependencies
necessary. Usually development dependencies include test frameworks, build
systems, etc.

Setting them in your gemspec is easy, just use `add_runtime_dependency` and
`add_development_dependency`:

Gem::Specification.new do |s|
s.name = "hola"
s.version = "2.0.0"
s.add_runtime_dependency("daemons", ["= 1.1.0"])
s.add_development_dependency("bourne", [">= 0"])


### Don't use `gem` from within your gem

You may have seen some code like this around to make sure you're using a
specific version of a gem:

gem "extlib", ">= 1.0.8"
require "extlib"

It's reasonable for appliations that consume gems to use this (but they could
also use a tool like [Bundler](http://gembundler.com)). Gems themselves **should
not** do this, they should instead use dependencies in the gemspec so RubyGems
can handle loading the dependency instead of the user.

### The twiddle-wakka

Explain ~>.

<a id="loading-code"> </a>
Loading code
------------
Expand All @@ -140,3 +183,12 @@ Requiring `'rubygems'`
Prerelease gems
--------------------


Credits
-------

Several sources were used for content for this guide:

* [Rubygems Good Practice](http://yehudakatz.com/2009/07/24/rubygems-good-practice/)
* [Gem Packaging: Best Practices](http://weblog.rubyonrails.org/2009/9/1/gem-packaging-best-practices)
* [How to Name Gems](http://blog.segment7.net/2010/11/15/how-to-name-gems)
2 changes: 1 addition & 1 deletion resources.md
Expand Up @@ -30,7 +30,7 @@ Philosophy

* [Semantic Versioning](http://semver.org/)
* [Ruby Packaging Standard](http://chneukirchen.github.com/rps/)
* [Why "require 'rubygems'" Is Wrong](http://tomayko.com/writings/require-rubygems-antipattern)
* [Why `require 'rubygems'` Is Wrong](http://tomayko.com/writings/require-rubygems-antipattern)
* [How to Name Gems](http://blog.segment7.net/2010/11/15/how-to-name-gems)

Patterns
Expand Down
2 changes: 1 addition & 1 deletion stylesheets/screen.css
Expand Up @@ -690,7 +690,7 @@ body.home {
margin: 25px 0;
clear: both; }
#container #content h3 {
font-size: 16px; }
font-size: 14px; }
#container #content p {
margin: 1em 0; }
#container #content pre {
Expand Down
2 changes: 1 addition & 1 deletion stylesheets/screen.scss
Expand Up @@ -165,7 +165,7 @@ body.home {
}

h3 {
font-size: 16px;
font-size: 14px;
}

p {
Expand Down

0 comments on commit 17af0c9

Please sign in to comment.