Watching you 'just paste in some code' made me remember why generators are cool :)
Protip: if you want to distribute command-line executables with your gem, like the "rake" or "rails" command, then put them in <code>bin/</code> folder. Hoe, and I think Echoe, automatically package them up as executables, which is sexy.
there has never been enough talk about publishing gems. Thanks ryan for adding to a lacking topic. btw - I sure like how echoe is not required as a dependency.
@drnic good point about generators, and thanks for the protip. I did paste a lot of code in this episode, but the majority of it is specific to the project. The only thing I feel needs generating is the Rakefile, and even that has a lot of project-specific settings in it.
A generator is very much a personal preference, but I encourage everyone to try the existing ones out there or make your own as needed. For me copy & pasting the Rakefile content from an existing one is easy enough.
Thankyou for this tutorial, I just made my first Ruby Gem - a gem for accessing the Google Translation API, currently hosted @ github: http://github.com/bdude/rosettastone/tree/master
@David, there already is spam protection in place behind the scenes which has been working really well (it's blocking an amazing amount of spam). As far as I can tell, the spam you were seeing (now deleted) was from an actual human and not a spam bot.
Your plugin has a clear (hard) dependency on ActiveRecord. But you do not declare anything in your gem. Can you do that with echoe ? (so uniquify cannot be installed unless activerecord is already installed on the host). Do you recommend to explicit dependencies in gems ?
Clarifying my previous post: after generating the gem, if you install it locally by running "gem install pkg\<gem-name>-<version>.gem", you end up with a distinct folder name in "...\ruby\lib\ruby\gems\1.8\gems" when compared to installing it from the git repository (as github always seems to add an owner prefix to the gem name provided in .gemspec file).
But of course adding the owner prefix yourself doesn't solve the issue, as github will still add the owner prefix to whatever gem name you supply to it.
@Laurent, good question, I prefer to only use dependencies where I have a "require" statement which loads that gem. Here there is no "require 'activerecord'" line because I expect the developer to load this environment how he desires. He may have edge rails frozen, in that case ActiveRecord is not loaded from a gem and there's really no gem dependency.
If I had other gem dependencies outside of Rails then I would likely add those.
@Cassiano, it's important the Rakefile be in the git repository so anyone else who clones/forks the repo can regenerate the gem after making changes.
Also the gem name should not contain your username prefix as GitHub will add this when it generates the gem using your gemspec.
But the only way I can do it is by manually adding the username prefix to my *local* copy of Rakefile and regenerating the gem via the "rake install" task.
The Rakefile would then be restored to its original state before running the "rake build_gemspec" task and committing it to git.
Ryan B. You make the world a better place. I can always find great content here and for your main focus to be sharing info rather than promoting info, it shows you have lot of character. Your mom should be proud.
-bash> gem push mygem-1.2.3.gem
Enter your RubyGems.org credentials.
Don't have an account yet? Create one at http://rubygems.org/sign_up
Email: ^CERROR: Interrupted
If you want to use gem commands from the command line, you'll need a ~/.gem/credentials file, which you can generate using the following command:
bash
-bash> curl -u bart https://rubygems.org/api/v1/api_key.yaml > ~/.gem/credentials
Enter host password for user 'bart':
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 56 0 56 0 0 53 0 --:--:-- 0:00:01 --:--:-- 495
Note that you can only push a single gem version once; if you update your gem in any way, and want to update rubygems.org, you'll have to increment the version number, build the gem again, git add new/changed files, remove the old version from git tracking, and then push the new version.
Another great railscast, I've been wondering how to make a gem and this was really straight forward! Thanks!
Full circle! Great as usual..
Watching you 'just paste in some code' made me remember why generators are cool :)
Protip: if you want to distribute command-line executables with your gem, like the "rake" or "rails" command, then put them in <code>bin/</code> folder. Hoe, and I think Echoe, automatically package them up as executables, which is sexy.
there has never been enough talk about publishing gems. Thanks ryan for adding to a lacking topic. btw - I sure like how echoe is not required as a dependency.
@drnic good point about generators, and thanks for the protip. I did paste a lot of code in this episode, but the majority of it is specific to the project. The only thing I feel needs generating is the Rakefile, and even that has a lot of project-specific settings in it.
A generator is very much a personal preference, but I encourage everyone to try the existing ones out there or make your own as needed. For me copy & pasting the Rakefile content from an existing one is easy enough.
Thankyou for this tutorial, I just made my first Ruby Gem - a gem for accessing the Google Translation API, currently hosted @ github: http://github.com/bdude/rosettastone/tree/master
@David, there already is spam protection in place behind the scenes which has been working really well (it's blocking an amazing amount of spam). As far as I can tell, the spam you were seeing (now deleted) was from an actual human and not a spam bot.
Ryan. Thx for your great screencasts.
Your plugin has a clear (hard) dependency on ActiveRecord. But you do not declare anything in your gem. Can you do that with echoe ? (so uniquify cannot be installed unless activerecord is already installed on the host). Do you recommend to explicit dependencies in gems ?
@Ryan,
Thanks for this very useful screencast.
Should Rakefile really be uploaded to github, as it seems like it wont' be used by either github or the final user of the gem?
Shouldn't your gem be named "ryanb-uniquify" instead, as this will be the final folder in "ruby\lib\ruby\gems\1.8\gems" (plus version, of course)?
Clarifying my previous post: after generating the gem, if you install it locally by running "gem install pkg\<gem-name>-<version>.gem", you end up with a distinct folder name in "...\ruby\lib\ruby\gems\1.8\gems" when compared to installing it from the git repository (as github always seems to add an owner prefix to the gem name provided in .gemspec file).
But of course adding the owner prefix yourself doesn't solve the issue, as github will still add the owner prefix to whatever gem name you supply to it.
@Laurent, good question, I prefer to only use dependencies where I have a "require" statement which loads that gem. Here there is no "require 'activerecord'" line because I expect the developer to load this environment how he desires. He may have edge rails frozen, in that case ActiveRecord is not loaded from a gem and there's really no gem dependency.
If I had other gem dependencies outside of Rails then I would likely add those.
@Cassiano, it's important the Rakefile be in the git repository so anyone else who clones/forks the repo can regenerate the gem after making changes.
Also the gem name should not contain your username prefix as GitHub will add this when it generates the gem using your gemspec.
@Ryan,
Thanks for the Rakefile explanation.
Regarding the naming problem, my intent is to have a local gem that installs exactly the same as the remote (gihub's) one, such that running:
gem install pkg\ryanb-uniquify-0.1.0.gem
or
gem install ryanb-uniquify --source http://gems.github.com
would yield the same installation.
But the only way I can do it is by manually adding the username prefix to my *local* copy of Rakefile and regenerating the gem via the "rake install" task.
The Rakefile would then be restored to its original state before running the "rake build_gemspec" task and committing it to git.
What is the benefit of using gems as opposed to plugins?
I don't think you are supposed to ignore the Manifest file on github.
Ryan B. You make the world a better place. I can always find great content here and for your main focus to be sharing info rather than promoting info, it shows you have lot of character. Your mom should be proud.
load my gem in github but...
ERROR: could not find gem redvex-ar_cache locally or in a repository
can you help me?
This is the url on github
http://github.com/redvex/ar_cache/tree/master
Ok... github told me that my gem mill Manifest file, maybe you should correct the post, becouse in it you told us to add Manifest file in .gitignore
When I do put *gem 'fastercsv'* in Gemfile and require it in file by using *require faster_csv* it works fine.
But, I wanted to add fastercsv in Rakefile, jeweler gem dependency:
*gem.add_runtime_dependency 'fastercsv'*
When I do bundle install now, the gem is not installed as the actual name of gem is different, i.e. 'faster_csv'.
@Ryanb, how to require such gems with 2 names in rakefile?
GitHub stopped building gems in October of 2009. They suggest RubyGems.org.
See RubyGems' docs on Distributing Gems
Create an account: http://rubygems.org/sign_up
If you want to use gem commands from the command line, you'll need a
~/.gem/credentials
file, which you can generate using the following command:Try again:
Note that you can only push a single gem version once; if you update your gem in any way, and want to update rubygems.org, you'll have to increment the version number, build the gem again, git add new/changed files, remove the old version from git tracking, and then push the new version.