RubyGems - A quick intro

RubyGems - A quick intro

A quick introduction to making your own RubyGems.

8d7c0c3b32899cccf8d0abb080a18c20?s=128

Peter Hellberg

November 24, 2011
Tweet

Transcript

  1. A QUICK INTRO RubyGems

  2. @peterhellberg

  3. I’m a Senior Systems Architect at Athega (where I build

    stuff in Ruby) ⃔ I’m also the owner o Code7 Interactive (where I build stuff in Ruby) ⃕
  4. Gem::Specification.new do |s| # The attributes end Gem Speci ication

    In order to create a gem, you need to define a gem specification, commonly called a “gemspec”.
  5. Required gemspec attributes name This gem’s name summary A short

    summary of this gem’s description. Displayed in `gem list -d`. version This gem’s version s.required_ruby_version = ">= 1.8.7" Required Ruby Version
  6. Name, Summary and Version s.name = "pinch" s.summary = "Retrieve

    a file from" + "inside a zip file, over" + "the network!" s.version = Pinch::VERSION I generally add a ProjectName::VERSION constant to all of my projects, this makes it easy to show the current version at runtime.
  7. s.email = "peter@c7.se" s.homepage = "http://peterhellberg.github.com/pinch/" s.authors = ["Peter Hellberg",

    "Edward Patel"] s.license = "MIT-LICENSE" About
  8. s.files = Dir.glob("lib/**/*") + %w(MIT-LICENSE README.rdoc Rakefile .gemtest) Files s.test_file

    = "spec/pinch_spec.rb" Testing
  9. s.has_rdoc = true s.rdoc_options = [ '--main', 'README.rdoc', '--charset=UTF-8' ]

    s.extra_rdoc_files = [ 'README.rdoc', 'MIT-LICENSE' ] Documentation
  10. s.add_development_dependency 'yard', '~> 0.7' s.add_development_dependency 'minitest','~> 2.8' s.add_development_dependency 'fakeweb', '~>

    1.3' s.add_development_dependency 'vcr', '~> 1.11' Dependencies No runtime dependencies in this particular project, otherwise I’d need a few calls to s.add_dependency
  11. Write some well tested code

  12. Publishing your gem to the world!

  13. $ gem build pinch.gemspec Building $ gem push pinch-0.2.1.gem Pushing

    http://guides.rubygems.org/command-reference/
  14. guides.rubygems.org/make-your-own-gem Learn more

  15. @peterhellberg peterhellberg.info git.io/peterhellberg