Path to dependency of a gem in Gemfile - ruby-on-rails

In a rails project, I have a Gemfile which specifies a gem dependency as follows:
gem 'darshan', '1.1.4'
To be compiled, this particular gem requires the location of the corresponding C library, which may not be in a "standard" location such as /usr/lib. Manually, one would install this gem as follows, for example:
gem install darshan -- --with-darshan-dir=$HOME/local
How can I add this "with-darshan-dir..." to the gem command in the Gemfile, and more importantly, how can I make it such that the user himself provides this location as optional parameter when calling bundle install?
I checked the gemfiles manual (http://bundler.io/man/gemfile.5.html) but couldn't find anything to do that.
Thanks

Related

Use additional gem in deployment

does anyone have any idea how to add ruby gems if Gemfile.lock exists?
I’m using an application from an apt package but I want to add my custom gem.
In the Gemfile it says:
# Want to extend Zammad with additional gems?
# ZAMMAD USERS: Specify them in Gemfile.local
# (That way, you can customize the Gemfile
# without having your changes overwritten during upgrades.)
But if I create the Gemfile.local with my Gem the Application couldn start.
You are trying to install in deployment mode after changing
your Gemfile. Run bundle install elsewhere and add the
updated Gemfile.lock to version control.
If this is a development machine, remove the / opt / zammad / Gemfile freeze
by running bundle install --no-deployment.
The list of sources changed
The dependencies in your gem file changed
You have added to the Gemfile:
mySpecialGem
I used to be able to do this with bundle install --no-deployment , but when I do that I always get the same message
Are you installing the gem as:
gem "gem_name", path: "/Users/Matthies/gem_location"
Could you post what your Gemfile looks like?
the gemfile from the original package is
https://github.com/zammad/zammad/blob/stable/Gemfile
in my Gemfile.local is this:
gem 'gem_name', git: 'https://github.com/myname/mygem'

What kind of dependencies must be in Gemfile and in gemspec?

Cant figure out where rails gem must specify its dependencies? In Gemfile on in gemspec? The generated Gemfile has these description:
# Declare your gem's dependencies in malibu.gemspec.
# Bundler will treat runtime dependencies like base dependencies, and
# development dependencies will be added by default to the :development group.
gemspec
# Declare any dependencies that are still in development here instead of in
# your gemspec. These might include edge Rails or gems from your path or
# Git. Remember to move these dependencies to your gemspec before releasing
# your gem to rubygems.org.
But I still can understand. Can you help me? My thanks
If you are developing a new gem, then you'll want to declare all of your production-ready gems in the .gemspec using add_dependency.
As for the Gemfile itself, as the comment states, it is used for adding dependencies which are still in development (i.e. not released). For example, if you want to use the latest edge version of Rails, you'd have to specify that dependency with the git or github option (e.g. gem "rails", github: "rails/rails"). These options are only available in the Gemfile, not the .gemspec.
In general you want to always put your dependencies in the .gemspec and only use the Gemfile if you need to.

Gemfile gem installation and gemspec dependencies

I have an app whose Gemfile requires a gem that is also dependent on another gem that is currently found on github.
So
app/Gemfile reads
gem "my-gem", :git => "git://github.com/MyCompany/my-gem.git"
my-gem/Gemfile reads
gem "my-gem-2", :git => "git#github.com:MyCompany/my-gem-2.git"
my-gem/my-gem.gemspec reads
spec.add_dependency "my-gem-2"
When I run bundle inside of app I get an error that it can't find gem my-gem-2 which is required by my-gem; however, if I put the following line
gem "my-gem-2", :git => "git#github.com:MyCompany/my-gem-2.git"
inside of app/Gemfile then it works fine.
This practice seems redundant as I wouldn't think I'd have to add gem dependencies of another gem into my parent app. Is there something I'm doing wrong here that myapp can't find my-gem-2?
This is just the way it goes - Gemfile dependencies within gems are just for when you're developing that gem. Only the gemspec gets evaluated when the gem is used elsewhere (and gemspecs have no concept of git dependencies), hence only dependencies in the gemspec apply.
So: you will need to have both git references within your app's Gemfile.
As stated in the gem specification, the list of gems that you provide through add_dependency will be use to make sure those are already installed in the system during the installation process (i.e gem install). So this line:
my-gem/my-gem.gemspec reads spec.add_dependency "my-gem-2"
Will trigger the verification of whether or not the gem is installed in the system, but it will not trigger any automatic installation of such gem, as Bundler would do.
This other line (inside of your gem):
gem "my-gem-2", :git => "git#github.com:MyCompany/my-gem-2.git"
Specify that a gem should come from a git repository with a .gemspec at its root.
For more details: Gems from git repositories

Ruby/rails/bundler: bundling only *some* of the required gems

I need to deploy a Rails app packaged up as a RHEL RPM. I want to bundle some of the gems it requires, but let the rest be satisfied from the production machine's system gems.
As an end result (for instance), I want the app to find some gems (like versionomy, for instance) in the app's vendor tree, but find the Rails activerecord, actionpack, and other gems in the host's system-wide gem library.
So far I've only found ways to bundle all-or-nothing. Can anyone point me to documentation explaining how to use Bundler and yet have $: be a search path, listing the app's bundled gems first and then the system's gems? Or if it's even possible?
Thanks!
specify path for gems in vendor directory
in Gemfile:
gem 'versionomy', :path => 'vendor/extensions'
Update
Yes it will work in deployment group.
You can specify wich gems are used in development, production and test
group :development, :test do
gem 'sqlite3'
gem 'thin'
end
group :production do
gem 'pg'
end
system path for gems in my case
/usr/local/lib/ruby/gems/1.9.1/gems/
check your install path by whereis gem
and if you are using rbenv
/home/username/.rbenv/versions/1.9.3-p362/lib/ruby/gems/1.9.1/gems/
You may have to install the requirements you don't want to provide as their own RPMs on the building machine. Then the RPM build process will require them but not provide them.

how to include all project gems into the gemfile?

I work as a developer supporting several apps built in Rails, often I need to install gems that are not included into the gem file.
Last day I build a project and when I try to run it on another computer I experienced some issues with missing gems, a lot actually and I didn't know where to get a list of all the missing gems or how to install them.
The question is, is there a way to include all the gems that the project needs into the gem file so next time someone try to run it on another computer it will be enough to use the comand bundle install.
You need to include the Gems in your Gemfile, and then run bundle install on ANY new machine in order to install those Gems and their dependencies. For example:
source 'https://rubygems.org'
gem 'rails', '3.2.6'
gem 'jquery-rails'
gem 'mongoid'
gem 'devise'
gem 'cancan'
With this example, all dependencies of rails such as Active Record, Action Pack and so on will be installed when bundler installs rails. The same for the remaining gems and their dependencies.
If you are planning, and it appears that you are, to spend much time with rails, you should really read up on Bundler.

Resources