public Method

Kernel.dependency(name, *ver)

Note that this new version tries to load the file via ROOT/gems first before moving off to the system gems (so if you have a lower version of a gem in ROOT/gems, it’ll still get loaded)

Source Code

# File merb/core_ext/kernel.rb, line 9
def dependency(name, *ver)
  begin
    # If it's not in ROOT/gems, skip to the next attempt
    raise LoadError unless File.directory?(Merb.root / "gems")

    # cache the gem path
    begin
      # Clear out the paths and reset them to Merb
      Gem.use_paths(Merb.root / "gems", [Merb.root / "gems"])

      # Try activating the gem (Failure will raise a LoadError)
      Gem.activate(name, true, *ver)
      Merb.logger.info("#{Time.now.httpdate}: loading gem '#{name}' from #{__app_file_trace__.first} ...")
    ensure
      # Either way, set the gem path back to normal
      Gem.clear_paths
    end

  # If we couldn't load the gem or there was no ROOT/gems, try again, now with the full gem path
  rescue LoadError
    begin
      # Try activating again
      Gem.activate(name, true, *ver)
      Merb.logger.info("#{Time.now.httpdate}: loading gem '#{name}' from #{__app_file_trace__.first} ...")
    rescue LoadError
      # Failed requiring as a gem, let's try loading with a normal require.
      require name
    end
  end
end
Comments

Have your say
Please use Textile formatting (click here for a cheat sheet). Use <code/> and <pre/> for code samples.
Click here to login with OpenID to to post comments.