public
Description: Ruby on Rails
Homepage: http://rubyonrails.org
Clone URL: git://github.com/rails/rails.git
Search Repo:
Added that gems can now be plugins if they include rails/init.rb (closes 
#11444) [jbarnette]

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@9101 
5ecf4fe2-1ee6-0310-87b1-e25e094e27de
dhh (author)
Thu Mar 27 11:37:53 -0700 2008
commit  8301ce4d0b9de4423b74abf842faa6cf9e5aae1b
tree    e22d7df34571655992cd160d7cce829f980f820d
parent  60809439509e071d9c9a6b6f1b2051fa6902985a
...
1
2
 
 
3
4
5
...
1
2
3
4
5
6
7
0
@@ -1,5 +1,7 @@
0
 *SVN*
0
 
0
+* Added that gems can now be plugins if they include rails/init.rb #11444 [jbarnette]
0
+
0
 * Added Plugin#about method to programmatically access the about.yml in a plugin #10979 [lazyatom]
0
 
0
     plugin = Rails::Plugin.new(path_to_my_plugin)
...
43
44
45
 
46
47
48
...
43
44
45
46
47
48
49
0
@@ -43,6 +43,7 @@ module Rails
0
   class VendorBoot < Boot
0
     def load_initializer
0
       require "#{RAILS_ROOT}/vendor/rails/railties/lib/initializer"
0
+ Rails::Initializer.run(:install_gem_spec_stubs)
0
     end
0
   end
0
 
...
72
73
74
 
75
76
77
...
118
119
120
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
121
122
123
...
666
667
668
669
 
 
 
670
671
672
...
72
73
74
75
76
77
78
...
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
...
687
688
689
 
690
691
692
693
694
695
0
@@ -72,6 +72,7 @@ module Rails
0
       Rails.configuration = configuration
0
 
0
       check_ruby_version
0
+ install_gem_spec_stubs
0
       set_load_path
0
       
0
       require_frameworks
0
@@ -118,6 +119,26 @@ module Rails
0
       require 'ruby_version_check'
0
     end
0
 
0
+ # If Rails is vendored and RubyGems is available, install stub GemSpecs
0
+ # for Rails, ActiveSupport, ActiveRecord, ActionPack, ActionMailer, and
0
+ # ActiveResource. This allows Gem plugins to depend on Rails even when
0
+ # the Gem version of Rails shouldn't be loaded.
0
+ def install_gem_spec_stubs
0
+ if Rails.vendor_rails?
0
+ begin; require "rubygems"; rescue LoadError; return; end
0
+
0
+ stubs = %w(rails activesupport activerecord actionpack actionmailer activeresource)
0
+ stubs.reject! { |s| Gem.loaded_specs.key?(s) }
0
+
0
+ stubs.each do |stub|
0
+ Gem.loaded_specs[stub] = Gem::Specification.new do |s|
0
+ s.name = stub
0
+ s.version = Rails::VERSION::STRING
0
+ end
0
+ end
0
+ end
0
+ end
0
+
0
     # Set the <tt>$LOAD_PATH</tt> based on the value of
0
     # Configuration#load_paths. Duplicates are removed.
0
     def set_load_path
0
@@ -666,7 +687,9 @@ module Rails
0
       end
0
 
0
       def default_plugin_locators
0
- [Plugin::FileSystemLocator]
0
+ locators = []
0
+ locators << Plugin::GemLocator if defined? Gem
0
+ locators << Plugin::FileSystemLocator
0
       end
0
 
0
       def default_plugin_loader
...
97
98
99
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
100
101
...
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
0
@@ -97,4 +97,24 @@ module Rails
0
          end
0
       end
0
   end
0
+
0
+ # This Plugin subclass represents a Gem plugin. It behaves exactly like a
0
+ # "traditional" Rails plugin, but doesn't expose any additional load paths,
0
+ # since RubyGems has already taken care of things.
0
+ class GemPlugin < Plugin
0
+
0
+ # Initialize this plugin from a Gem::Specification.
0
+ def initialize(spec)
0
+ super(File.join(spec.full_gem_path, "rails"))
0
+ @name = spec.name
0
+ end
0
+
0
+ def valid?
0
+ true
0
+ end
0
+
0
+ def load_paths
0
+ []
0
+ end
0
+ end
0
 end
0
\ No newline at end of file
...
72
73
74
75
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
76
77
78
79
...
72
73
74
 
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
0
@@ -72,7 +72,26 @@ module Rails
0
             plugins
0
           end
0
         end
0
-
0
+ end
0
+
0
+ # The GemLocator scans all the loaded RubyGems, looking for gems with
0
+ # a <tt>rails/init.rb</tt> file.
0
+ class GemLocator < Locator
0
+ def plugins
0
+ specs = Gem.loaded_specs.values.select do |spec|
0
+ spec.loaded_from && # prune stubs
0
+ File.exist?(File.join(spec.full_gem_path, "rails", "init.rb"))
0
+ end
0
+
0
+ require "rubygems/dependency_list"
0
+
0
+ deps = Gem::DependencyList.new
0
+ deps.add(*specs)
0
+
0
+ deps.dependency_order.collect do |spec|
0
+ Rails::GemPlugin.new(spec)
0
+ end
0
+ end
0
     end
0
   end
0
 end
0
\ No newline at end of file

Comments

    No one has commented yet.