Ruby‎ > ‎Working with Gems‎ > ‎

Merging Gems

Merging Gems

Workers run in a Ruby environment in the cloud. A limited number of gems are included as part of the native environment. See Supported Gems for the list.

You can merge gems (and specific gem versions) with your worker by using the merge_gem command.

Here's how:

  1. Make sure you're using the most recent simple_worker gem.

  2. Add merge_gem "<gem name>" in your worker class (inside the class but outside the run method).

That's it!


For example, to use the dropbox gem, simply add:

class DropBoxGem < SimpleWorker::Base
    merge_gem "dropbox"
    merge_gem "some_other_gem"

    def run
      # your worker code

For including a specific version of a gem, just include the version number after the gem.

 merge_gem "some_other_gem_with_version", "1.2.3"

For gems with different sub-directory names, include a require with the path.

merge_gem 'mongoid_i18n', :require => 'mongoid/i18n'

Merging Gems with Data Files

For including non .rb files with the gem, you can include the directory after the gem

merge_gem 'prawn', :include_dirs=>['data']

Global merge_gem

You can also specify gems that you would like to use globally. In your configuration block you can use:

config.merge_gem 'mini_fb'

This will then be used in all of your workers.

Gems with Dependencies

Gems with other gem dependencies will not automatically be merged. You may have to merge in the dependent gems in these situations. Use the gem dependency 'gem_name' command to find additional gems you may need to merge.

Also, if one gem depends on another at require/load time, then they will need to appear in the correct order. One way to think of merge_gem is as if it were just a require.

For example, if you're using the gdocs4ruby gem, running gem dependency gdocs4ruby shows that it depends ongdata4ruby.

$ gem dependency gdocs4ruby
Gem gdocs4ruby-0.1.2
  gdata4ruby (>= 0.1.1, runtime)

Given this dependency, you'll want to merge them both into your worker -- in the order of dependency.

merge_gem "gdata4ruby"
merge_gem "gdocs4ruby"

Gems with Binary Encodings

Gems that make use of binary encodings may have issues running within SimpleWorker. Contact us if you are having difficulties when using a binary gem.

Other Notes

  • Our initial policy was to support a host of popular gems but we found it wasn't the right approach. We have since moved to maintaining a more streamlined native SimpleWorker environment. (We were introducing some unintended conflicts and versioning issues and realized it was better to keep things simple and let users have more control.)

  • Gems are uploaded the first time a worker runs (and if the worker changes) but are stored in the cache for subsequent runs.

  • The Code tab in your Dashboard will provide you with a view of the code, models, and gems that have been uploaded to SimpleWorker. Use this if you have questions about what gems are being merged in.