Skip to content

Caches required/loaded files (from library or GEMs) into a _vendor_ subfolder. Can be used by IRPackager

License

Notifications You must be signed in to change notification settings

rifraf/Vendorize

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Overview

Vendorize is used to create a local project-based cache of all of the files that your application requires, loads or autoloads.

This includes the standard Ruby library files, GEMs and your site-specific libraries

Example load mechanisms:

require "rubygems"
require "nokogiri"
autoload :Builder, "rack/builder"
load 'a_file.rb'

Once have built the cache, your application can be directed to use the cached files instead of the originals.

Why would I want to do this?

  1. You can put all of your application’s code under source control.
  2. Your application will become immune to external updates to the library or GEMs.
  3. Much easier deployment; just ship the application folder and its cache.
  4. You can ‘compile’1 your application and its libraries into a single .exe file using IronRuby and IronRubyAppPackager

Why should I not do this?

  1. It’s not the Ruby way
  2. Your application won’t benefit from external updates to the library or GEMs.

Not what you are looking for?

Try

How do I use it?

Vendorize has to get into the application early. Otherwise it won’t be able to spot files getting loaded. The most effective way to do this is to use the -r option on the command line before anything else gets a chance to load.

e.g.

ruby -I..\..\Vendorize\lib -rvendorize sinatra_app.rb

Note that Vendorize does not run as a Gem. It can’t, because then it would load after rubygems. You either need to place Vendorize.rb in your ‘site_ruby’, or provide the path to it, something like that shown above.

Other than that, you can then just run your application as normal and Vendorize will cache all the files that it sees getting loaded. You can run your application several times if you load different files depending on the situation – the files will just get added to the cache.

When you want to use the cache, the easy way is to switch from -rvendorize above to -rvendor_only.

i.e.

ruby -I..\..\Vendorize\lib -rvendor_only sinatra_app.rb

Issues

Vendorize finds files using the normal $LOAD_PATH mechanisms. If your application does strange and unusual things to this in order to trick the loading process, then there is a chance that you won’t cache the files that you are expecting. (You can probably work around this as explained in other pages.)

Requires that specify absolute paths or ‘.’ relative paths won’t be cached. This is not the Ruby way. You should probably be using code such as this to do such operations:

$LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..')
require 'myproject/test/test_helper'

Rubygems

Vendorize works with Rubygems and will add its dependencies to the cache if it is required. However you should find that you don’t need to run require 'rubygems' when using -rvendor_only because files will get loaded from the Vendorize cache.

Bundler

Vendorize works happily with Bundler. You should probably just stick to using Bundler though unless you are planning to use IronRubyAppPackager

License

Copyright © 2010-2011 David Lake (rifraf at rifraf.net)

Released under the MIT license. See LICENSE file for details.


1 As always, phrases that are ‘quoted’ should be interpreted as having the prefix ‘not’2. IronRubyAppPackager does not compile Ruby. It just looks like it’s compiled, and behaves like it’s compiled… Quack!

2 Recursively of course

About

Caches required/loaded files (from library or GEMs) into a _vendor_ subfolder. Can be used by IRPackager

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages