I want to install a gem mannually.
I have downloaded the content of the git repo, modified the gemfile.lock (delete rails version depedencie in order to use the gem in my superior version of Rails).
But where do I put the folder and how do I add this folder to my gem list?
GitHub repo
In your Gemfile you just put
gem 'gem_name', :path => "path_to_gem"
Related
All right so I have a gem file the is local. In my rails application the gem spec file and the created gem along with all files bundled is located at:
vendor/gems/mygem
In my Gemfile I have
gem 'mygem-1.0', :path => 'vendor/gems/mygem'
When I run:
bundle install
I get an error:
Could not find gem 'mygem-1.0 x86-mingw32' in source at 'vendor/gems/mygem' in source at 'vendor/gems/mygem/'.
Source does not contain any version of 'mygem-1.0 x86-mingw32'
Ok so after taking a break for a few minutes. I noticed that I was actually calling the version number of the gem as part of the gem name:
# What I originally Had
gem 'mygem-1.0', :path 'vendor/gems/mygem'
# What it should be
gem 'mygem', :path 'vendor/gems/mygem'
the bundler added the version number to the gem automatically and I assumed this was part of the file name and the version was specified inside the gemfile itself.
In my Rail 3.2.13 gemfile I have added the country_select gem
gem 'country_select', :git => 'git://github.com/stefanpenner/country_select.git'
Rrunning bundle install however loads the wrong version of the gem. It instead loads the out-dated repository at https://github.com/rails/country_select
This happens in my development environment as well as when deploying my app to Heroku.
I was able to overcome this in my dev environment by using the ruby gem specific_install however that doesn't help with heroku.
Any ideas?
You have to update your Gemfile.lock with the git path:
bundle update country_select
It should do the trick.
You can set the branch you want to use on the remote git repository using:
gem 'country_select', :git => 'git://github.com/stefanpenner/country_select.git', branch: 'master'
or event a commit tag:
gem 'country_select', :git => 'git://github.com/stefanpenner/country_select.git', revision: 'commit_tag_here'
Beside, when running in Production, a good practice is to fix your gem versions in order to avoid unwanted gem updates.
in my gemfile I use a gem that points to git and a specific branch. How can I unpack a gem in my vendors/gem folder and specify the branch like so?
gem 'devise-async', :git => 'git://github.com/mhfs/devise-async.git', :branch => 'master'
Thanks
After you executed bundle install in your Rails app, you could try the bundle open devise-async to open the gem in your editor and then just save it away?
There's also bundle cache which caches all the used gems of your app in vendor/cache, but I don't know exactly in which kind...
Hope this helps!
I wrote a plugin that requires a gem as a dependency.
Where do I have to define this dependency?
I have tried to create a Gemfile in vendor/plugins/my_plugin/, but bundle install doesn‛t find this file.
Ok. I have solved.
1) Create a Gemfile in vendor/plugins/my_plugin like:
# Gemfile
source "http://rubygems.org"
gemspec
2) Create a gemspec file. In the folder vendor/plugins run this command:
bundle gem my_plugin
(Note this command ask you for overwrite some files. Check the files before answer: Y)
3) Open gemspec file in vendor/plugins/my_plugin/ and add before the keyword end:
s.add_dependency('will_paginate', '~> 3.0.pre2')
(In this example I have used will_paginate how required dipendency of my_plugin)
4) Now go in your rails app and edit Gemfile, add:
gem 'my_plugin', :path=>'vendor/plugins/my_plugin'
The path specified supposed that your plugin is already in vendor/plugins folder of your rails app.
Of course when deploy rails app you don't need anymore to specify :path argument.
5) Now in rails app root do:
bundle install
And dependency of my_plugin (will_paginate in this case) is installed.
Thank to Sinetris for initial input.
Create a Gemfile in your vendor/plugins/my_plugin/ like:
# Gemfile
source "http://rubygems.org"
gemspec
gem "your-dependency-gem-name"
note the gemspec directive.
Take a look at Using Bundler with Rubygem gemspecs for more information.
Sebtm's own answer is quite good, but it still didn't work as Tiago and orangechicken described. I had to add
require 'your-dependency-gem-name'
on top of lib/my_plugin.rb right before the engine of my_plugin is loaded.
See http://guides.rubyonrails.org/engines.html#other-gem-dependencies
Gemfile in the application folder.
# Bundle the extra gems:
# gem 'bj'
# gem 'nokogiri'
# gem 'sqlite3-ruby', :require => 'sqlite3'
# gem 'aws-s3', :require => 'aws/s3
Reference for myself. If you're making a plugin that should work with Rails as a RailTie, use rails plugin my_plugin to create the gem instead of bundle gem my_plugin. It saves you (me) a lot of trouble.
Edit: When do you need the gem to work as a RailTie? Whenever you want to add rails generator, rake tasks or add your code to a Rails app (Called Rails Engine).
/Edit
$ rails plugin new my_plugin
then you add dependencies
Gem::Specification.new do |s|
#...
s.add_dependency "rails"
s.add_runtime_dependency "heroku"
s.add_development_dependency "sqlite3"
end
to include it in your rails app, use path: as described by #Sebtm
or release it to rubygems.
$ gem build my_plugin.gemspec
$ gem push my_plugin-0.7.0.gem #replace version number
#in Gemfile, as always
gem 'my_plugin'
or tag it on github. (use their release UI) and depend on it using
gem 'my_plugin', github: 'accountname/my_plugin', tag: 'v0.7.0'
I am developing a gem to use in my rails app.
The gem is located at /home/me/my_gem.
If I use gem 'my_gem', :git => '/home/me/my_gem' bundler takes it and installs it into ~/.bundler/... but I want the gem to be used directly from /home/me/my_gem so I don't have to run bundle install every time I do a change to the gem.
You need use the :path options
gem 'my_gem', :path => '/home/me/my_gem'
After that you even not need run a bundle install. Each time is your directory code used.