- Read Tutorial
- Watch Guide Video
In the last guide, we finished building out our ruby gem that renders the copyright information on the portfolio site. Technically, that is all you need for a traditional type of ruby gem, one that you simply want to use internally or that you want to have for just a select number of projects. However, if you are creating a ruby gem that you want the rest of the world to use then the traditional spot is to put it on rubygems.org.
If you switch over to the codebase and look at your gemfile, you may notice, each one of these is simply a call to the gem followed by a version number in most cases. If you go all the way down the bottom you can see that ours has this little git argument right here and that's because it is only on GitHub. Each one of these other gems is on rubygems.org and by default whenever you type in gem and then the name, it is going to go to rubygems.org to look for that version of the gem. Right now we're overwriting that behavior in saying we want you to use git. We really to append this at the very end so we can just say gem devcamp_view_tool and it will pull it in like these other ones.
If you do not have a rubygems.org account, you can come to the site and press sign up or if you do have an account you can press sign in. After you have finished filling out an account, you'll be able to log into the system. If you click on your profile it will show any gems that you currently have. I want to walk you through how to add gems in case that something that you would like to do.
If you click on edit profile and scroll down, (He paused the video to hide his API key) I am at the bottom of the page. Click and drag all of this content right here, hit copy and then going back into the terminal, hit paste and run it.
I already have these installed so I don't need to do it, now that you have that installed on your system, make sure that you are in the gem repo and not your portfolio repo. Come to your gem repo and type
- git status, to make sure that we don't have anything else that is committed
- bundle install
- next run
bundle exec rake release
and hit return
Let's come up to google chrome and I'm just going to go to rubygems.org. Click on my profile and look at that, we have the devcamp_view_tool. if I click on it right here you can see all of these things you can see that we have a homepage, documentation. Rubygem system connects into ruby-doc. We have a full set of instructions and our usage,
Let me come here to the gemfile, this is the type of installation we want, copy this to the clipboard. Come into our code first, scrolling all the way down the bottom, instead of using this git version I'm going to paste this in. Notice that this gives us our gem devcamp_view_tool followed by this little pointer to which version to use. Now there is a full set of ways that you can use this type of versioning. If you look through the rest of your gem code you'll see that you have these kinds of things here. Squiggly lines stand for approximately this version.
Look at uglifier, where this gives greater than or equal to 1..3 0 this is a little bit more strict. It says in the sense that it will take anything above this uglifier version 5, it would still work. If sass-rails upgraded to 10 this would no longer work. You can also do one that is exact, say that you wanted to lock this in place. You could remove that entirely and give an exact version.
What happens if we have a very small change we find a bug in our code and we want to go push it up more as a patch than anything else. We would create a version called 0.1.1 and that way all the applications that have this squiggly line would still work when they run bundle install and it could be updated as opposed to if a hard code that value. Any patches we put up or any fixes won't be accepted.
Coming back to the terminal, type bundle install
. This is going to go out to rubygems.org and if everything works there you go. Now it brought it in and it brought it in straight from ruby gems which is so cool.
Let's type in rails s to see how that is working, hit refresh, everything still works.
Very nice job if you went through all of that, you now have your first ruby gem.
- git status
- git add .
- git commit -m "Updated call to rubygems for copyright generator"
- git push origin rubygem
Since we're done with our section we can switch over to the master branch
- git checkout master
- git merge rubygem
- git push
I will see you in the next section.