Why do names of Rails gems & plugins sometimes contain author name? - ruby-on-rails

When it comes to adding gems/plugins I notice that sometimes the author name is prepended to the gem/plugin name, whereas other times it isn't. Is there any reasoning behind this?
Example:
config.gem "thoughtbot-factory_girl", :source => "http://gems.github.com"
Why not have it as:
config.gem "factory_girl", :source => "http://gems.github.com"
When do you differentiate between the two?

When GitHub used to auto-build and host gems, they enforced a namespacing scheme by username. This is why github gems are prefixed with a username. GitHub embraces forking projects; hence the need for the prefixed usernames. GitHub was never really a good place for the canonical gem names, so they decided to drop their automatic gem hosting* when Gemcutter launched. Since then, even the original host of canonical gems, RubyForge, stopped hosting gems in favor of Gemcutter. Gemcutter is now the canonical source for all gems.
To make this easy for everyone, http://gems.rubyforge.org now points to http://gemcutter.org.
*GitHub announced that they would continue to host all old username namespaced gems for at least one more year.
With regards to factory_girl, that too is now hosted on Gemcutter. Your config only needs to look like this now:
config.gem "factory_girl"
...but I suggest also adding a version number for your projects (you'll thank me when you come back to a stale project later):
config.gem "factory_girl", :version => "1.2.3"

Because there are several projects with similar funcitonality, but provided by different authors. Maybe some of them are forks of the other ones. Or maybe they just have a common interface for a specific task.
Quick googleing yields the following authors:
javan's factory_girl
thoughtbot's factory_girl
mattmatt's factory_girl
To distinguish them, it's useful to prepend author's nickname to gem name.

Related

How can I alter a gem on heroku?

I recently deployed my app to heroku. It uses Devise, which I had to alter the after_sign_up_path so it would redirect correctly to a set page after someone signs up. This works fine locally, but when I deploy on heroku it installs the original unmodified devise gem.
Does anyone know of a way to modify a gem on heroku, or to make it use the modified gem in my vendor folder?
Thanks.
So, in general, it shouldn't be any different deploying your app on heroku than anywhere else.
One difference is that on heroku you're probably running in 'production' environment settings, and locally in 'development'. You can run in production locally too, if that were the issue.
But I don't think it is. When you say you "altered" Devise, do you mean you actually edited the source code inside the Devise gem source itself?
That's not a good practice. When a new version of Devise comes out, perhaps with security patches, what are you going to do? Re-customize the new version? It's not a great maintenance plan. If you really want to do this you can. The best way might be to create a fork of the Devise gem in a git repo (on github or anywhere else), customize that and commit your customizations to the repo, and then point to your customized version of Devise from your own git repo in your Gemfile with gem 'devise', :git => 'http://some.git.repo.clone.url.org'
But it's a bad idea.
Devise probably already supports your use case with configuration, rather than by editing Devise source code. Most experienced devs would consider that a much preferable way to accomplish what you want.
In this case, it looks like you should be providing an after_signup_path method override in your own local app, not modifying the default implementation in devise source. Google for more info, or consult the URL Finks provides in another answer, or post another question specifically asking how to do what you want to do with devise (it's actually nothing to do with heroku), being as specific as possible about what you want to accomplish.
Assuming you forked Devise to your github account, you can point your Gemfile to it by doing this:
gem "devise", :git => "git://github.com/user/devise.git", :branch => "my-awesome-branch"
By the way, I'd recommend you overwrite some devise methods rather than hack the gem but thats just my 2cents.
This may not answer your question but according to devise wiki, you don't have to alter the gem to get the redirect behavior you like, you just need to override the after_sign_in_path_for method in application controller. https://github.com/plataformatec/devise/wiki/How-To%3A-Redirect-to-a-specific-page-on-successful-sign-in-and-sign-out
Example:
def after_sign_in_path_for(resource)
current_user_path
end

how to require different gems with the same name?

I am interested in making an application that requires me to require a gmail gem for ruby.
Right now there are 2 gems:
https://github.com/dcparker/ruby-gmail
https://github.com/nu7hatch/gmail
Both gems have the same require name, ie: gmail
The second one is much clear but there is a problem with one of its method. This method works well in the first gem (link). So I was thinking maybe I could require the first one for just that method. Is it possible to do so, how?
As others answers and comments have said, you cannot simply require both gems as they are.
However, given that both are hosted on GitHub, you could fork one of them and rename the offending classes. So long as your renaming is consistent within the gem you could use your fork within your Gemfile
Of course, you wouldn't be easily able to rebase changes onto your fork easily but if you really must use both gems this might be a compromise that you are happy with.
You could add the following to your Gemfile:
gem 'gmail', :git => "git://github.com/dcparker/ruby-gmail", :branch => "master"
gem 'gmail', :git => "git://github.com/nu7hatch/gmail", :branch => "master"

Is there an updated rails_sql_views gem for rails 3.2?

I need the functionality provided by the rails_sql_views gem. However it looks like the last commit for this gem was made in 2010. Has this project been outdated by a new project? I'd like to find an active gem to use to get this functionality.
http://activewarehouse.rubyforge.org/rails_sql_views/
http://rubygems.org/gems/rails_sql_views
After further research here is a Rails 3 candidate for similar functionality:
https://github.com/bradphelan/Active-Illusion
This is a gem of this blog post:
http://xtargets.com/2011/08/02/tableless-views-with-active-record/
However this solution doesn't seem to be very popular.
schema_plus gem has create_view method that seems compatible (although I'm not familiar with rails_sql_views).
barancw, I needed this gem for our product using Rails 3.2.5, so I forked the repo and updated the necessary pieces. This gem is great for improving the performance of our large database queries, as it reduces the need to load objects into memory. I combined this gem with another optimization: Rails - given an array of Users - how to get a output of just emails?
https://github.com/ryanlitalien/rails_sql_views
Original documentation: http://rubydoc.info/gems/rails_sql_views/0.8.0/frames/index
Please keep in mind the docs are a bit outdated ("require_gem" has been replaced with "gem" and add the gem to your Gemfile as well).

How to package a gem into a Rails app that I'm concurrently developing with the app?

I'm developing a Rails app. Cool.
I'm also having to develop a component as a Gem.
Basically, the Rails app use Omniauth to allow authentication from an OAuth2 service provider. However, NO strategy exist for this particular service provider, so I am writing one, and using my app to test it (they kind of need to be tested together). Unfortunately, Omniauth now REQUIRES strategies to be packaged as gems, and put into the Gemfile along with the omniauth gem.
So basically I'm wanting to put /my-new-strategy-gem with the strategy contents, IN my /myrailsapp folder, and then do gem "mystrategy" :as => "/myrailsapp", where inside /my-new-strategy-gem there is an actual gem, with gemfile, readme, etc.
The reason I'm asking here is that I tried this before, and Git would not recognize the /my-new-strategy-gem folder inside my main app folder, since it contains its own .git file and other info.
I've heard of making it a submodule, or ways that use the vender folder, and other things, so I'm wondering which approach works best in this situation.
Edit: The reason I wanted to do it this way, too, is so my coding partner who is helping with both, could clone a repo with both, all at once, and we could repackage the standalone strategy gem later.
You can use the :git attribute to point to the git repository for your gem.
http://gembundler.com/git.html
gem "my_strategy", :git => "git://github.com/rcd/my_strategy.git"
I believe you could also do this locally instead of on github.

For some reason config.gem 'xapian-fu' fails despite gem 'xapian-fu' works?

For some reason when I try to do config.gem include for this particular gem package it always says its missing. I tried gem 'xapian-fu' and that works just fine! I am sure its not multi gem repository issue as I use the environment in regular basis and has no problem about this.
OK turns out I figured out the answer myself :P
config.gem 'xapian-fu', :lib=>'xapian_fu'
The problem seems because the lib file is being named with the underscore while the gem itself is named with hyphen.
Glad you figured out the issue, there is a good Railscast about Gem Dependencies that covers the whole config.gem setup in depth.
One additional thing, I'd highly recommend explicitly setting the gem version number you want installed as otherwise you're risking pulling a newer version of a gem that may have compatibility issues.
I wrote xapian-fu and this naming inconsistency is a bug, sorry!
It's fixed in the latest version, so you don't need to specify the :lib option any more (the library is now available as both xapian_fu and xapian-fu).

Resources