The document discusses RubyGems, the package manager for the Ruby programming language. It describes how RubyGems improved on Ruby's original require method by allowing gems to be packaged and distributed. This introduced a standardized way to share and reuse code. The document also explains how RubyGems works under the hood, including how it modifies the load path and resolve dependencies through gemspec files. Rake tasks are also highlighted as a useful tool for gem authors to automate common tasks.
31. RUBYGEMS 101
MATT YOHO
⚡ matt $ irb
ruby-1.8.7-p249 > require 'foo'
LoadError: no such file to load -- foo
from (irb):1:in `require'
from (irb):1
32. RUBYGEMS 101
MATT YOHO
⚡ matt $ irb -rubygems
ruby-1.8.7-p249 > require 'foo'
LoadError: no such file to load -- foo
from /Users/matt/ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
from /Users/matt/ruby/1.8/rubygems/custom_require.rb:31:in `require'
from (irb):1
33. RUBYGEMS 101
MATT YOHO
⚡ matt $ irb
ruby-1.8.7-p249 > require 'foo'
LoadError: no such file to load -- foo
from (irb):1:in `require'
from (irb):1
34. RUBYGEMS 101
MATT YOHO
⚡ matt $ irb
ruby-1.8.7-p249 > require 'foo'
LoadError: no such file to load -- foo
from (irb):1:in `require'
from (irb):1
35. RUBYGEMS 101
MATT YOHO
⚡ matt $ irb -rubygems
ruby-1.8.7-p249 > require 'foo'
LoadError: no such file to load -- foo
from /Users/matt/ruby/1.8/rubygems/
custom_require.rb:31:in `gem_original_require'
from /Users/matt/ruby/1.8/rubygems/
custom_require.rb:31:in `require'
from (irb):1
36. RUBYGEMS 101
MATT YOHO
⚡ matt $ irb -rubygems
ruby-1.8.7-p249 > require 'foo'
LoadError: no such file to load -- foo
from /Users/matt/ruby/1.8/rubygems/
custom_require.rb:31:in `gem_original_require'
from /Users/matt/ruby/1.8/rubygems/
custom_require.rb:31:in `require'
from (irb):1
37. RUBYGEMS 101
MATT YOHO
⚡ matt $ irb -rubygems
ruby-1.8.7-p249 > require 'foo'
LoadError: no such file to load -- foo
from /Users/matt/ruby/1.8/rubygems/
custom_require.rb:31:in `gem_original_require'
from /Users/matt/ruby/1.8/rubygems/
custom_require.rb:31:in `require'
from (irb):1
49. RUBYGEMS 101
MATT YOHO
#!/usr/local/bin/ruby
#
# This file was generated by RubyGems.
#
# The application 'thin' is installed as part of a gem, and
# this file is here to facilitate running it.
#
require 'rubygems'
version = ">= 0"
if ARGV.first =~ /^_(.*)_$/ and Gem::Version.correct? $1 then
version = $1
ARGV.shift
end
gem 'thin', version
load 'thin'
51. RUBYGEMS 101
MATT YOHO
Rake tasks make a
gem author’s life
easier.
52. RUBYGEMS 101
MATT YOHO
namespace :gem do
desc 'Builds the gem from the gemspec'
task :build do
sh 'mkdir -p ./pkg'
sh 'gem build ./basic_assumption.gemspec'
sh 'mv ./basic_assumption-*.gem ./pkg/basic_assumption-EDGE.gem'
end
desc 'Installs the built gem'
task :install => :build do
sh 'gem install ./pkg/basic_assumption-EDGE.gem'
end
end
task :default => [:spec, :cucumber]
53. RUBYGEMS 101
MATT YOHO
⚡ basic_assumption (master)$ rake -T
(in /Users/matt/projects/basic_assumption)
rake bundle:install # Installs the dependencies listed in Gemfile
rake clobber # Remove generated code
rake clobber:app # Remove generated Rails app
rake cucumber # Run Cucumber features
rake gem:build # Builds the gem from the gemspec
rake gem:install # Installs the built gem
rake generate:app # Generate Rails app for integ tests
rake generate:custom # Generate scaffolds, etc
rake init # Set up gem, runs the specs and cukes
rake setup # Sets up the environment for cukes
rake spec # Run specs
rake spec_with_rcov # Run specs with rcov
71. RUBYGEMS 101
MATT YOHO
Permissive Licenses
Copyright (c) 2004-2010 David Heinemeier Hansson
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
72. RUBYGEMS 101
MATT YOHO
The DWTFYWTPL
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. You just DO WHAT THE FUCK YOU WANT TO.
73. RUBYGEMS 101
MATT YOHO
Matz and OSS
“There are various merits,
but for me the biggest is
freedom. I prefer the term
'free software' more than
open source.”
- Japan, Inc., August 2000
101. CUCARUBA! MATT YOHO
YO DAWG! I heard you like writing
features while you write features so we
put cukes in your cukes!
102. RUBYGEMS 101
MATT YOHO
~/projects/lib/tmp/aruba
103. RUBYGEMS 101
MATT YOHO
~/projects/lib/tmp/aruba
./tmp/aruba
rake
task
104. RUBYGEMS 101
MATT YOHO
~/projects/lib/tmp/aruba
templates ./tmp/aruba
rake
task
105. RUBYGEMS 101
MATT YOHO
Feature: Rails Controllers Can Make Assumptions
Scenario: controller invokes assume
Given a file named "app/controllers/widgets_controller.rb" with:
"""
class WidgetsController < ApplicationController
assume(:widget) { Widget.find(params[:id]) }
end
"""
And a file named "app/views/widgets/show.html.erb" with:
"""
<blink><%= widget.name %></blink>
"""
And a file named "features/widget_is_viewed_by_visitor.feature" with:
"""
Feature: Widget is viewed by visitor
Scenario: success
Given a widget named "foobar"
When I view the widget
Then I should see "foobar"
"""
When I run "cucumber features/widget_is_viewed_by_visitor.feature"
Then I should see:
"""
1 scenario (1 passed)
3 steps
"""
106. RUBYGEMS 101
MATT YOHO
Feature: Foo Does Something
Scenario: foo works
Given a file named "foo.feature" with:
"""
Feature: Widget is viewed by visitor
Scenario: success
Given a foo named "bar"
When I view the foo
Then I should see "bar"
"""
When I run "cucumber foo.feature"
Then I should see:
"""
1 scenario (1 passed)
1 step
"""
107. RUBYGEMS 101
MATT YOHO
A little slow, but totally badass.