Problem: Rails apps depending on gems
From WhyNotWiki
Contents |
[edit] GemInstaller
| Homepage: | http://geminstaller.rubyforge.org/index.html |
|---|---|
| Documentation: | .
|
| Depends on: | RubyGems
|
| Implementation language: | Ruby
|
GemInstaller Documentation (http://geminstaller.rubyforge.org/documentation/documentation.html#using_geminstaller_from_other_ruby_apps).
Config File Syntax SummaryThis is an example config file template showing all the valid properties (boolean defaults capitalized):
--- defaults: install_options: [ any valid option for the RubyGems 'gem install' command ] check_for_upgrade: [ true | FALSE ] fix_dependencies: [ true | FALSE ] no_autogem: [ true | FALSE ] prefer_binary_platform: [ TRUE | false ] gems: - name: [ gem name ] version: '[ any valid version specification for this gem, e.g. >= 1.0.0 ]' platform: [ any valid platform for this Gem and version specification ] install_options: [ any valid option for the RubyGems 'gem' command ] check_for_upgrade: [ true | FALSE ] fix_dependencies: [ true | FALSE ] no_autogem: [ true | FALSE ] prefer_binary_platform: [ TRUE | false ] - name: [ another gem name ] - name: [ yet another gem name ] (etc...)[edit] Automatically Requiring Gems with the autogem Method
GemInstaller provides a GemInstaller.autogem class method which will automatically invoke RubyGems’ ‘gem’ method to add all of the gems in your GemInstaller config file(s) to the load path. [...]
...
... GemInstaller.autogem('--config=/path/to/one/geminstaller.yml,/path/to/another/geminstaller.yml') ......
You can also use the “—exceptions” argument to cause autogem to throw an exception if it encounters any error. This is useful if you want to abort your application startup if any gems failed to load.
http://geminstaller.rubyforge.org/documentation/tutorials.html.
[edit] Using Common or Shared Config Files
GemInstaller supports multiple config files, with the last config files in the list overriding the previous ones. This means you could do any of the following:
- Have a common config file across all your projects, which is shared via an svn:external, and a custom config file to override or add gems which are not in the common config.
- Have a common config file across all development machines, shared on a windows share or NFS mounted drive, with machine- or platform-specific gems listed in local config files.
- Have config files that are specific to certain environments such as development and test, which will not be included when GemInstaller is run in a demo or production environment.
You may have no idea what gems your app uses, or you might just want to create a GemInstaller config file with all the gems currently on your system, in order to install the same gems on a different system. This tutorial will show you how to use the --print-rogue-gems option to automatically create a GemInstaller config file.$ geminstaller --print-rogue-gems > geminstaller.ymlThat was easy, wasn’t it? This config file should specify the exact versions for all of the gems which are currently installed on your system.
Gotchas/Notes:
- ...
- The --print-rogue-gems option generates exact version specifications. This means that you won’t ever get any gem upgrades by running GemInstaller with the standard generated file. This may be good (an upgrade can never break your app unexpectedly). However, you may wish to modify some of the version specifications to allow for upgrades. If you do this, remember to set the
check_for_upgradeconfig property to true, but be aware that this will cause GemInstaller to check the remote gem server for upgrades each time it runs, and cause it to run slow or fail if the server is unavailable.
[edit] Integrating/using with Rails
http://geminstaller.rubyforge.org/documentation/tutorials.html.
[edit] Integrating GemInstaller into Ruby on Rails
GemInstaller can be configured to automatically install all gems in the config file, and add them to the load path when Rails boots. This means that you can check out and run your application anywhere, without having to worry about manually ensuring that the required dependency gems are installed. This works with Webrick and Mongrel.
IMPORTANT NOTE: Currently, there is a bug with installing Mongrel and Rails gems on Rails startup. See Known Bugs for details.
First, you need a Rails app. I’ll let you handle this step on your own. See the Rails documentation for details.
Next, you need a geminstaller.yml config file. Create this under the Rails config directory. For details, see the documentation on the config file and the tutorial on bootstrapping your GemInstaller config with the --print-rogue-gems option.
[edit] Capistrano method
http://geminstaller.rubyforge.org/documentation/tutorials.html#running_geminstaller_from_capistrano.
GemInstaller can be hooked in as a capistrano task. This is a way to avoid having the boot.rb hacks run in [...] production, and possibly cause problems with app startup in these environments. It also is a way to avoid the current bug with Rails and Mongrel gems not being loaded correctly if they are upgraded during the app startup process.TODO: Finish writing this
[edit] boot.rb method
GemInstaller Documentation (http://geminstaller.rubyforge.org/documentation/documentation.html#using_geminstaller_from_other_ruby_apps).
Once you have your geminstaller.yml created, invoke the GemInstaller on app startup in your boot.rb. It should be placed right after the block which defines the RAILS_ROOT constant, as shown below:...
[edit] Possible solution: Freeze/unpack all your gems
[edit] Gems on Rails
| Homepage: | http://drnicwilliams.com/2007/02/09/railsrally-2007-and-gemsonrails/
|
|---|---|
| Project/Development: | https://rubyforge.org/projects/gemsonrails/
|
http://drnicwilliams.com/2007/02/09/railsrally-2007-and-gemsonrails/.
rake gems:freeze GEM=gem_to_freeze rake gems:link GEM=gem_to_link rake gems:unfreeze GEM=gem_to_unfreeze_or_unlink
