Professional Documents
Culture Documents
R B Y
Nick Quaranto
@qrush nick@thoughtbot.com
Wednesday, May 25, 2011
first, a
P S A
Wednesday, May 25, 2011
Where have all of
the manuals gone?
G E M
Wednesday, May 25, 2011
Gems contain a
packaged Ruby
application or library.
gems
gems
.gem Rails
D Y I
Wednesday, May 25, 2011
share/modularize code
automate your process
releasing a gem is easy!
% tree
.
├── hola.gemspec
└── lib
└── hola.rb
Wednesday, May 25, 2011
% cat hola.gemspec
Gem::Specification.new do |s|
s.name = 'hola'
s.version = '0.0.0'
s.date = '2010-04-28'
s.summary = "Hola!"
s.description = "A simple hello world gem"
s.authors = ["Nick Quaranto"]
s.email = 'nick@quaran.to'
s.files = ["lib/hola.rb"]
s.homepage =
'http://rubygems.org/gems/hola'
end
install
push
Wednesday, May 25, 2011
build
LOCAL
install
push
Wednesday, May 25, 2011
build
LOCAL
install
REMOTE
push
Wednesday, May 25, 2011
% gem build hola.gemspec
Successfully built RubyGem
Name: hola
Version: 0.0.0
File: hola-0.0.0.gem
% irb -rubygems
>> require 'hola'
=> true
>> Hola.hi
Hello world!
LOCAL
install
push
REMOTE
install list -r
Wednesday, May 25, 2011
% gem list -r hola
hola (0.0.0)
executable
require 'hola'
puts Hola.hi(ARGV[0])
% cat bin/hola
#!/usr/bin/env ruby
require 'hola'
puts Hola.hi(ARGV[0])
% cat bin/hola
#!/usr/bin/env ruby
require 'hola'
puts Hola.hi(ARGV[0])
“Probably derived from “shell bang” under the influence of
American slang “the whole shebang” (everything, the works)”
http://www.retrologic.com/jargon/S/shebang.html
Wednesday, May 25, 2011
(shə-băng')
% cat bin/hola
#!/usr/bin/env ruby
require 'hola'
puts Hola.hi(ARGV[0])
“Probably derived from “shell bang” under the influence of
American slang “the whole shebang” (everything, the works)”
http://www.retrologic.com/jargon/S/shebang.html
Wednesday, May 25, 2011
% ruby -Ilib ./bin/hola
Hello world!
% hola Baltimore
Hello Baltimore!
executable
tests
rake
thor
Wednesday, May 25, 2011
automation framework
Test::Unit rspec
rake bacon context
matchy shoulda
riot testy shindo
thor zebra lemon dfect
cucumber steak
Wednesday, May 25, 2011
Test your gem.
Use whatever.
Please test it.
Rake::TestTask.new do |t|
t.libs << 'test'
end
def test_custom_hello
assert_equal "Hello Boston!",
Hola.hi("Boston")
end
end
Wednesday, May 25, 2011
% rake test
(in /Users/qrush/Dev/ruby/hola)
Loaded suite
Started
..
Finished in 0.000736 seconds.
executable
tests
docs
Wednesday, May 25, 2011
Others will use your gem.
Write about it.
nokogiri
yard
Wednesday, May 25, 2011
guides inline
nokogiri rails
yard datamapper
Wednesday, May 25, 2011
# The main Hola driver
class Hola
# Say hi to the world!
#
# Example:
# >> Hola.hi("Buffalo")
# => Hello Buffalo!
#
# Arguments:
# message: (String)
P T N
Wednesday, May 25, 2011
more files
require ‘set’
Wednesday, May 25, 2011
.
└── lib
├── foo
│ └── cgi.rb
├── foo.rb
└── set.rb
require ‘foo/cgi’
Wednesday, May 25, 2011
more files
semver
MAJOR.MINOR.PATCH
semver
dependencies
Exact
This one works for me!
Wednesday, May 25, 2011
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(
"rspec", [">= 2.2.0"])
Optimistic
Wednesday, May 25, 2011
It will always work!
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(
"rspec", [">= 2.2.0", "< 3.0.0"])
Pessimistic
This and future minor releases work
Wednesday, May 25, 2011
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(
"rspec", ["~> 2.2"])
Pessimistic
Use the twiddle-wakka!
Wednesday, May 25, 2011
releasing a gem
is easy!
T H X
http://guides.rubygems.org