Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Changeset 9140

Show
Ignore:
Timestamp:
03/30/08 02:17:28 (2 months ago)
Author:
rick
Message:

Added config.gem for specifying which gems are required by the application, as well as rake tasks for installing and freezing gems. [rick]

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/railties/CHANGELOG

    r9134 r9140  
    11*SVN* 
     2 
     3* Added config.gem for specifying which gems are required by the application, as well as rake tasks for installing and freezing gems. [rick] 
     4 
     5  Rails::Initializer.run do |config| 
     6    config.gems "bj" 
     7    config.gems "hpricot", :version => '0.6', :source => "http://code.whytheluckystiff.net" 
     8    config.gems "aws-s3", :lib => "aws/s3" 
     9  end 
     10   
     11  # List required gems. 
     12  rake gems 
     13   
     14  # Install all required gems: 
     15  rake gems:install 
     16   
     17  # Unpack specified gem to vendor/gems/gem_name-x.x.x 
     18  rake gems:unpack GEM=bj 
    219 
    320* Removed the default .htaccess configuration as there are so many good deployment options now (kept it as an example in README) [DHH] 
  • trunk/railties/lib/initializer.rb

    r9108 r9140  
    88require 'rails/plugin/locator' 
    99require 'rails/plugin/loader' 
     10require 'rails/gem_dependency' 
    1011 
    1112 
     
    7879      require_frameworks 
    7980      set_autoload_paths 
     81      add_gem_load_paths 
    8082      add_plugin_load_paths 
    8183      load_environment 
     
    99101      add_support_load_paths 
    100102 
     103      load_gems 
    101104      load_plugins 
    102  
    103105      load_application_initializers 
    104106 
     
    184186    def add_plugin_load_paths 
    185187      plugin_loader.add_plugin_load_paths 
     188    end 
     189 
     190    def add_gem_load_paths 
     191      unless @configuration.gems.empty? 
     192        require "rubygems" 
     193        @configuration.gems.each &:add_load_paths 
     194      end 
     195    end 
     196 
     197    def load_gems 
     198      @configuration.gems.each &:load 
    186199    end 
    187200 
     
    230243    def load_observers 
    231244      if configuration.frameworks.include?(:active_record) 
    232         ActiveRecord::Base.instantiate_observers 
     245        if @configuration.gems.any? { |g| !g.loaded? } 
     246          puts "Unable to instantiate observers, some gems that this application depends on are missing.  Run 'rake gems:install'" 
     247        else 
     248          ActiveRecord::Base.instantiate_observers 
     249        end 
    233250      end 
    234251    end 
     
    495512    # the implementation of Rails::Plugin::Loader for more details. 
    496513    attr_accessor :plugin_loader 
     514 
     515    # An array of gems that this rails application depends on.  Rails will automatically load 
     516    # these gems during installation, and allow you to install any missing gems with: 
     517    # 
     518    #   rake gems:install 
     519    # 
     520    # You can add with the #gem method. 
     521    attr_accessor :gems 
     522 
     523    # Adds a single Gem dependency to the rails application. 
     524    # 
     525    #   # gem 'aws-s3', '>= 0.4.0' 
     526    #   # require 'aws/s3' 
     527    #   config.gem 'aws-s3', :lib => 'aws/s3', :version => '>= 0.4.0', \ 
     528    #     :source => "http://code.whytheluckystiff.net" 
     529    # 
     530    def gem(name, options = {}) 
     531      @gems << Rails::GemDependency.new(name, options) 
     532    end 
    497533     
    498534    # Deprecated options: 
     
    530566      self.plugin_loader                = default_plugin_loader 
    531567      self.database_configuration_file  = default_database_configuration_file 
     568      self.gems                         = default_gems 
    532569 
    533570      for framework in default_frameworks 
     
    713750        end 
    714751      end 
     752       
     753      def default_gems 
     754        [] 
     755      end 
    715756  end 
    716757end