Giter Site home page Giter Site logo

buildingagemwithbundler's Introduction

LoremCasiano

This gem describes the way to build a gem using bundler

Tutorial

  1. $ bundle gem lorem_casiano create lorem_casiano/Gemfile create lorem_casiano/Rakefile create lorem_casiano/LICENSE create lorem_casiano/README.md create lorem_casiano/.gitignore create lorem_casiano/lorem_casiano.gemspec create lorem_casiano/lib/lorem_casiano.rb create lorem_casiano/lib/lorem_casiano/version.rb Initializating git repo in /Users/casiano/Dropbox/src/ruby/makingagemwithbundler/lorem_casiano makingagemwithbundler$ cd lorem_casiano/

    As it says, it initializes a git repo

  2. The lorem_casiano.gemfile file looks like this:

$ cat lorem_casiano.gemspec # -- encoding: utf-8 -- require File.expand_path('../lib/lorem_casiano/version', FILE)

  Gem::Specification.new do |gem|
    gem.authors       = ["Casiano Rodriguez"]
    gem.email         = ["[email protected]"]
    gem.description   = %q{TODO: Write a gem description}
    gem.summary       = %q{TODO: Write a gem summary}
    gem.homepage      = ""

    gem.files         = `git ls-files`.split($\)
    gem.executables   = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
    gem.test_files    = gem.files.grep(%r{^(test|spec|features)/})
    gem.name          = "lorem_casiano"
    gem.require_paths = ["lib"]
    gem.version       = LoremCasiano::VERSION
  end
  1. The version for the project is taken from lib/lorem_casiano/version.rb

         $ cat lib/lorem_casiano/version.rb 
         module LoremCasiano
           VERSION = "0.0.1"
         end
    

    modify it to "0.0.2"

  2. vi lib/lorem_casiano.rb. Introduce method ipsum

  3. Fill the TODOs and homepage fields in lorem_casiano.gemspec vi lorem_casiano.gemspec

  4. Generate the gem:

    $ gem build lorem_casiano.gemspec Successfully built RubyGem Name: lorem_casiano Version: 0.0.2 File: lorem_casiano-0.0.2.gem

which generates a file "lorem_casiano-0.0.2.gem"

  1. Push the gem to rubygems.org

       $ gem push lorem_casiano-0.0.2.gem 
       Pushing gem to https://rubygems.org...
       Successfully registered gem: lorem_casiano (0.0.2)
    

Of course you have to have an account in rubygems.org

  1. Lead your browser to "https://rubygems.org/gems/lorem_casiano". Your gem must be allocated there

  2. The "Gemfile" file has this contents:

    $ cat Gemfile source 'https://rubygems.org'

    Specify your gem's dependencies in lorem_casiano.gemspec

    gemspec

The "gemspec" leads Bundler to use "lorem_casiano.gemspec" to solve the dependencies. This way, there is no need to specify dependencies here.

  1. $ bundle Fetching gem metadata from https://rubygems.org/.... Installing diff-lcs (1.1.3) Using lorem_casiano (0.0.3) from source at /Users/casiano/Dropbox/src/ruby/makingagemwithbundler/lorem_casiano Installing rspec-core (2.10.1) Installing rspec-expectations (2.10.0) Installing rspec-mocks (2.10.1) Installing rspec (2.10.0) Using bundler (1.1.3) Your bundle is complete! Use bundle show [gemname] to see where a bundled gem is installed.

  2. A new call to bundle recomputes and install the dependencies:

$ bundle Fetching gem metadata from https://rubygems.org/.... Installing diff-lcs (1.1.3) Using lorem_casiano (0.0.3) from source at /Users/casiano/Dropbox/src/ruby/makingagemwithbundler/lorem_casiano Installing rspec-core (2.10.1) Installing rspec-expectations (2.10.0) Installing rspec-mocks (2.10.1) Installing rspec (2.10.0) Using bundler (1.1.3) Your bundle is complete! Use bundle show [gemname] to see where a bundled gem is installed.

  1. The Rakefile contains:

$ cat Rakefile #!/usr/bin/env rake require "bundler/gem_tasks"

Thes are the tasks that provides:

$ rake -T rake build # Build lorem_casiano-0.0.3.gem into the pkg directory rake install # Build and install lorem_casiano-0.0.3.gem into system gems rake release # Create tag v0.0.3 and build and push lorem_casiano-0.0.3.gem to Rubygems

  1. Let us see the "build" target:

    $ rake build lorem_casiano 0.0.3 built to pkg/lorem_casiano-0.0.3.gem

    Now we have this structure:

    $ tree . ├── Gemfile ├── Gemfile.lock ├── LICENSE ├── README.md ├── Rakefile ├── lib │   ├── lorem_casiano │   │   └── version.rb │   └── lorem_casiano.rb ├── lorem_casiano-0.0.2.gem ├── lorem_casiano.gemspec └── pkg └── lorem_casiano-0.0.3.gem

  2. We can install the gem:

    $ rake install lorem_casiano 0.0.3 built to pkg/lorem_casiano-0.0.3.gem lorem_casiano (0.0.3) installed

  3. The rake release task creates a tag on GitHub with the version of your gem, push the locally committed files to the master on GitHub and publishes your gem on RubyGems.org. Remember, commit your changes, before run this task.

    $git commit -m 'preparing release 0.0.3' -a

Set the remote:

$ git remote rm origin
$ git remote add origin [email protected]:crguezl/buildingagemwithbundler.git

push the changes:

$ git push origin master
Counting objects: 31, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (26/26), done.
Writing objects: 100% (31/31), 5.78 KiB, done.
Total 31 (delta 11), reused 0 (delta 0)
To [email protected]:crguezl/buildingagemwithbundler.git
 * [new branch]      master -> master

Release:

$ rake release
  lorem_casiano 0.0.3 built to pkg/lorem_casiano-0.0.3.gem
  Tagged v0.0.3
  Pushed git commits and tags
  Pushed lorem_casiano 0.0.3 to rubygems.org

Usage

TODO: Write usage instructions here

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Added some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

##See Also

  1. http://railscasts.com/episodes/245-new-gem-with-bundler "New Gem with Bundler" Source code: https://github.com/ryanb/railscasts-episodes/tree/master/episode-245

  2. http://no-fucking-idea.com/blog/2012/04/11/building-gem-with-bundler/ "Building Gem With Bundler"

  3. http://pablotron.org/files/signing_gems.txt

  4. Gem::Specification Reference: http://docs.rubygems.org/read/chapter/20

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.