Yura Tolstik
Ruby/Rails developer at Altoros Development

            t witter: @yltsrc
         email: yltsrc@gmail.com
Extracting ruby gem

          Why?

      Reusable code
      Easy to install
      Easy to share
Lets start

 Find code duplications
Write tests if not exists

        Ready?
How to create

  creating a gem
specification file
(mygem.gemspec)      bundle gem mygem
 and do all things
     by hand...
By hand?
mygem.gemspec
Gem::Specification.new do |s|
  s.name        = "mygem"
  s.version     = Mygem::VERSION
  s.authors     = ["Yura Tolstik"]
  s.email       = ["yltsrc@gmail.com"]
  s.homepage    = "http://github.com/yltsrc/mygem"
  s.summary     = %q{My first gem}
  s.description = %q{Create ruby gem step by step with bundler}
  s.license     = "MIT"

  s.files         = `git ls-files`.split("n")
  s.test_files    = `git ls-files -- spec/*`.split("n")
  s.require_paths = ["lib"]
  s.add_development_dependency "rake"
  s.add_development_dependency "rspec"
end
spec_helper.rb

$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
$LOAD_PATH.unshift(File.dirname(__FILE__))
require 'rspec'
require 'newgem'

RSpec.configure do |config|
  # if needed
end
Extract tests

describe "Mygem" do
  describe "#hello" do
    it "should return 'Hello world!'" do
      @base = ""
      @base.extend(Mygem::Base)
      @base.hello.should eql("Hello world!")
    end
  end
end
Extract methods

module Mygem
  module Base
    def hello
      "Hello #{self.empty? ? 'world' : self}!"
    end
  end
end
Rakefile

require "bundler/gem_tasks"

require 'rspec/core'
require 'rspec/core/rake_task'
RSpec::Core::RakeTask.new(:spec) do |spec|
  spec.pattern = FileList['spec/**/*_spec.rb']
end
task :default => :spec
Test


rake spec
Build
       rake build

          or

gem build mygem.gemspec
Publish
      rake release

           or

gem push mygem-0.0.1.gem
My own gem server

   gem help generate_index

       gem help server
Questions




  http://gembundler.com/rubygems.html
http://docs.rubygems.org/read/chapter/20

Extracting ruby gem