Extracting ruby gem

2,556 views

Published on

Create ruby gem step by step with bundler

Published in: Self Improvement, Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
2,556
On SlideShare
0
From Embeds
0
Number of Embeds
4
Actions
Shares
0
Downloads
14
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Extracting ruby gem

  1. 1. Yura TolstikRuby/Rails developer at Altoros Development t witter: @yltsrc email: yltsrc@gmail.com
  2. 2. Extracting ruby gem Why? Reusable code Easy to install Easy to share
  3. 3. Lets start Find code duplicationsWrite tests if not exists Ready?
  4. 4. How to create creating a gemspecification file(mygem.gemspec) bundle gem mygem and do all things by hand...
  5. 5. By hand?
  6. 6. mygem.gemspecGem::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
  7. 7. spec_helper.rb$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), .., lib))$LOAD_PATH.unshift(File.dirname(__FILE__))require rspecrequire newgemRSpec.configure do |config| # if neededend
  8. 8. Extract testsdescribe "Mygem" do describe "#hello" do it "should return Hello world!" do @base = "" @base.extend(Mygem::Base) @base.hello.should eql("Hello world!") end endend
  9. 9. Extract methodsmodule Mygem module Base def hello "Hello #{self.empty? ? world : self}!" end endend
  10. 10. Rakefilerequire "bundler/gem_tasks"require rspec/corerequire rspec/core/rake_taskRSpec::Core::RakeTask.new(:spec) do |spec| spec.pattern = FileList[spec/**/*_spec.rb]endtask :default => :spec
  11. 11. Testrake spec
  12. 12. Build rake build orgem build mygem.gemspec
  13. 13. Publish rake release orgem push mygem-0.0.1.gem
  14. 14. My own gem server gem help generate_index gem help server
  15. 15. Questions http://gembundler.com/rubygems.htmlhttp://docs.rubygems.org/read/chapter/20

×