Where should I put gem that I cannot download from rubyforge? - ruby-on-rails

I want to use cloudmade gem but it is not stored in rubyforge so I have to download the .gem and to gem install cloudmade.gem.
Questions:
1)Is it wise to commit this to git repo so that others can use it as well?
1a) If yes, where should I put the gem in my rails app?
1b) If not, how should I share this with other people so that they won't have error when they do 'bundle install'

Best way IMHO :
clone the repo in Github,
in your Gemfile, add the path to your git depo using something like :
gem "abc", :git => "https://github.com........"
So that your team will be able to work on the project.
Try to contact the author of the gem to know if you can be the new maintainer of the gem.
Then upload it on Rubygems if you want.

Related

Rails: Extract and Edit Source Code of Specific Gem

How to extract source code of specific gem so that it is possible to edit it locally? Shall I add it to my Rails application folder?
I need that to be able to make changes to the gem's code.
If you find an error in gem, you'd better make pull request on GitHub. But let's suppose you need your private fork of gem. Best workflow for that:
Download the gem source code from GitHub: git clone https://github.com/author/awesome_gem.git.
In your project's Gemfile add gem awesome_gem, path: "/local/path/to/awesome_gem"
Run bundle install
Now you can make changes to the gem locally, and have your project use local copy of it. When you are done making initial changes, push your Gem to your github repository, and change Gemfile line to something like:
gem awesome_gem, github: 'QQQ/awesome_gem' ('QQQ' being your Github's account name)

Rails Engine gem using another Rails engine gem from git

Rails 4 # Ruby 2
So i have two engine (A, B) gems that cannot be uploaded to Rubgems because the code is private, so im using git.
A must use B, so basically i should add B as a dependency in A gemspec. As far as i know, gemspec doesn't allow git based gems as a dependency inside gemspec.
I tried to use A gemfile but no luck. Is there a way out?
For development or test, you can do it in Gemfile. You can even point it to use your local folder.
gem 'gem_b', path: "/path/to/the/folder"
or to use a git reference
gem 'gem_b', git: "git#github.com:user/gem_b.git"
This will allow you to do the development and testing.
Another option is this. If you have 2 engines, I assume you also have a Rails app to use them. In that rails app, you can simply require them in Gemfile one after another using git reference.
gem 'gem_b', git: "git#github.com:user/gem_b.git"
gem 'gem_a', git: "git#github.com:user/gem_a.git"
If you must declare this dependency in gemspec, you can build the gem using rake;
cd /path/to/gem_b
rake build
This will create a gem_b.gem file under pgk folder.
Then you can install it in your local using gem instal like this
gem install pgk/gem_b.gem
Now you have gem_b installed in our local. There will be no problem adding it as a dependency in gemspec.
When you are ready to release your application, you need to copy gem_b.gem to your server and install using usual way;
gem install /full/path/to/gem_b.gem

Where are the gem files located?

Where are the gem files located ?
I'm new to rails and trying o understand how the whole gem functionality works.
My question is how can i follow a gem installation in order to confirm a gem is been installed ?
Where are the installed files located ?
From within your rails app, you can list out all of the gems being used, their versions, and the local path:
bundle show --paths
There's no reason to modify any of these files though. Configuration is typically done through an initializer in /app/initializers, but it depends on the gem being used.
If you need to modify something about the gem, you should fork it on Github and then reference the git location in your Gemfile until your pull request makes it back into the gem:
gem 'some_gem', '4.1.1', git: 'https://github.com/some_github_repo/some_gem.git'

Whats the best way to tweak ruby gems for code reading

To help understand the source code of various gems I often want to place various puts statements in the source code or even try using the ruby debugger.
But whats the best way of doing this?
Do you clone the project from github and make changes locally, if so how do you "force" the use of the local cloned code over the local gem on your machine. Do I just create some scripts that explicitly require the path of the cloned repos folder?
Or do should I use rvm to create a temp gemset, download the gem and modify it directly?
Are there any other methods ive overlooked? How would this change for gems designed for use within rails projects.
The way I usually do it when I want to make changes to a Gem:
Fork the repository on Github
Check it out and create a new branch for local changes
Use Bundler to manage dependencies for the project which uses the Gem
Change one line in the Gemfile to make it use the forked version of the Gem:
gem "thegem", :git => "git://github.com/name/thegem.git", :branch => 'mybranch'
or
gem "thegem", :git => "file:///path/to/thegem", :branch => 'mybranch'
with /path/to/thegem being the path to your local working copy.
The advantage is that you now already have a the perfect infrastructure set up for contributing your changes through a pull request :)
With Bundler.
In a Rails app simply edit the Gemfile and add:
gem "gem_name", :path => "~/MyGems/gem_name"
PS: Bundler work with any Ruby project.
You can use rvm to create a temp gemset, download the gem and modify it directly. A fast way to view/modify a gem is using gemedit :
Install:
gem install gemedit
Usage:
gem edit devise
or: gem edit devise -e mate

How to find out what fork/original of a gem is installed on my system?

When I add gem 'delayed_job' to my gemfile, how do I know whether I am going to get
collectiveidea / delayed_job or tobi / delayed_job ?
Also, is there some way to check among the list of gems I already have installed, as to which fork/location those gems were downloaded/installed from?
Ps. I am using RVM on Ubuntu, Bundler and Rails 3.0.3
There isn't one way to tell which github fork or branch you are downloading from. For the delayed_job gem you are downloading from collectiveidea's branch. You can tell on this page where the homepage points to collectiveidea's github fork. The reason you can't tell which fork in particular is because rubygems aren't linked to github repositories. They are simply packages that are uploaded to the site. For all you know you could be downloading a gem from a copy of someone's local repository that isn't even published on the internet. You could also be downloading from an SVN repository instead of a Git repository. In general the rubygems.org site should give you some idea of how to find the source code for a gem though. Also, most github gems tag their commits with a version number so that you can tell which revision you are using by checking the github/git tags.
If you want to specify git location you can use :git param:
gem "delayed_job", :git => "git://github.com/collectiveidea/delayed_job.git"
gem "delayed_job", :git => "git://github.com/tobi/delayed_job.git"
Read more about Gemfile
The gemspec contains a homepage attribute, which often shows the source code repository. You can view a gemspec of a locally installed gem with:
gem spec delayed_job
View the homepage with:
gem spec delayed_job | grep homepage
That said, the gemspec does not always have the source repo.
To help solve this problem (and others), I wrote a gem called gemdiff. It does the gemspec inspection, and if that does not contain a github URL, it searches github for a match. It includes exceptions for gems like delayed_job, which is a fork of the original repository by tobi.
gem install gemdiff
gemdiff find delayed_job
=> http://github.com/collectiveidea/delayed_job
More valuably, gemdiff will inspect your project's bundle and can show you the source code diff between the version of a gem you have installed and the highest version that can be installed, as determined by bundler.
https://github.com/teeparham/gemdiff

Resources