SlideShare a Scribd company logo
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

More Related Content

KEY
Rails3勘所
PPTX
Word Play in the Digital Age: Building Text Bots with Tracery
PPTX
Getting Started with Microsoft Bot Framework
ZIP
Sphinx on Rails
PDF
HappyKardashian.com for #FVCP
PDF
ECMAScript 6
PDF
Mojolicious: what works and what doesn't
PDF
AddressBook.swift
Rails3勘所
Word Play in the Digital Age: Building Text Bots with Tracery
Getting Started with Microsoft Bot Framework
Sphinx on Rails
HappyKardashian.com for #FVCP
ECMAScript 6
Mojolicious: what works and what doesn't
AddressBook.swift

What's hot (20)

PDF
YAPC::Asia 2010 Twitter解析サービス
PDF
Mojolicious
PDF
Inside Bokete: Web Application with Mojolicious and others
PDF
エロサイト管理者の憂鬱3 - Hokkaiodo.pm#4 -
KEY
Mojo as a_client
PDF
Asynchronous programming patterns in Perl
PDF
Twib in Yokoahma.pm 2010/3/5
PPTX
Mojolicious - Perl Framework for the Real-Time Web (Lightning Talk)
PDF
A piece of sugar in your client-side development
PDF
Absolute Beginners Guide to Puppet Through Types - PuppetConf 2014
PDF
RESTful web services
PDF
Intro to Rails
PDF
Découplez votre appli en micro-APIs
KEY
Keeping it small: Getting to know the Slim micro framework
PDF
Mojolicious, real-time web framework
PDF
JavaScript OOP Pattern
PDF
Sinatra slideshare
PDF
Advanced fun with Objective-C runtime.
PDF
A Gentle Introduction to Event Loops
PPTX
YAPC::Asia 2010 Twitter解析サービス
Mojolicious
Inside Bokete: Web Application with Mojolicious and others
エロサイト管理者の憂鬱3 - Hokkaiodo.pm#4 -
Mojo as a_client
Asynchronous programming patterns in Perl
Twib in Yokoahma.pm 2010/3/5
Mojolicious - Perl Framework for the Real-Time Web (Lightning Talk)
A piece of sugar in your client-side development
Absolute Beginners Guide to Puppet Through Types - PuppetConf 2014
RESTful web services
Intro to Rails
Découplez votre appli en micro-APIs
Keeping it small: Getting to know the Slim micro framework
Mojolicious, real-time web framework
JavaScript OOP Pattern
Sinatra slideshare
Advanced fun with Objective-C runtime.
A Gentle Introduction to Event Loops
Ad

Viewers also liked (17)

PPTX
Edu 290 ppt 1
PDF
Mpeg Advisor Presentation Power Point[1]
PPTX
KulturA Benedenwinds
PPTX
DTC Lab Kickoff Intro
PPTX
LaunchPad Framework Module
PDF
1 examen et corrige his geo 2012 1-am t1
PPTX
Pptppom 111011111708-phpapp01
PPTX
Integral
PDF
3 examen et corrige arabe 2014 1 am t1
RTF
Ko'galo After Party
PDF
11 compo
PDF
DOC3 - Soft Drinks and Beer 4 MI
ODP
United World Project
PDF
Internet product-of-foss
PPTX
Positive thinking
PDF
Session 6 - Poll
PPTX
trabajo 23/09/11
Edu 290 ppt 1
Mpeg Advisor Presentation Power Point[1]
KulturA Benedenwinds
DTC Lab Kickoff Intro
LaunchPad Framework Module
1 examen et corrige his geo 2012 1-am t1
Pptppom 111011111708-phpapp01
Integral
3 examen et corrige arabe 2014 1 am t1
Ko'galo After Party
11 compo
DOC3 - Soft Drinks and Beer 4 MI
United World Project
Internet product-of-foss
Positive thinking
Session 6 - Poll
trabajo 23/09/11
Ad

Similar to Extracting ruby gem (20)

PDF
All I Need to Know I Learned by Writing My Own Web Framework
KEY
A tour on ruby and friends
PDF
Building web framework with Rack
PDF
Great Developers Steal
PDF
Ruby Isn't Just About Rails
PDF
Hacking with ruby2ruby
PDF
JRuby + Rails = Awesome Java Web Framework at Jfokus 2011
PDF
Play vs Rails
PDF
Migrating Legacy Rails Apps to Rails 3
PDF
TDC 2012 - Patterns e Anti-Patterns em Ruby
PDF
Metaprogramovanie #1
PDF
Adventurous Merb
PDF
Ruby on Rails - Introduction
PDF
Gem That (2009)
PDF
Ruby 入門 第一次就上手
PDF
Practical Testing of Ruby Core
PPTX
Rails Engine | Modular application
PDF
Introduction to Rails - presented by Arman Ortega
PDF
Buildr In Action @devoxx france 2012
PPTX
ES6 is Nigh
All I Need to Know I Learned by Writing My Own Web Framework
A tour on ruby and friends
Building web framework with Rack
Great Developers Steal
Ruby Isn't Just About Rails
Hacking with ruby2ruby
JRuby + Rails = Awesome Java Web Framework at Jfokus 2011
Play vs Rails
Migrating Legacy Rails Apps to Rails 3
TDC 2012 - Patterns e Anti-Patterns em Ruby
Metaprogramovanie #1
Adventurous Merb
Ruby on Rails - Introduction
Gem That (2009)
Ruby 入門 第一次就上手
Practical Testing of Ruby Core
Rails Engine | Modular application
Introduction to Rails - presented by Arman Ortega
Buildr In Action @devoxx france 2012
ES6 is Nigh

Recently uploaded (20)

PPTX
Emotional Intelligence- Importance and Applicability
PPTX
Learn how to prevent Workplace Incidents?
PDF
The Power of Pausing Before You React by Meenakshi Khakat
PDF
Red Light Wali Muskurahat – A Heart-touching Hindi Story
PPTX
How to Deal with Imposter Syndrome for Personality Development?
PPTX
Travel mania in india needs to change the world
PDF
Quiet Wins: Why the Silent Fish Survives.pdf
PPTX
Pradeep Kumar Roll no.30 Paper I.pptx....
PPTX
Personal Development - By Knowing Oneself?
PPTX
Attitudes presentation for psychology.pptx
PPTX
SELF ASSESSMENT -SNAPSHOT.pptx an index of yourself by Dr NIKITA SHARMA
PDF
Elle Lalli on The Role of Emotional Intelligence in Entrepreneurship
PPTX
Chapter-7-The-Spiritual-Self-.pptx-First
PPTX
Commmunication in Todays world- Principles and Barriers
PPTX
Learn numerology content and join tarot reading
PPTX
cấu trúc sử dụng mẫu Cause - Effects.pptx
PPTX
Understanding the Self power point presentation
PPTX
Presentation on interview preparation.pt
PDF
⚡ Prepping for grid failure_ 6 Must-Haves to Survive Blackout!.pdf
PPTX
Learn how to use Portable Grinders Safely
Emotional Intelligence- Importance and Applicability
Learn how to prevent Workplace Incidents?
The Power of Pausing Before You React by Meenakshi Khakat
Red Light Wali Muskurahat – A Heart-touching Hindi Story
How to Deal with Imposter Syndrome for Personality Development?
Travel mania in india needs to change the world
Quiet Wins: Why the Silent Fish Survives.pdf
Pradeep Kumar Roll no.30 Paper I.pptx....
Personal Development - By Knowing Oneself?
Attitudes presentation for psychology.pptx
SELF ASSESSMENT -SNAPSHOT.pptx an index of yourself by Dr NIKITA SHARMA
Elle Lalli on The Role of Emotional Intelligence in Entrepreneurship
Chapter-7-The-Spiritual-Self-.pptx-First
Commmunication in Todays world- Principles and Barriers
Learn numerology content and join tarot reading
cấu trúc sử dụng mẫu Cause - Effects.pptx
Understanding the Self power point presentation
Presentation on interview preparation.pt
⚡ Prepping for grid failure_ 6 Must-Haves to Survive Blackout!.pdf
Learn how to use Portable Grinders Safely

Extracting ruby gem