SlideShare a Scribd company logo
1 of 40
Download to read offline
LET'S MAKE A GEM
WHAT IS A GEM?
LET'S MAKE A GEM
1. Creating a Gem with Bundler
LET'S MAKE A GEM
1. Creating a Gem with Bundler
2. Testing it with rspec
LET'S MAKE A GEM
1. Creating a Gem with Bundler
2. Testing it with rspec
3. Setting up continuous integration
LET'S MAKE A GEM
1. Creating a Gem with Bundler
2. Testing it with rspec
3. Setting up continuous integration
4. Publishing to Rubygems
LET'S MAKE A GEM
1. Creating a Gem with Bundler
2. Testing it with rspec
3. Setting up continuous integration
4. Publishing to Rubygems
5. Publishing to a private gem server
1. Creating a Gem
RVM
BUNDLER
RUBYGEMS
INITIALIZING OUR GEM
$ rvm use 2.1.0
$ gem install bundler
$ bundle gem eleventh
$ cd eleventh
$ rvm --rvmrc --create 2.1.0@eleventh
$ cd ..; cd -
GENERATED STRUCTURE
$ ls
eleventh
|--- README.md
|--- eleventh.gemspec
|--- Rakefile
|--- Gemfile
|--- lib
|--- eleventh.rb
|--- eleventh
|--- version.rb
EXPLORING THE GENERATED STRUCTURE
$ vim eleventh.gemspec
$ vim Gemfile
$ vim lib/eleventh.rb
$ vim lib/eleventh/version.rb
$ rake -T
MAKE IT DO SOMETHING
$ vim lib/eleventh/array_access.rb
$ vim lib/eleventh.rb
$ git add .
$ git commit -m "Version 1"
MAKE IT DO SOMETHING
# ./lib/eleventh/array_access.rb
class Array
def eleventh
self[10]
end
end
# ./lib/eleventh.rb
require "eleventh/version"
require "eleventh/array_access"
module Eleventh
end
2. Testing our gem with rspec
TESTING OUR GEM
$ mkdir spec
$ vim spec/spec_helper.rb
$ vim spec/array_access_spec.rb
$ rspec spec/array_access.rb
TESTING OUR GEM
# ./spec/spec_helper.rb
require 'rubygems'
require 'bundler/setup'
Bundler.setup
require 'eleventh'
RSpec.configure do |config|
end
TESTING OUR GEM
# ./spec/array_access.rb
require 'spec_helper'
describe Array do
describe '#eleventh' do
it 'should return the eleventh element' do
arr = (1..15).to_a
arr.eleventh.should eq(11)
end
it 'should return nil if the eleventh element not not exist' do
arr = (1..9).to_a
arr.eleventh.should eq(nil)
end
end
end
TESTING OUR GEM
$ rspec spec/array_access.rb
..
Finished in 0.00135 seconds
2 examples, 0 failures
TESTING OUR GEM
$ vim Rakefile
# ./Rakefile
require "bundler/gem_tasks"
require 'rspec/core/rake_task'
RSpec::Core::RakeTask.new('spec')
task :default => :spec
TESTING OUR GEM
$ rake
/Users/bmorris/.rvm/rubies/ruby-2.1.0-p247/bin/ruby -S rspec ./spec/array_access_spec.rb
..
Finished in 0.00066 seconds
2 examples, 0 failures
3. Setting up continuous integration
JENKINS
CIRCLE CI
TRAVIS CI
SETTING UP CONTINUOUS INTEGRATION
$ vim travis.yml
$ vim eleventh.gemspec
$ vim README.md
$ vim git commit -m "Setting up Travis CI"
$ git push
SETTING UP CONTINUOUS INTEGRATION
# ./travis.yml
language: ruby
rvm:
- 2.1.0
4. Publishing to Rubygems
PUBLISHING TO RUBYGEMS
$ rake -T
$ rake release
$ gem build eleventh.gemspec
$ gem push eleventh-0.0.1.gem
$ open rubygems.org
TA-DA!
REMOVING THE GEM
$ gem yank eleventh -v 0.0.1
5. Publishing to a private gem server
WHY PRIVATE?
GITHUB
GEMINABOX
GEMFURY
PUBLISHING TO GEMFURY
$ gem install gemfury
$ gem build eleventh.gemspec
$ fury push eleventh-0.0.1.gem
$ git remote add fury https://bnmrrs@git.fury.io/bnmrrs/eleventh.git
$ git push fury master
PUBLISHING TO GEMFURY
$ cd ../other-project
$ vim Gemfile
# ../other-project/Gemfile
source 'https://TOKEN@gem.fury.io/bnmrrs/'
$ bundle install
PUBLISHING A NEW VERSION
$ vim lib/eleventh/version.rb
$ gem build eleventh.gemspec
$ git add .
$ git commit -m "Version 2"
$ fury push eleventh-0.0.2.gem
$ fury list
QUESTIONS?
@bnmrrs
www.boltmade.com
https://github.com/bnmrrs/talks

More Related Content

What's hot

Resources and providers chef conf 2013
Resources and providers chef conf 2013Resources and providers chef conf 2013
Resources and providers chef conf 2013
rosekolodny
 
JavaScript Sprachraum
JavaScript SprachraumJavaScript Sprachraum
JavaScript Sprachraum
patricklee
 

What's hot (19)

Resources and providers chef conf 2013
Resources and providers chef conf 2013Resources and providers chef conf 2013
Resources and providers chef conf 2013
 
JavaScript Sprachraum
JavaScript SprachraumJavaScript Sprachraum
JavaScript Sprachraum
 
Socket.io
Socket.ioSocket.io
Socket.io
 
No Callbacks, No Threads - RailsConf 2010
No Callbacks, No Threads - RailsConf 2010No Callbacks, No Threads - RailsConf 2010
No Callbacks, No Threads - RailsConf 2010
 
Capistrano - automate all the things
Capistrano - automate all the thingsCapistrano - automate all the things
Capistrano - automate all the things
 
Deploying Rails Apps with Chef and Capistrano
 Deploying Rails Apps with Chef and Capistrano Deploying Rails Apps with Chef and Capistrano
Deploying Rails Apps with Chef and Capistrano
 
email delivery
email deliveryemail delivery
email delivery
 
Capistrano
CapistranoCapistrano
Capistrano
 
Ruby Concurrency and EventMachine
Ruby Concurrency and EventMachineRuby Concurrency and EventMachine
Ruby Concurrency and EventMachine
 
Socket.io (part 1)
Socket.io (part 1)Socket.io (part 1)
Socket.io (part 1)
 
Elastic search
Elastic searchElastic search
Elastic search
 
Nevermore Unit Testing
Nevermore Unit TestingNevermore Unit Testing
Nevermore Unit Testing
 
Going real time with Socket.io
Going real time with Socket.ioGoing real time with Socket.io
Going real time with Socket.io
 
Socket.io under the hood
Socket.io under the hoodSocket.io under the hood
Socket.io under the hood
 
Sinatra
SinatraSinatra
Sinatra
 
Mage Titans USA 2016 - Miguel Balparda - Magento 2: Premium Performance with ...
Mage Titans USA 2016 - Miguel Balparda - Magento 2: Premium Performance with ...Mage Titans USA 2016 - Miguel Balparda - Magento 2: Premium Performance with ...
Mage Titans USA 2016 - Miguel Balparda - Magento 2: Premium Performance with ...
 
What Is Async, How Does It Work, And When Should I Use It?
What Is Async, How Does It Work, And When Should I Use It?What Is Async, How Does It Work, And When Should I Use It?
What Is Async, How Does It Work, And When Should I Use It?
 
Getting Started with Capistrano
Getting Started with CapistranoGetting Started with Capistrano
Getting Started with Capistrano
 
bivou.ac
bivou.acbivou.ac
bivou.ac
 

Similar to Let's Make a Gem

Migrating Legacy Rails Apps to Rails 3
Migrating Legacy Rails Apps to Rails 3Migrating Legacy Rails Apps to Rails 3
Migrating Legacy Rails Apps to Rails 3
Clinton Dreisbach
 

Similar to Let's Make a Gem (20)

Gem That (2009)
Gem That (2009)Gem That (2009)
Gem That (2009)
 
The Future of Dependency Management for Ruby
The Future of Dependency Management for RubyThe Future of Dependency Management for Ruby
The Future of Dependency Management for Ruby
 
Rocket Fuelled Cucumbers
Rocket Fuelled CucumbersRocket Fuelled Cucumbers
Rocket Fuelled Cucumbers
 
RVM, Bundler and Ruby Tracker
RVM, Bundler and Ruby TrackerRVM, Bundler and Ruby Tracker
RVM, Bundler and Ruby Tracker
 
Ruby gemsパッケージの作り方
Ruby gemsパッケージの作り方Ruby gemsパッケージの作り方
Ruby gemsパッケージの作り方
 
Perl Sucks - and what to do about it
Perl Sucks - and what to do about itPerl Sucks - and what to do about it
Perl Sucks - and what to do about it
 
Unit Testing Lots of Perl
Unit Testing Lots of PerlUnit Testing Lots of Perl
Unit Testing Lots of Perl
 
Open Source Saturday - How can I contribute to Ruby on Rails?
Open Source Saturday - How can I contribute to Ruby on Rails?Open Source Saturday - How can I contribute to Ruby on Rails?
Open Source Saturday - How can I contribute to Ruby on Rails?
 
Practical Testing of Ruby Core
Practical Testing of Ruby CorePractical Testing of Ruby Core
Practical Testing of Ruby Core
 
Autotesting rails app
Autotesting rails appAutotesting rails app
Autotesting rails app
 
Laravel Day / Deploy
Laravel Day / DeployLaravel Day / Deploy
Laravel Day / Deploy
 
Babushka
BabushkaBabushka
Babushka
 
perlall
perlallperlall
perlall
 
#CNX14 - Using Ruby for Reliability, Consistency, and Speed
#CNX14 - Using Ruby for Reliability, Consistency, and Speed#CNX14 - Using Ruby for Reliability, Consistency, and Speed
#CNX14 - Using Ruby for Reliability, Consistency, and Speed
 
Migrating Legacy Rails Apps to Rails 3
Migrating Legacy Rails Apps to Rails 3Migrating Legacy Rails Apps to Rails 3
Migrating Legacy Rails Apps to Rails 3
 
Extracting ruby gem
Extracting ruby gemExtracting ruby gem
Extracting ruby gem
 
Creating Ruby Gems
Creating Ruby Gems Creating Ruby Gems
Creating Ruby Gems
 
Redmine on amazon ec2
Redmine on amazon ec2Redmine on amazon ec2
Redmine on amazon ec2
 
Infrastructure as code - Python Saati #36
Infrastructure as code - Python Saati #36Infrastructure as code - Python Saati #36
Infrastructure as code - Python Saati #36
 
Serializing Ruby Objects in Redis
Serializing Ruby Objects in RedisSerializing Ruby Objects in Redis
Serializing Ruby Objects in Redis
 

Recently uploaded

Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Medical / Health Care (+971588192166) Mifepristone and Misoprostol tablets 200mg
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
VictorSzoltysek
 

Recently uploaded (20)

W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand
 
Architecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastArchitecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the past
 
Harnessing ChatGPT - Elevating Productivity in Today's Agile Environment
Harnessing ChatGPT  - Elevating Productivity in Today's Agile EnvironmentHarnessing ChatGPT  - Elevating Productivity in Today's Agile Environment
Harnessing ChatGPT - Elevating Productivity in Today's Agile Environment
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students
 
WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
 
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
 
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
 
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionIntroducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
 
WSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With SimplicityWSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
 
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
 

Let's Make a Gem

  • 2. WHAT IS A GEM?
  • 3. LET'S MAKE A GEM 1. Creating a Gem with Bundler
  • 4. LET'S MAKE A GEM 1. Creating a Gem with Bundler 2. Testing it with rspec
  • 5. LET'S MAKE A GEM 1. Creating a Gem with Bundler 2. Testing it with rspec 3. Setting up continuous integration
  • 6. LET'S MAKE A GEM 1. Creating a Gem with Bundler 2. Testing it with rspec 3. Setting up continuous integration 4. Publishing to Rubygems
  • 7. LET'S MAKE A GEM 1. Creating a Gem with Bundler 2. Testing it with rspec 3. Setting up continuous integration 4. Publishing to Rubygems 5. Publishing to a private gem server
  • 10. INITIALIZING OUR GEM $ rvm use 2.1.0 $ gem install bundler $ bundle gem eleventh $ cd eleventh $ rvm --rvmrc --create 2.1.0@eleventh $ cd ..; cd -
  • 11. GENERATED STRUCTURE $ ls eleventh |--- README.md |--- eleventh.gemspec |--- Rakefile |--- Gemfile |--- lib |--- eleventh.rb |--- eleventh |--- version.rb
  • 12. EXPLORING THE GENERATED STRUCTURE $ vim eleventh.gemspec $ vim Gemfile $ vim lib/eleventh.rb $ vim lib/eleventh/version.rb $ rake -T
  • 13. MAKE IT DO SOMETHING $ vim lib/eleventh/array_access.rb $ vim lib/eleventh.rb $ git add . $ git commit -m "Version 1"
  • 14. MAKE IT DO SOMETHING # ./lib/eleventh/array_access.rb class Array def eleventh self[10] end end # ./lib/eleventh.rb require "eleventh/version" require "eleventh/array_access" module Eleventh end
  • 15. 2. Testing our gem with rspec
  • 16. TESTING OUR GEM $ mkdir spec $ vim spec/spec_helper.rb $ vim spec/array_access_spec.rb $ rspec spec/array_access.rb
  • 17. TESTING OUR GEM # ./spec/spec_helper.rb require 'rubygems' require 'bundler/setup' Bundler.setup require 'eleventh' RSpec.configure do |config| end
  • 18. TESTING OUR GEM # ./spec/array_access.rb require 'spec_helper' describe Array do describe '#eleventh' do it 'should return the eleventh element' do arr = (1..15).to_a arr.eleventh.should eq(11) end it 'should return nil if the eleventh element not not exist' do arr = (1..9).to_a arr.eleventh.should eq(nil) end end end
  • 19. TESTING OUR GEM $ rspec spec/array_access.rb .. Finished in 0.00135 seconds 2 examples, 0 failures
  • 20. TESTING OUR GEM $ vim Rakefile # ./Rakefile require "bundler/gem_tasks" require 'rspec/core/rake_task' RSpec::Core::RakeTask.new('spec') task :default => :spec
  • 21. TESTING OUR GEM $ rake /Users/bmorris/.rvm/rubies/ruby-2.1.0-p247/bin/ruby -S rspec ./spec/array_access_spec.rb .. Finished in 0.00066 seconds 2 examples, 0 failures
  • 22. 3. Setting up continuous integration
  • 26. SETTING UP CONTINUOUS INTEGRATION $ vim travis.yml $ vim eleventh.gemspec $ vim README.md $ vim git commit -m "Setting up Travis CI" $ git push
  • 27. SETTING UP CONTINUOUS INTEGRATION # ./travis.yml language: ruby rvm: - 2.1.0
  • 28. 4. Publishing to Rubygems
  • 29. PUBLISHING TO RUBYGEMS $ rake -T $ rake release $ gem build eleventh.gemspec $ gem push eleventh-0.0.1.gem $ open rubygems.org
  • 31. REMOVING THE GEM $ gem yank eleventh -v 0.0.1
  • 32. 5. Publishing to a private gem server
  • 37. PUBLISHING TO GEMFURY $ gem install gemfury $ gem build eleventh.gemspec $ fury push eleventh-0.0.1.gem $ git remote add fury https://bnmrrs@git.fury.io/bnmrrs/eleventh.git $ git push fury master
  • 38. PUBLISHING TO GEMFURY $ cd ../other-project $ vim Gemfile # ../other-project/Gemfile source 'https://TOKEN@gem.fury.io/bnmrrs/' $ bundle install
  • 39. PUBLISHING A NEW VERSION $ vim lib/eleventh/version.rb $ gem build eleventh.gemspec $ git add . $ git commit -m "Version 2" $ fury push eleventh-0.0.2.gem $ fury list