$30 off During Our Annual Pro Sale. View Details »

How to build a Ruby Gem

How to build a Ruby Gem

Presentation given at Macedonian Ruby Users Group: http://ruby.mk/.

Dalibor Nasevic

February 27, 2014
Tweet

More Decks by Dalibor Nasevic

Other Decks in Programming

Transcript

  1. How to build a Ruby Gem
    Github: @dalibor

    View Slide

  2. Tools

    Past
    – jeweler, newgem, echoe, hoe, bones

    Today
    – bundler

    View Slide

  3. What is Bundler?

    Manage application dependencies

    Create new gems

    Install bundler
    – gem install bundler

    has a command for creating gems 'gem'
    – bundle gem the_name_of_the_gem
    http://bundler.io/

    View Slide

  4. Create a new Gem
    $ bundle gem mkrug
    create mkrug/Gemfile
    create mkrug/Rakefile
    create mkrug/LICENSE.txt
    create mkrug/README.md
    create mkrug/.gitignore
    create mkrug/mkrug.gemspec
    create mkrug/lib/mkrug.rb
    create mkrug/lib/mkrug/version.rb
    Initializating git repo in /home/dalibor/projects/mkrug/mkrug

    View Slide

  5. Rake Tasks
    $ rake -T
    rake build
    # Build mkrug-0.0.1.gem into the pkg directory
    rake install
    # Build and install mkrug-0.0.1.gem into system gems
    rake release
    # Create tag v0.0.1 and build and push mkrug-0.0.1.gem to Rubygems

    View Slide

  6. Development Tips

    bundle console

    before the build, commit all the changes

    Gemfile and gemspec

    Use in an existing app while in development
    – gem 'mkrug', path: '~/projects/mkrug'
    – gem 'mkrug', git: 'git://github.com/dalibor/mkrug.git'

    View Slide

  7. Maintenance/Promotion Tips

    https://travis-ci.org

    http://rubydoc.info

    https://www.ruby-toolbox.com/ (Suggest a new project)

    http://semver.org/

    http://tom.preston-werner.com/2010/08/23/readme-driven-development.html

    License (MIT, ...)

    Github Wiki

    Changelog

    Development

    Contributing

    Issues

    View Slide

  8. Showcase

    mars_rover
    – School example
    – Naming
    – Structure
    – Conventions
    – Testing setup
    – Best practices

    deferrer
    – Real world example
    – Uses Redis

    List: "deferred:#{identifier}"

    Sorted set: 'deferred_list', (score by time, "deferred:#{identifier}")

    ruby example/runner.rb

    ruby example/client.rb

    View Slide

  9. References

    Gems
    – https://github.com/dalibor/mars_rover
    – https://github.com/dalibor/should_clean
    – https://github.com/dalibor/risky
    – https://github.com/dalibor/cyrillizer
    – https://github.com/dalibor/deferrer

    Tutorials
    – http://rakeroutes.com/blog/lets-write-a-gem-part-one/
    – http://rakeroutes.com/blog/lets-write-a-gem-part-two/
    – https://github.com/radar/guides/blob/master/gem-development.md
    – https://blog.engineyard.com/2010/extending-rails-3-with-railties

    View Slide