public
Description: Ruby on Rails
Homepage: http://rubyonrails.org
Clone URL: git://github.com/rails/rails.git
Added config.gem for specifying which gems are required by the application, as 
well as rake tasks for installing and freezing gems. [rick]

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@9140 
5ecf4fe2-1ee6-0310-87b1-e25e094e27de
technoweenie (author)
Sat Mar 29 19:17:28 -0700 2008
commit  088ef182e3006294b8f0e9b185d272a777c4437a
tree    11b760af7a23bb5280f5aef5dc61350d0ea302f1
parent  81286f858770e0b95e15af37f19156b044ec6a95
...
1
2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3
4
5
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
0
@@ -1,5 +1,22 @@
0
 *SVN*
0
 
0
+* Added config.gem for specifying which gems are required by the application, as well as rake tasks for installing and freezing gems. [rick]
0
+
0
+  Rails::Initializer.run do |config|
0
+    config.gems "bj"
0
+    config.gems "hpricot", :version => '0.6', :source => "http://code.whytheluckystiff.net"
0
+    config.gems "aws-s3", :lib => "aws/s3"
0
+  end
0
+  
0
+  # List required gems.
0
+  rake gems
0
+  
0
+  # Install all required gems:
0
+  rake gems:install
0
+  
0
+  # Unpack specified gem to vendor/gems/gem_name-x.x.x
0
+  rake gems:unpack GEM=bj
0
+
0
 * Removed the default .htaccess configuration as there are so many good deployment options now (kept it as an example in README) [DHH]
0
 
0
 * config.time_zone accepts TZInfo::Timezone identifiers as well as Rails TimeZone identifiers [Geoff Buesing]
...
7
8
9
 
10
11
12
...
77
78
79
 
80
81
82
...
98
99
100
 
101
102
103
104
105
...
185
186
187
 
 
 
 
 
 
 
 
 
 
 
188
189
190
...
229
230
231
232
 
 
 
 
 
233
234
235
...
494
495
496
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
497
498
499
...
529
530
531
 
532
533
534
...
712
713
714
 
 
 
 
715
716
717
...
7
8
9
10
11
12
13
...
78
79
80
81
82
83
84
...
100
101
102
103
104
 
105
106
107
...
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
...
242
243
244
 
245
246
247
248
249
250
251
252
...
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
...
565
566
567
568
569
570
571
...
749
750
751
752
753
754
755
756
757
758
0
@@ -7,6 +7,7 @@ require 'railties_path'
0
 require 'rails/version'
0
 require 'rails/plugin/locator'
0
 require 'rails/plugin/loader'
0
+require 'rails/gem_dependency'
0
 
0
 
0
 RAILS_ENV = (ENV['RAILS_ENV'] || 'development').dup unless defined?(RAILS_ENV)
0
@@ -77,6 +78,7 @@ module Rails
0
       
0
       require_frameworks
0
       set_autoload_paths
0
+      add_gem_load_paths
0
       add_plugin_load_paths
0
       load_environment
0
 
0
@@ -98,8 +100,8 @@ module Rails
0
 
0
       add_support_load_paths
0
 
0
+      load_gems
0
       load_plugins
0
-
0
       load_application_initializers
0
 
0
       # the framework is now fully initialized
0
@@ -185,6 +187,17 @@ module Rails
0
       plugin_loader.add_plugin_load_paths
0
     end
0
 
0
+    def add_gem_load_paths
0
+      unless @configuration.gems.empty?
0
+        require "rubygems"
0
+        @configuration.gems.each &:add_load_paths
0
+      end
0
+    end
0
+
0
+    def load_gems
0
+      @configuration.gems.each &:load
0
+    end
0
+
0
     # Loads all plugins in <tt>config.plugin_paths</tt>.  <tt>plugin_paths</tt>
0
     # defaults to <tt>vendor/plugins</tt> but may also be set to a list of
0
     # paths, such as
0
@@ -229,7 +242,11 @@ module Rails
0
 
0
     def load_observers
0
       if configuration.frameworks.include?(:active_record)
0
-        ActiveRecord::Base.instantiate_observers
0
+        if @configuration.gems.any? { |g| !g.loaded? }
0
+          puts "Unable to instantiate observers, some gems that this application depends on are missing.  Run 'rake gems:install'"
0
+        else
0
+          ActiveRecord::Base.instantiate_observers
0
+        end
0
       end
0
     end
0
 
0
@@ -494,6 +511,25 @@ module Rails
0
     # a sub class would have access to fine grained modification of the loading behavior. See
0
     # the implementation of Rails::Plugin::Loader for more details.
0
     attr_accessor :plugin_loader
0
+
0
+    # An array of gems that this rails application depends on.  Rails will automatically load
0
+    # these gems during installation, and allow you to install any missing gems with:
0
+    #
0
+    #   rake gems:install
0
+    #
0
+    # You can add with the #gem method.
0
+    attr_accessor :gems
0
+
0
+    # Adds a single Gem dependency to the rails application.
0
+    #
0
+    #   # gem 'aws-s3', '>= 0.4.0'
0
+    #   # require 'aws/s3'
0
+    #   config.gem 'aws-s3', :lib => 'aws/s3', :version => '>= 0.4.0', \
0
+    #     :source => "http://code.whytheluckystiff.net"
0
+    #
0
+    def gem(name, options = {})
0
+      @gems << Rails::GemDependency.new(name, options)
0
+    end
0
     
0
     # Deprecated options:
0
     def breakpoint_server(_ = nil)
0
@@ -529,6 +565,7 @@ module Rails
0
       self.plugin_locators              = default_plugin_locators
0
       self.plugin_loader                = default_plugin_loader
0
       self.database_configuration_file  = default_database_configuration_file
0
+      self.gems                         = default_gems
0
 
0
       for framework in default_frameworks
0
         self.send("#{framework}=", Rails::OrderedOptions.new)
0
@@ -712,6 +749,10 @@ module Rails
0
           :memory_store
0
         end
0
       end
0
+      
0
+      def default_gems
0
+        []
0
+      end
0
   end
0
 end
0
 

Comments