Capistrano bundle install gem from git rails not finding gem? - ruby-on-rails-3.1

Forked wicked_pdf and added to Gemfile
gem 'wicked_pdf', '= 0.7.2', :git => 'git://github.com/geoffcorey/wicked_pdf.git'
Capistrano deploy does
bundle install --path vendor/gems --without development
All gems show up in vendor/gems/ruby/1.9.1/gems except wicked_pdf which the repo is cloned to vendor/gems/ruby/1.9.1/bundler/gems.
bundle list will show the wicked_pdf (0.7.2 156782e) but when I fire up the application via Apache/Passenger, Rails 3.1.3 cannot find wicked_pdf.
Is there something else I should be doing as part of the deploy to have the wicked_pdf build the gem and install as a separate task?

I am having exactly the same problem here (but hosting on heroku).
http://gembundler.com/man/bundle-package.1.html
"In Bundler 1.0, the bundle package command only packages .gem files, not gems specified using the :git or :path options. This will likely change in the future."
Have a look at:
Bundler: `bundle package` with a :git source
and maybe use:
http://underpantsgnome.com/2011/01/05/how-to-install-private-gems-on-heroku
to install the gem.

Your problem may be that (a) you're locking it to an exact version "=0.7.2", but you don't specify a commit ID on the git repo. These two things are in conflict. It's possible that the version entry in the gemspec is no longer 0.7.2 at the tip of the branch you're pulling from git.
If you specify a git location for a gem, it's best not to specify a version, but instead the commit ID you want, i.e.:
gem 'wicked_pdf', :git => 'git://github.com/geoffcorey/wicked_pdf.git', :ref => 'commit_id_on_github_you_want'

Related

How could I install Gems from git repositories?

I need to install gem form git repository. repository contains .gemspec file. In my gem file i have following code:
gem 'echo_server', :git => 'http://127.0.0.1/org/echo_server.git'
When i am running bundle install gems are installer in .bundeler and not showing in gem list.
my question is:
How the gem will be available in system, so that i can use in require ?
There are some similar SOQ but it does't help me.
It is not showing up when you type gem list because it is not being installed like a regular gem. You can require it like you would any other library because Bundler knows about it and will set it up for you. You should see it in your $LOAD_PATH:
$LOAD_PATH.grep(/nameofgem/)
See the Bundler documentation on this for more information.
If instead you want to install it as a regular gem from the Git repository, you can clone the repository and then build and install the generated gem. For example:
gem build echo_server.gemspec
gem install echo_server-X.Y.Z.gem
There is also specific_install.

Ruby gem for Mozenda

Has anyone worked with Mozenda in ruby on rails project before?
I am looking for gem or wrapper of Mozenda API.
Searched online there were two library 'mozenda' and 'mozenda-api'.
Unfortunately, both cannot be found when i tried to install them.
Install one of them as a git repo by adding the proper record into Gemfile:
gem 'mozenda', :git => 'https://github.com/jefferyf/mozenda.git'
or
gem 'mozenda-api', :git => 'https://github.com/darrikmazey/mozenda-api.git'
Then issue:
$ bundle install

Bundler and Heroku: conditional gems / two different versions of a gem

I have a gem that is not public and not on a publicly accessible repo (it is on the local filesystem) that I wish to use in a Heroku hosted app.
Bundler does not even allow this, for example:
group :production do
gem 'mygem', :git => #giturl
end
group :development do
gem "mygem", :require => "mygem", :path => "/gem_dev/mygem"
end
$ bundle install
...
You cannot specify the same gem twice coming from different sources. You specified that mygem (>= 0) should come from source at vendor/cache and source at ...
I've used bundle install --path vendor and bundle package to try and get it to use the cache, but since the gem is a local path Bundler tells me (helpfully) that it won't cache it. To get around this I copied the .gem to vendor/cache and had the line in Gemfile:
gem 'mygem', :path => 'vendor/cache'
but I get this error from Bundler:
Could not find gem 'mygem (>= 0) ruby' in source at vendor/cache.
Source does not contain any versions of 'mygem (>= 0) ruby'
Heroku needs a valid path. Any ideas how I can get this to work for me?
Any help is much appreciated.
This can't be done with the current version (1.0.x). From http://gembundler.com/man/bundle-package.1.html
GIT AND PATH GEMS In Bundler 1.0, the bundle package command only
packages .gem files, not gems specified using the :git or :path
options. This will likely change in the future.
What follows is my opinion:
Why not? That surely wasn't a technical decision so I'm... aggrieved... Bundler is supposed to solve problems, and since it's written in Ruby by a couple of well known rubyists you'd expect (or I would) that they'd have taken the route that Ruby core has - we're adults, let us choose what we really want to do, regardless of whether the computer believes otherwise.
If I'm using Bundler and want to install a thousand different versions of a gem then that should be my business. A warning would've done. Let's hope the next version doesn't have this strange decision included in the code.

Using bundler with "--path vendor", why are gems specified with ":git" not locally vendored?

I'm using bundler and have a Gemfile that looks like this:
source 'http://rubygems.org'
gem 'sinatra', '1.3.1'
gem 'httparty'
# ...etc...
gem 'my_custom_gem', :git => 'git#github.com:me/my_custom_gem.git'
When I run bundle install it fetches the necessary gems, including my custom gem, and installs them in the system gem directory. So far, so good. However, an issue arises when I try to vendor them into a project-local directory. When I run
bundle install --path vendor
It creates the "vendor" directory in my project root and installs all the regular gems there. So I see directories like
vendor/ruby/1.8/gems/sinatra-1.3.1
vendor/ruby/1.8/gems/httparty-0.8.1
...etc...
But it does not vendor the gem specified with a 'git' parameter. I expect to see but do not see anything like
vendor/ruby/1.8/gems/my_custom_gem-1.0.0
It continues to use the system-installed version of this gem. Any explanation for this? Any clean way to get this custom gem vendored as well?
Not supported right now, hopefully coming in Bundler 1.1:
https://github.com/carlhuda/bundler/issues/67
For now you'll have to do:
cd vendor/ruby/1.8/gems/
git clone git://github.com/foo/foo.git
or similar

How do I specify local .gem files in my Gemfile?

I have a couple of gem files which I install via gem install xx.gem. Can I tell Bundler to use them? Or do I have to specify the source path?
This isn't strictly an answer to your question about installing .gem packages, but you can specify all kinds of locations on a gem-by-gem basis by editing your Gemfile.
Specifying a :path attribute will install the gem from that path on your local machine.
gem "foreman", path: "/Users/pje/my_foreman_fork"
Alternately, specifying a :git attribute will install the gem from a remote git repository.
gem "foreman", git: "git://github.com/pje/foreman.git"
# ...or at a specific SHA-1 ref
gem "foreman", git: "git://github.com/pje/foreman.git", ref: "bf648a070c"
# ...or branch
gem "foreman", git: "git://github.com/pje/foreman.git", branch: "jruby"
# ...or tag
gem "foreman", git: "git://github.com/pje/foreman.git", tag: "v0.45.0"
(As #JHurrah mentioned in his comment.)
Seems bundler can't use .gem files out of the box. Pointing the :path to a directory containing .gem files doesn't work. Some people suggested to setup a local gem server (geminabox, stickler) for that purpose.
However, what I found to be much simpler is to use a local gem "server" from file system:
Just put your .gem files in a local directory, then use "gem generate_index" to make it a Gem repository
mkdir repo
mkdir repo/gems
cp *.gem repo/gems
cd repo
gem generate_index
Finally point bundler to this location by adding the following line to your Gemfile
source "file://path/to/repo"
If you update the gems in the repository, make sure to regenerate the index.
I would unpack your gem in the application vendor folder
gem unpack your.gem --target /path_to_app/vendor/gems/
Then add the path on the Gemfile to link unpacked gem.
gem 'your', '2.0.1', :path => 'vendor/gems/your'
By default Bundler will check your system first and if it can't find a gem it will use the sources specified in your Gemfile.
You can force bundler to use the gems you deploy using "bundle package" and "bundle install --local"
On your development machine:
bundle install
(Installs required gems and makes Gemfile.lock)
bundle package
(Caches the gems in vendor/cache)
On the server:
bundle install --local
(--local means "use the gems from vendor/cache")
Adding .gem to vendor/cache seems to work. No options required in Gemfile.
I found it easiest to run my own gem server using geminabox
See these simple instructions.

Resources