Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails 3: define plugin gem dependency

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.

like image 385
Sebtm Avatar asked Nov 21 '10 17:11

Sebtm


1 Answers

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.

like image 186
Sebtm Avatar answered Nov 02 '22 23:11

Sebtm