Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Build a Ruby Gem

Build a Ruby Gem

This deck covers the basics of getting started contributing to OSS and building a Ruby Gem. It goes a long with my Book, Build a Ruby gem (http://brandonhilkert.com/books/build-a-ruby-gem/).

Brandon Hilkert

March 11, 2014
Tweet

More Decks by Brandon Hilkert

Other Decks in Technology

Transcript

  1. My Background 2009 - Started Ruby/Rails 2010 - Wrote first

    gem 2011 - Contributed to Sidekiq 2013 - Sucker Punch 2014 - Book
  2. 1 - Introduction 2 - Structure 3 - Testing 4

    - Code 5 - Release 6 - Versioning 7 - Changelog 8 - Responsibility 9 - Loading 10 - Command-line Utilities ! 11 - Configuration Patterns 12 - Rails Hooks 13 - Rails View Helpers 14 - Rails Controller Includes 15 - Rails Model Includes 16 - Rails Rake Tasks 17 - Rails Generators 18 - Rails Engines 19 - Open Source Management 20 - Summary Chapter list
  3. class MegaLotto NUMBERS = 5 def draw NUMBERS.times.map do single_draw

    end end def single_draw rand(0…60) end end Codebase
  4. getting started $ bundle help ... bundle gem(1) Create a

    simple gem, suitable for development with bundler ... ! $ bundle gem mega_lotto
  5. getting started . "## Gemfile "## LICENSE.txt "## README.md "##

    Rakefile "## lib $ "## mega_lotto $ $ &## version.rb $ &## mega_lotto.rb &## mega_lotto.gemspec 
 2 directories, 7 files Main dir. Entry file Gemspec
  6. spec.files = `git ls-files`.split($/) spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f)

    } spec.test_files = spec.files.grep(%r{^(test|spec|features)/}) spec.require_paths = ["lib"] gemspec
  7. # Rakefile require "bundler/gem_tasks" Rakefile $ rake -T rake build

    # Build mega_lotto-0.0.1.gem into the pkg directory rake install # Build and install mega_lotto-0.0.1.gem into system gems rake release # Create tag v0.0.1 and build and push mega_lotto-0.0.1.gem to Rubygem
  8. Release! $ rake release mega_lotto 0.0.1 built to pkg/mega_lotto-0.0.1.gem. Tagged

    v0.0.1. Pushed git commits and tags. Pushed mega_lotto 0.0.1 to rubygems.org.
  9. $ rake release mega_lotto 0.0.2 built to pkg/mega_lotto-0.0.2.gem. Tagged v0.0.2.

    Pushed git commits and tags. Pushed mega_lotto 0.0.2 to rubygems.org. Next Release # lib/mega_lotto/version.rb module MegaLotto VERSION = “0.0.2" # was “0.0.1” end
  10. How to get started Fix a bug in an existing

    gem because it affects you 1 Improve an existing gem to learn more 2 Create new gem by extracting code 3