SlideShare ist ein Scribd-Unternehmen logo
1 von 50
Downloaden Sie, um offline zu lesen
RubyGems and You


Josh Nichols      technicalpickles.com
Overview

      • How ‘require’ works
      • Where rubygems fits in
      • Creating your own rubygem from scratch
      • Creating your own rubygem using jeweler




Josh Nichols                                 technicalpickles.com
Overview

      • How ‘require’ works
      • Where rubygems fits in
      • Creating your own rubygem from scratch
      • Creating your own rubygem using jeweler




Josh Nichols                                 technicalpickles.com
require
               executes the contents of a file




Josh Nichols                             technicalpickles.com
# foo.rb
               puts quot;zomg, so awesomequot;

               # bar.rb
               require 'foo.rb'

               $ ruby bar.rb
               zomg, so awesome




Josh Nichols                         technicalpickles.com
require ‘/usr/lib/awesome.rb’
               absolute path




Josh Nichols                   technicalpickles.com
require ‘subdir/foo.rb’
                 relative path




Josh Nichols                     technicalpickles.com
require ‘subdir/foo’
                    can omit the .rb




Josh Nichols                           technicalpickles.com
$LOAD_PATH
         list of directories to look for required files




Josh Nichols                               technicalpickles.com
require ‘net/http’
         $LOAD_PATH includes your ruby install....
            this actually lives under a path like:
                   /usr/local/lib/ruby/1.8/




Josh Nichols                            technicalpickles.com
require
          only will execute a particular path once




Josh Nichols                             technicalpickles.com
# foo.rb
               puts quot;zomg, so awesomequot;

               # bar.rb
               require 'foo'
               require 'foo'
               require './foo'

               $ ruby bar.rb
               zomg, so awesome
               zomg, so awesome




Josh Nichols                             technicalpickles.com
Dealing with diversity...

      • Different environments (mac vs. win. vs. linux)
      • People install stuff to random places
      • Different versions of libraries
      • What do we do?




Josh Nichols                                     technicalpickles.com
MASS HYSTERIA!
Josh Nichols              technicalpickles.com
Overview

      • How ‘require’ works
      • Where rubygems fits in
      • Creating your own rubygem from scratch
      • Creating your own rubygem using jeweler




Josh Nichols                                 technicalpickles.com
Enter RubyGems

      • Handles downloading and installing library
      • Manages $LOAD_PATH
      • Allows a developer to package & distribute their library




Josh Nichols                                    technicalpickles.com
Installing

      • gem install burninator




Josh Nichols                            technicalpickles.com
Using gems



               require 'rubygems'
               require 'burninator'




Josh Nichols                    technicalpickles.com
Using gems in under Rails



        # config/environment.rb, or anywhere really
        require 'burninator'




Josh Nichols                             technicalpickles.com
Using gems in under Rails



                 # config/environment.rb
                 config.gem 'burninator'




Josh Nichols                         technicalpickles.com
Using gems in under Rails

  # create vendor/gems...
  # then 'gem unpack' gems there
  # config/environment.rb
  Rails::Initializer.run do |config|
    config.load_paths += Dir[quot;#{RAILS_ROOT}/vendor/gems/**quot;].map do |dir|
      File.directory?(lib = quot;#{dir}/libquot;) ? lib : dir
    end
  end




Josh Nichols                                       technicalpickles.com
Where do gems live?


Josh Nichols      technicalpickles.com
• RubyGems already knows about it by default
      • Has been the defacto standard for hosting




Josh Nichols                                 technicalpickles.com
• But you need to apply for projects...
      • And you need extra tools to publish gems...




Josh Nichols                                   technicalpickles.com
• The new hotness
      • Just create a repository and turn on RubyGem support
      • Create a Gem::Specification, and push it




Josh Nichols                                 technicalpickles.com
Overview

      • How ‘require’ works
      • Where rubygems fits in
      • Creating your own rubygem from scratch
      • Creating your own rubygem using jeweler




Josh Nichols                          technicalpickles.com
Tools of the trade

      • Rake for automation
      • Testing framework of choice (we’ll assume test/unit)
      • RubyGems




Josh Nichols                                   technicalpickles.com
Directory Layout
               |~bin/
               | `-cylon_detector
               |~lib/
               | `-cylon_detector.rb
               |~test/
               | |-test_cylon_detector.rb
               | `-test_helper.rb
               |-LICENSE
               |-Rakefile
               `-README.rdoc

Josh Nichols                           technicalpickles.com
Rakefile basics



               require 'rubygems'
               require 'rake'




Josh Nichols                        technicalpickles.com
Gem::Specification

      • Metadata about your gem
       • name, files, binaries, homepage, etc, etc




Josh Nichols                                        technicalpickles.com
Rakefile gemspec
         spec = Gem::Specification.new do |s|
           s.name = 'cylon-detector'
           s.version = '0.8.1'
           s.authors = ['Josh Nichols']
           s.date = '2009-02-03'
           s.email = 'josh@technicalpickles.com'
           s.files = FileList['{bin,lib}/**']
           s.executables = 'cylon_detector'
           s.has_rdoc = true
           s.summary = 'Detect cylons with ease'
         end




Josh Nichols                           technicalpickles.com
Rakefile gemspec


      task :gemspec do
        File.open('cylon-detector.gemspec', 'w') do |file|
          file.write spec.to_ruby
        end
      end




Josh Nichols                                technicalpickles.com
Rakefile package


               require 'rake/gempackagetask'
               Rake::GemPackageTask.new(spec) do |pkg|
                 pkg.need_zip = false
                 pkg.need_tar = false
               end




Josh Nichols                                  technicalpickles.com
Rakefile rdoc

       require 'rake/rdoctask'
       Rake::RDocTask.new do |rdoc|
         rdoc.rdoc_dir = 'rdoc'
         rdoc.title = 'cylon-detector'
         rdoc.options << '--line-numbers' << '--inline-source'
         rdoc.rdoc_files.include('README.rdoc')
         rdoc.rdoc_files.include('lib/**/*.rb')
       end




Josh Nichols                                    technicalpickles.com
Rakefile test


               require 'rake/testtask'
               Rake::TestTask.new(:test) do |t|
                 t.test_files = 'test/**/test_*.rb'
                 t.verbose = false
               end




Josh Nichols                                technicalpickles.com
Rakefile rcov

begin
  require 'rcov/rcovtask'
  Rcov::RcovTask.new do |t|
    t.test_files = 'test/**/test_*.rb'
    t.verbose = true
  end
rescue LoadError
  task :rcov do
    abort quot;RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcovquot;
  end
end




Josh Nichols                                                       technicalpickles.com
Rakefile default



               task :default => :test




Josh Nichols                            technicalpickles.com
bin/cylon_detector


    #!/usr/bin/env ruby

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

    # detection code here




Josh Nichols                                        technicalpickles.com
lib/cylon_detector.rb

      • The entry point into your library
      • Require all dependencies (internal and external)
      • Design decisions
       • generally want to namespace your project
       • class or module?
      • Do not require rubygems (unless you are interacting
       directly with it)



Josh Nichols                                  technicalpickles.com
test/test_helper.rb

      • Central location to setup testing environment
      require 'rubygems'
      require 'test/unit'

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

      require 'cylon_detector'

      class Test::Unit::TestCase
      end




Josh Nichols                                           technicalpickles.com
test/test_cylon_detector.rb


         require File.dirname(__FILE__) + '/test_helper'

         class CylonDetectorTest < Test::Unit::TestCase
           # tests go here
         end




Josh Nichols                                 technicalpickles.com
Workflow

      • Hack and commit your code
      • ‘rake gemspec’ and commit your gemspec
      • push to GitHub
      • wait for the gem to build
      • rejoice and have some Scotch




Josh Nichols                                technicalpickles.com
Overview

      • How ‘require’ works
      • Where rubygems fits in
      • Creating your own rubygem from scratch
      • Creating your own rubygem using jeweler




Josh Nichols                         technicalpickles.com
Jeweler

      • Handles the grunt work
      • Generator
       • Skeleton project setup for your test framework of choice
       • Starts a git repo setup for GitHub
       • Creates the repo on GitHub and enables RubyGem for it
      • Rake tasks
       • Automate version bumping
       • Releasing to GitHub, including tagging the release

Josh Nichols                                           technicalpickles.com
Generator

      • Choose between testing frameworks
       • Test::Unit
       • Shoulda
       • RSpec
       • Bacon
      • Also includes cucumber stories enabled for



Josh Nichols                                  technicalpickles.com
Versioning

      • Tracks current version in VERSION.yml
      • Rake tasks for bumping the version
       • version:bump:patch, version:bump:minor,
         version:bump:major




Josh Nichols                                 technicalpickles.com
0.8.5
                     patch version
               API backward-compatible
                       bug fixes
                minor enhancements



Josh Nichols                        technicalpickles.com
0.8.5
                        minor version
               mostly API backwards compatible
                more significant enhancements




Josh Nichols                            technicalpickles.com
0.8.5
                      major version
               break API as much you want
               usually signifies an overhaul




Josh Nichols                            technicalpickles.com
Releasing

      • Updates the gemspec based on the version
      • Pushes to GitHub
      • Tags the release with the version number




Josh Nichols                                 technicalpickles.com

Weitere ähnliche Inhalte

Ähnlich wie Rubygems And You

Open Source Saturday - How can I contribute to Ruby on Rails?
Open Source Saturday - How can I contribute to Ruby on Rails?Open Source Saturday - How can I contribute to Ruby on Rails?
Open Source Saturday - How can I contribute to Ruby on Rails?Pravin Mishra
 
Rocket Fuelled Cucumbers
Rocket Fuelled CucumbersRocket Fuelled Cucumbers
Rocket Fuelled CucumbersJoseph Wilk
 
Ruby on Rails 101 - Presentation Slides for a Five Day Introductory Course
Ruby on Rails 101 - Presentation Slides for a Five Day Introductory CourseRuby on Rails 101 - Presentation Slides for a Five Day Introductory Course
Ruby on Rails 101 - Presentation Slides for a Five Day Introductory Coursepeter_marklund
 
RubyConfBD 2013 decouple, bundle and share with ruby gems
RubyConfBD 2013   decouple, bundle and share with ruby gems RubyConfBD 2013   decouple, bundle and share with ruby gems
RubyConfBD 2013 decouple, bundle and share with ruby gems nhm taveer hossain khan
 
Crate Packaging Standalone Ruby Applications
Crate  Packaging Standalone Ruby ApplicationsCrate  Packaging Standalone Ruby Applications
Crate Packaging Standalone Ruby Applicationsrailsconf
 
Extracting Plugins And Gems From Rails Apps
Extracting Plugins And Gems From Rails AppsExtracting Plugins And Gems From Rails Apps
Extracting Plugins And Gems From Rails AppsJosh Nichols
 
Crate - ruby based standalone executables
Crate - ruby based standalone executablesCrate - ruby based standalone executables
Crate - ruby based standalone executablesJeremy Hinegardner
 
The Future of Bundled Bundler
The Future of Bundled BundlerThe Future of Bundled Bundler
The Future of Bundled BundlerHiroshi SHIBATA
 
The Architecture of PicCollage Server
The Architecture of PicCollage ServerThe Architecture of PicCollage Server
The Architecture of PicCollage ServerLin Jen-Shin
 
Simple Web Services With Sinatra and Heroku
Simple Web Services With Sinatra and HerokuSimple Web Services With Sinatra and Heroku
Simple Web Services With Sinatra and HerokuOisin Hurley
 
Node js quick-tour_v2
Node js quick-tour_v2Node js quick-tour_v2
Node js quick-tour_v2http403
 
Node js quick tour v2
Node js quick tour v2Node js quick tour v2
Node js quick tour v2Wyatt Fang
 
Node js quick-tour_v2
Node js quick-tour_v2Node js quick-tour_v2
Node js quick-tour_v2tianyi5212222
 
Ruby on-rails-101-presentation-slides-for-a-five-day-introductory-course-1194...
Ruby on-rails-101-presentation-slides-for-a-five-day-introductory-course-1194...Ruby on-rails-101-presentation-slides-for-a-five-day-introductory-course-1194...
Ruby on-rails-101-presentation-slides-for-a-five-day-introductory-course-1194...Nilesh Panchal
 
Boxen: How to Manage an Army of Laptops
Boxen: How to Manage an Army of LaptopsBoxen: How to Manage an Army of Laptops
Boxen: How to Manage an Army of LaptopsPuppet
 
Gemification for Ruby 2.5/3.0
Gemification for Ruby 2.5/3.0Gemification for Ruby 2.5/3.0
Gemification for Ruby 2.5/3.0Hiroshi SHIBATA
 
Rake: Not Your Father's Build Tool
Rake: Not Your Father's Build ToolRake: Not Your Father's Build Tool
Rake: Not Your Father's Build Toolfilmprog
 

Ähnlich wie Rubygems And You (20)

Open Source Saturday - How can I contribute to Ruby on Rails?
Open Source Saturday - How can I contribute to Ruby on Rails?Open Source Saturday - How can I contribute to Ruby on Rails?
Open Source Saturday - How can I contribute to Ruby on Rails?
 
Rocket Fuelled Cucumbers
Rocket Fuelled CucumbersRocket Fuelled Cucumbers
Rocket Fuelled Cucumbers
 
Ruby on Rails 101 - Presentation Slides for a Five Day Introductory Course
Ruby on Rails 101 - Presentation Slides for a Five Day Introductory CourseRuby on Rails 101 - Presentation Slides for a Five Day Introductory Course
Ruby on Rails 101 - Presentation Slides for a Five Day Introductory Course
 
RubyConfBD 2013 decouple, bundle and share with ruby gems
RubyConfBD 2013   decouple, bundle and share with ruby gems RubyConfBD 2013   decouple, bundle and share with ruby gems
RubyConfBD 2013 decouple, bundle and share with ruby gems
 
Crate Packaging Standalone Ruby Applications
Crate  Packaging Standalone Ruby ApplicationsCrate  Packaging Standalone Ruby Applications
Crate Packaging Standalone Ruby Applications
 
Extracting Plugins And Gems From Rails Apps
Extracting Plugins And Gems From Rails AppsExtracting Plugins And Gems From Rails Apps
Extracting Plugins And Gems From Rails Apps
 
Crate - ruby based standalone executables
Crate - ruby based standalone executablesCrate - ruby based standalone executables
Crate - ruby based standalone executables
 
Week6
Week6Week6
Week6
 
Setup ruby
Setup rubySetup ruby
Setup ruby
 
The Future of Bundled Bundler
The Future of Bundled BundlerThe Future of Bundled Bundler
The Future of Bundled Bundler
 
The Architecture of PicCollage Server
The Architecture of PicCollage ServerThe Architecture of PicCollage Server
The Architecture of PicCollage Server
 
Simple Web Services With Sinatra and Heroku
Simple Web Services With Sinatra and HerokuSimple Web Services With Sinatra and Heroku
Simple Web Services With Sinatra and Heroku
 
Node js quick-tour_v2
Node js quick-tour_v2Node js quick-tour_v2
Node js quick-tour_v2
 
Node js quick tour v2
Node js quick tour v2Node js quick tour v2
Node js quick tour v2
 
Node js quick-tour_v2
Node js quick-tour_v2Node js quick-tour_v2
Node js quick-tour_v2
 
Creating Ruby Gems
Creating Ruby Gems Creating Ruby Gems
Creating Ruby Gems
 
Ruby on-rails-101-presentation-slides-for-a-five-day-introductory-course-1194...
Ruby on-rails-101-presentation-slides-for-a-five-day-introductory-course-1194...Ruby on-rails-101-presentation-slides-for-a-five-day-introductory-course-1194...
Ruby on-rails-101-presentation-slides-for-a-five-day-introductory-course-1194...
 
Boxen: How to Manage an Army of Laptops
Boxen: How to Manage an Army of LaptopsBoxen: How to Manage an Army of Laptops
Boxen: How to Manage an Army of Laptops
 
Gemification for Ruby 2.5/3.0
Gemification for Ruby 2.5/3.0Gemification for Ruby 2.5/3.0
Gemification for Ruby 2.5/3.0
 
Rake: Not Your Father's Build Tool
Rake: Not Your Father's Build ToolRake: Not Your Father's Build Tool
Rake: Not Your Father's Build Tool
 

Kürzlich hochgeladen

SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
Vector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesVector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesZilliz
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfRankYa
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clashcharlottematthew16
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024The Digital Insurer
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostZilliz
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embeddingZilliz
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 

Kürzlich hochgeladen (20)

SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
Vector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesVector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector Databases
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdf
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clash
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embedding
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 

Rubygems And You

  • 1. RubyGems and You Josh Nichols technicalpickles.com
  • 2. Overview • How ‘require’ works • Where rubygems fits in • Creating your own rubygem from scratch • Creating your own rubygem using jeweler Josh Nichols technicalpickles.com
  • 3. Overview • How ‘require’ works • Where rubygems fits in • Creating your own rubygem from scratch • Creating your own rubygem using jeweler Josh Nichols technicalpickles.com
  • 4. require executes the contents of a file Josh Nichols technicalpickles.com
  • 5. # foo.rb puts quot;zomg, so awesomequot; # bar.rb require 'foo.rb' $ ruby bar.rb zomg, so awesome Josh Nichols technicalpickles.com
  • 6. require ‘/usr/lib/awesome.rb’ absolute path Josh Nichols technicalpickles.com
  • 7. require ‘subdir/foo.rb’ relative path Josh Nichols technicalpickles.com
  • 8. require ‘subdir/foo’ can omit the .rb Josh Nichols technicalpickles.com
  • 9. $LOAD_PATH list of directories to look for required files Josh Nichols technicalpickles.com
  • 10. require ‘net/http’ $LOAD_PATH includes your ruby install.... this actually lives under a path like: /usr/local/lib/ruby/1.8/ Josh Nichols technicalpickles.com
  • 11. require only will execute a particular path once Josh Nichols technicalpickles.com
  • 12. # foo.rb puts quot;zomg, so awesomequot; # bar.rb require 'foo' require 'foo' require './foo' $ ruby bar.rb zomg, so awesome zomg, so awesome Josh Nichols technicalpickles.com
  • 13. Dealing with diversity... • Different environments (mac vs. win. vs. linux) • People install stuff to random places • Different versions of libraries • What do we do? Josh Nichols technicalpickles.com
  • 14. MASS HYSTERIA! Josh Nichols technicalpickles.com
  • 15. Overview • How ‘require’ works • Where rubygems fits in • Creating your own rubygem from scratch • Creating your own rubygem using jeweler Josh Nichols technicalpickles.com
  • 16. Enter RubyGems • Handles downloading and installing library • Manages $LOAD_PATH • Allows a developer to package & distribute their library Josh Nichols technicalpickles.com
  • 17. Installing • gem install burninator Josh Nichols technicalpickles.com
  • 18. Using gems require 'rubygems' require 'burninator' Josh Nichols technicalpickles.com
  • 19. Using gems in under Rails # config/environment.rb, or anywhere really require 'burninator' Josh Nichols technicalpickles.com
  • 20. Using gems in under Rails # config/environment.rb config.gem 'burninator' Josh Nichols technicalpickles.com
  • 21. Using gems in under Rails # create vendor/gems... # then 'gem unpack' gems there # config/environment.rb Rails::Initializer.run do |config| config.load_paths += Dir[quot;#{RAILS_ROOT}/vendor/gems/**quot;].map do |dir| File.directory?(lib = quot;#{dir}/libquot;) ? lib : dir end end Josh Nichols technicalpickles.com
  • 22. Where do gems live? Josh Nichols technicalpickles.com
  • 23. • RubyGems already knows about it by default • Has been the defacto standard for hosting Josh Nichols technicalpickles.com
  • 24. • But you need to apply for projects... • And you need extra tools to publish gems... Josh Nichols technicalpickles.com
  • 25. • The new hotness • Just create a repository and turn on RubyGem support • Create a Gem::Specification, and push it Josh Nichols technicalpickles.com
  • 26. Overview • How ‘require’ works • Where rubygems fits in • Creating your own rubygem from scratch • Creating your own rubygem using jeweler Josh Nichols technicalpickles.com
  • 27. Tools of the trade • Rake for automation • Testing framework of choice (we’ll assume test/unit) • RubyGems Josh Nichols technicalpickles.com
  • 28. Directory Layout |~bin/ | `-cylon_detector |~lib/ | `-cylon_detector.rb |~test/ | |-test_cylon_detector.rb | `-test_helper.rb |-LICENSE |-Rakefile `-README.rdoc Josh Nichols technicalpickles.com
  • 29. Rakefile basics require 'rubygems' require 'rake' Josh Nichols technicalpickles.com
  • 30. Gem::Specification • Metadata about your gem • name, files, binaries, homepage, etc, etc Josh Nichols technicalpickles.com
  • 31. Rakefile gemspec spec = Gem::Specification.new do |s| s.name = 'cylon-detector' s.version = '0.8.1' s.authors = ['Josh Nichols'] s.date = '2009-02-03' s.email = 'josh@technicalpickles.com' s.files = FileList['{bin,lib}/**'] s.executables = 'cylon_detector' s.has_rdoc = true s.summary = 'Detect cylons with ease' end Josh Nichols technicalpickles.com
  • 32. Rakefile gemspec task :gemspec do File.open('cylon-detector.gemspec', 'w') do |file| file.write spec.to_ruby end end Josh Nichols technicalpickles.com
  • 33. Rakefile package require 'rake/gempackagetask' Rake::GemPackageTask.new(spec) do |pkg| pkg.need_zip = false pkg.need_tar = false end Josh Nichols technicalpickles.com
  • 34. Rakefile rdoc require 'rake/rdoctask' Rake::RDocTask.new do |rdoc| rdoc.rdoc_dir = 'rdoc' rdoc.title = 'cylon-detector' rdoc.options << '--line-numbers' << '--inline-source' rdoc.rdoc_files.include('README.rdoc') rdoc.rdoc_files.include('lib/**/*.rb') end Josh Nichols technicalpickles.com
  • 35. Rakefile test require 'rake/testtask' Rake::TestTask.new(:test) do |t| t.test_files = 'test/**/test_*.rb' t.verbose = false end Josh Nichols technicalpickles.com
  • 36. Rakefile rcov begin require 'rcov/rcovtask' Rcov::RcovTask.new do |t| t.test_files = 'test/**/test_*.rb' t.verbose = true end rescue LoadError task :rcov do abort quot;RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcovquot; end end Josh Nichols technicalpickles.com
  • 37. Rakefile default task :default => :test Josh Nichols technicalpickles.com
  • 38. bin/cylon_detector #!/usr/bin/env ruby $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib')) require 'cylon_detector' # detection code here Josh Nichols technicalpickles.com
  • 39. lib/cylon_detector.rb • The entry point into your library • Require all dependencies (internal and external) • Design decisions • generally want to namespace your project • class or module? • Do not require rubygems (unless you are interacting directly with it) Josh Nichols technicalpickles.com
  • 40. test/test_helper.rb • Central location to setup testing environment require 'rubygems' require 'test/unit' $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib')) $LOAD_PATH.unshift(File.dirname(__FILE__)) require 'cylon_detector' class Test::Unit::TestCase end Josh Nichols technicalpickles.com
  • 41. test/test_cylon_detector.rb require File.dirname(__FILE__) + '/test_helper' class CylonDetectorTest < Test::Unit::TestCase # tests go here end Josh Nichols technicalpickles.com
  • 42. Workflow • Hack and commit your code • ‘rake gemspec’ and commit your gemspec • push to GitHub • wait for the gem to build • rejoice and have some Scotch Josh Nichols technicalpickles.com
  • 43. Overview • How ‘require’ works • Where rubygems fits in • Creating your own rubygem from scratch • Creating your own rubygem using jeweler Josh Nichols technicalpickles.com
  • 44. Jeweler • Handles the grunt work • Generator • Skeleton project setup for your test framework of choice • Starts a git repo setup for GitHub • Creates the repo on GitHub and enables RubyGem for it • Rake tasks • Automate version bumping • Releasing to GitHub, including tagging the release Josh Nichols technicalpickles.com
  • 45. Generator • Choose between testing frameworks • Test::Unit • Shoulda • RSpec • Bacon • Also includes cucumber stories enabled for Josh Nichols technicalpickles.com
  • 46. Versioning • Tracks current version in VERSION.yml • Rake tasks for bumping the version • version:bump:patch, version:bump:minor, version:bump:major Josh Nichols technicalpickles.com
  • 47. 0.8.5 patch version API backward-compatible bug fixes minor enhancements Josh Nichols technicalpickles.com
  • 48. 0.8.5 minor version mostly API backwards compatible more significant enhancements Josh Nichols technicalpickles.com
  • 49. 0.8.5 major version break API as much you want usually signifies an overhaul Josh Nichols technicalpickles.com
  • 50. Releasing • Updates the gemspec based on the version • Pushes to GitHub • Tags the release with the version number Josh Nichols technicalpickles.com