rails 2.1.2 → 2.2.2

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of rails might be problematic. Click here for more details.

Files changed (221) hide show
  1. data/CHANGELOG +27 -3
  2. data/Rakefile +70 -10
  3. data/bin/about +0 -0
  4. data/bin/console +0 -0
  5. data/bin/destroy +0 -0
  6. data/bin/generate +0 -0
  7. data/bin/performance/benchmarker +0 -0
  8. data/bin/performance/profiler +0 -0
  9. data/bin/performance/request +0 -0
  10. data/bin/plugin +0 -0
  11. data/bin/process/inspector +0 -0
  12. data/bin/process/reaper +0 -0
  13. data/bin/process/spawner +0 -0
  14. data/bin/runner +0 -0
  15. data/bin/server +0 -0
  16. data/config.ru +17 -0
  17. data/configs/apache.conf +0 -0
  18. data/configs/databases/ibm_db.yml +62 -0
  19. data/configs/databases/mysql.yml +3 -0
  20. data/configs/databases/postgresql.yml +3 -0
  21. data/configs/databases/sqlite2.yml +3 -0
  22. data/configs/databases/sqlite3.yml +3 -0
  23. data/configs/locales/en.yml +5 -0
  24. data/dispatches/dispatch.fcgi +1 -1
  25. data/dispatches/dispatch.rb +2 -2
  26. data/dispatches/gateway.cgi +2 -2
  27. data/doc/README_FOR_APP +5 -2
  28. data/doc/guides/html/2_2_release_notes.html +1185 -0
  29. data/doc/guides/html/actioncontroller_basics.html +1270 -0
  30. data/doc/guides/html/activerecord_validations_callbacks.html +749 -0
  31. data/doc/guides/html/association_basics.html +2585 -0
  32. data/doc/guides/html/authors.html +240 -0
  33. data/doc/guides/html/benchmarking_and_profiling.html +1018 -0
  34. data/doc/guides/html/caching_with_rails.html +583 -0
  35. data/doc/guides/html/command_line.html +434 -0
  36. data/doc/guides/html/configuring.html +438 -0
  37. data/doc/guides/html/creating_plugins.html +1594 -0
  38. data/doc/guides/html/debugging_rails_applications.html +1175 -0
  39. data/doc/guides/html/finders.html +1090 -0
  40. data/doc/guides/html/form_helpers.html +638 -0
  41. data/doc/guides/html/getting_started_with_rails.html +2066 -0
  42. data/doc/guides/html/index.html +349 -0
  43. data/doc/guides/html/layouts_and_rendering.html +1406 -0
  44. data/doc/guides/html/migrations.html +921 -0
  45. data/doc/guides/html/routing_outside_in.html +2213 -0
  46. data/doc/guides/html/security.html +1346 -0
  47. data/doc/guides/html/testing_rails_applications.html +1859 -0
  48. data/doc/guides/source/2_2_release_notes.txt +435 -0
  49. data/doc/guides/source/actioncontroller_basics/changelog.txt +5 -0
  50. data/doc/guides/source/actioncontroller_basics/cookies.txt +34 -0
  51. data/doc/guides/source/actioncontroller_basics/csrf.txt +32 -0
  52. data/doc/guides/source/actioncontroller_basics/filters.txt +119 -0
  53. data/doc/guides/source/actioncontroller_basics/http_auth.txt +24 -0
  54. data/doc/guides/source/actioncontroller_basics/index.txt +40 -0
  55. data/doc/guides/source/actioncontroller_basics/introduction.txt +9 -0
  56. data/doc/guides/source/actioncontroller_basics/methods.txt +39 -0
  57. data/doc/guides/source/actioncontroller_basics/parameter_filtering.txt +14 -0
  58. data/doc/guides/source/actioncontroller_basics/params.txt +93 -0
  59. data/doc/guides/source/actioncontroller_basics/request_response_objects.txt +43 -0
  60. data/doc/guides/source/actioncontroller_basics/rescue.txt +67 -0
  61. data/doc/guides/source/actioncontroller_basics/session.txt +187 -0
  62. data/doc/guides/source/actioncontroller_basics/streaming.txt +91 -0
  63. data/doc/guides/source/actioncontroller_basics/verification.txt +40 -0
  64. data/doc/guides/source/active_record_basics.txt +181 -0
  65. data/doc/guides/source/activerecord_validations_callbacks.txt +404 -0
  66. data/doc/guides/source/association_basics.txt +1840 -0
  67. data/doc/guides/source/authors.txt +39 -0
  68. data/doc/guides/source/benchmarking_and_profiling/appendix.txt +95 -0
  69. data/doc/guides/source/benchmarking_and_profiling/digging_deeper.txt +105 -0
  70. data/doc/guides/source/benchmarking_and_profiling/edge_rails_features.txt +185 -0
  71. data/doc/guides/source/benchmarking_and_profiling/gameplan.txt +27 -0
  72. data/doc/guides/source/benchmarking_and_profiling/index.txt +242 -0
  73. data/doc/guides/source/benchmarking_and_profiling/rubyprof.txt +179 -0
  74. data/doc/guides/source/benchmarking_and_profiling/statistics.txt +57 -0
  75. data/doc/guides/source/caching_with_rails.txt +367 -0
  76. data/doc/guides/source/command_line.txt +147 -0
  77. data/doc/guides/source/configuring.txt +225 -0
  78. data/doc/guides/source/creating_plugins/acts_as_yaffle.txt +191 -0
  79. data/doc/guides/source/creating_plugins/appendix.txt +46 -0
  80. data/doc/guides/source/creating_plugins/controllers.txt +59 -0
  81. data/doc/guides/source/creating_plugins/core_ext.txt +123 -0
  82. data/doc/guides/source/creating_plugins/custom_route.txt +69 -0
  83. data/doc/guides/source/creating_plugins/gem.txt +1 -0
  84. data/doc/guides/source/creating_plugins/generator_method.txt +89 -0
  85. data/doc/guides/source/creating_plugins/helpers.txt +51 -0
  86. data/doc/guides/source/creating_plugins/index.txt +52 -0
  87. data/doc/guides/source/creating_plugins/migration_generator.txt +156 -0
  88. data/doc/guides/source/creating_plugins/models.txt +76 -0
  89. data/doc/guides/source/creating_plugins/odds_and_ends.txt +69 -0
  90. data/doc/guides/source/creating_plugins/test_setup.txt +230 -0
  91. data/doc/guides/source/debugging_rails_applications.txt +733 -0
  92. data/doc/guides/source/finders.txt +668 -0
  93. data/doc/guides/source/form_helpers.txt +345 -0
  94. data/doc/guides/source/getting_started_with_rails.txt +1256 -0
  95. data/doc/guides/source/images/belongs_to.png +0 -0
  96. data/doc/guides/source/images/bullet.gif +0 -0
  97. data/doc/guides/source/images/csrf.png +0 -0
  98. data/doc/guides/source/images/habtm.png +0 -0
  99. data/doc/guides/source/images/has_many.png +0 -0
  100. data/doc/guides/source/images/has_many_through.png +0 -0
  101. data/doc/guides/source/images/has_one.png +0 -0
  102. data/doc/guides/source/images/has_one_through.png +0 -0
  103. data/doc/guides/source/images/header_backdrop.png +0 -0
  104. data/doc/guides/source/images/icons/README +5 -0
  105. data/doc/guides/source/images/icons/callouts/1.png +0 -0
  106. data/doc/guides/source/images/icons/callouts/10.png +0 -0
  107. data/doc/guides/source/images/icons/callouts/11.png +0 -0
  108. data/doc/guides/source/images/icons/callouts/12.png +0 -0
  109. data/doc/guides/source/images/icons/callouts/13.png +0 -0
  110. data/doc/guides/source/images/icons/callouts/14.png +0 -0
  111. data/doc/guides/source/images/icons/callouts/15.png +0 -0
  112. data/doc/guides/source/images/icons/callouts/2.png +0 -0
  113. data/doc/guides/source/images/icons/callouts/3.png +0 -0
  114. data/doc/guides/source/images/icons/callouts/4.png +0 -0
  115. data/doc/guides/source/images/icons/callouts/5.png +0 -0
  116. data/doc/guides/source/images/icons/callouts/6.png +0 -0
  117. data/doc/guides/source/images/icons/callouts/7.png +0 -0
  118. data/doc/guides/source/images/icons/callouts/8.png +0 -0
  119. data/doc/guides/source/images/icons/callouts/9.png +0 -0
  120. data/doc/guides/source/images/icons/caution.png +0 -0
  121. data/doc/guides/source/images/icons/example.png +0 -0
  122. data/doc/guides/source/images/icons/home.png +0 -0
  123. data/doc/guides/source/images/icons/important.png +0 -0
  124. data/doc/guides/source/images/icons/next.png +0 -0
  125. data/doc/guides/source/images/icons/note.png +0 -0
  126. data/doc/guides/source/images/icons/prev.png +0 -0
  127. data/doc/guides/source/images/icons/tip.png +0 -0
  128. data/doc/guides/source/images/icons/up.png +0 -0
  129. data/doc/guides/source/images/icons/warning.png +0 -0
  130. data/doc/guides/source/images/polymorphic.png +0 -0
  131. data/doc/guides/source/images/rails_logo_remix.gif +0 -0
  132. data/doc/guides/source/images/ruby_on_rails_by_mike_rundle2.gif +0 -0
  133. data/doc/guides/source/images/session_fixation.png +0 -0
  134. data/doc/guides/source/index.txt +118 -0
  135. data/doc/guides/source/layouts_and_rendering.txt +982 -0
  136. data/doc/guides/source/migrations/anatomy_of_a_migration.txt +85 -0
  137. data/doc/guides/source/migrations/changelog.txt +5 -0
  138. data/doc/guides/source/migrations/creating_a_migration.txt +109 -0
  139. data/doc/guides/source/migrations/foreign_keys.txt +8 -0
  140. data/doc/guides/source/migrations/index.txt +22 -0
  141. data/doc/guides/source/migrations/rakeing_around.txt +111 -0
  142. data/doc/guides/source/migrations/scheming.txt +47 -0
  143. data/doc/guides/source/migrations/using_models_in_migrations.txt +46 -0
  144. data/doc/guides/source/migrations/writing_a_migration.txt +159 -0
  145. data/doc/guides/source/routing_outside_in.txt +986 -0
  146. data/doc/guides/source/security.txt +984 -0
  147. data/doc/guides/source/stylesheets/base.css +358 -0
  148. data/doc/guides/source/stylesheets/forms.css +35 -0
  149. data/doc/guides/source/stylesheets/more.css +82 -0
  150. data/doc/guides/source/templates/guides.html.erb +97 -0
  151. data/doc/guides/source/templates/inline.css +165 -0
  152. data/doc/guides/source/testing_rails_applications.txt +995 -0
  153. data/environments/boot.rb +2 -2
  154. data/environments/environment.rb +9 -1
  155. data/environments/production.rb +3 -1
  156. data/helpers/performance_test.rb +9 -0
  157. data/html/500.html +4 -1
  158. data/html/javascripts/controls.js +72 -72
  159. data/html/javascripts/dragdrop.js +165 -164
  160. data/html/javascripts/effects.js +173 -165
  161. data/html/javascripts/prototype.js +362 -267
  162. data/lib/commands/console.rb +13 -0
  163. data/lib/commands/dbconsole.rb +2 -2
  164. data/lib/commands/ncgi/listener +2 -2
  165. data/lib/commands/ncgi/tracker +2 -2
  166. data/lib/commands/plugin.rb +41 -24
  167. data/lib/commands/process/spawner.rb +4 -4
  168. data/lib/commands/runner.rb +1 -1
  169. data/lib/commands/server.rb +11 -1
  170. data/lib/commands/servers/thin.rb +25 -0
  171. data/lib/fcgi_handler.rb +1 -3
  172. data/lib/initializer.rb +162 -39
  173. data/lib/performance_test_help.rb +5 -0
  174. data/lib/rails/gem_builder.rb +3 -3
  175. data/lib/rails/gem_dependency.rb +155 -33
  176. data/lib/rails/mongrel_server/commands.rb +1 -1
  177. data/lib/rails/plugin.rb +10 -2
  178. data/lib/rails/rack.rb +6 -0
  179. data/lib/rails/rack/logger.rb +28 -0
  180. data/lib/rails/rack/static.rb +35 -0
  181. data/lib/rails/vendor_gem_source_index.rb +140 -0
  182. data/lib/rails/version.rb +1 -1
  183. data/lib/rails_generator/commands.rb +10 -16
  184. data/lib/rails_generator/generated_attribute.rb +4 -0
  185. data/lib/rails_generator/generators/applications/app/app_generator.rb +9 -3
  186. data/lib/rails_generator/generators/components/controller/controller_generator.rb +1 -1
  187. data/lib/rails_generator/generators/components/controller/templates/functional_test.rb +1 -1
  188. data/lib/rails_generator/generators/components/integration_test/integration_test_generator.rb +1 -1
  189. data/lib/rails_generator/generators/components/integration_test/templates/integration_test.rb +2 -2
  190. data/lib/rails_generator/generators/components/mailer/mailer_generator.rb +1 -1
  191. data/lib/rails_generator/generators/components/mailer/templates/unit_test.rb +2 -3
  192. data/lib/rails_generator/generators/components/model/model_generator.rb +1 -1
  193. data/lib/rails_generator/generators/components/model/templates/model.rb +3 -0
  194. data/lib/rails_generator/generators/components/model/templates/unit_test.rb +1 -1
  195. data/lib/rails_generator/generators/components/observer/observer_generator.rb +1 -1
  196. data/lib/rails_generator/generators/components/observer/templates/unit_test.rb +1 -1
  197. data/lib/rails_generator/generators/components/performance_test/USAGE +8 -0
  198. data/lib/rails_generator/generators/components/performance_test/performance_test_generator.rb +16 -0
  199. data/lib/rails_generator/generators/components/performance_test/templates/performance_test.rb +9 -0
  200. data/lib/rails_generator/generators/components/plugin/plugin_generator.rb +11 -11
  201. data/lib/rails_generator/generators/components/plugin/templates/Rakefile +1 -0
  202. data/lib/rails_generator/generators/components/plugin/templates/test_helper.rb +3 -0
  203. data/lib/rails_generator/generators/components/plugin/templates/unit_test.rb +4 -4
  204. data/lib/rails_generator/generators/components/resource/resource_generator.rb +2 -2
  205. data/lib/rails_generator/generators/components/resource/templates/functional_test.rb +1 -1
  206. data/lib/rails_generator/generators/components/scaffold/USAGE +9 -5
  207. data/lib/rails_generator/generators/components/scaffold/scaffold_generator.rb +10 -3
  208. data/lib/rails_generator/generators/components/scaffold/templates/functional_test.rb +7 -7
  209. data/lib/rails_generator/scripts.rb +1 -1
  210. data/lib/rails_generator/scripts/destroy.rb +6 -7
  211. data/lib/rails_generator/secret_key_generator.rb +5 -147
  212. data/lib/tasks/annotations.rake +8 -11
  213. data/lib/tasks/databases.rake +42 -15
  214. data/lib/tasks/documentation.rake +15 -0
  215. data/lib/tasks/framework.rake +5 -1
  216. data/lib/tasks/gems.rake +24 -8
  217. data/lib/tasks/misc.rake +3 -4
  218. data/lib/tasks/testing.rake +25 -4
  219. data/lib/test_help.rb +1 -2
  220. data/lib/webrick_server.rb +2 -11
  221. metadata +165 -9
@@ -0,0 +1,5 @@
1
+ require 'action_controller/performance_test'
2
+
3
+ ActionController::Base.perform_caching = true
4
+ ActiveSupport::Dependencies.mechanism = :require
5
+ Rails.logger.level = ActiveSupport::BufferedLogger::INFO
@@ -12,10 +12,10 @@ module Rails
12
12
  @spec = spec
13
13
  @gem_dir = gem_dir
14
14
  end
15
-
15
+
16
16
  # silence the underlying builder
17
17
  def say(message)
18
18
  end
19
-
19
+
20
20
  end
21
- end
21
+ end
@@ -1,50 +1,79 @@
1
+ require 'rails/vendor_gem_source_index'
2
+
3
+ module Gem
4
+ def self.source_index=(index)
5
+ @@source_index = index
6
+ end
7
+ end
8
+
1
9
  module Rails
2
10
  class GemDependency
3
- attr_accessor :name, :requirement, :version, :lib, :source
11
+ attr_accessor :lib, :source
4
12
 
5
13
  def self.unpacked_path
6
14
  @unpacked_path ||= File.join(RAILS_ROOT, 'vendor', 'gems')
7
15
  end
8
16
 
17
+ @@framework_gems = {}
18
+
19
+ def self.add_frozen_gem_path
20
+ @@paths_loaded ||= begin
21
+ source_index = Rails::VendorGemSourceIndex.new(Gem.source_index)
22
+ Gem.clear_paths
23
+ Gem.source_index = source_index
24
+ # loaded before us - we can't change them, so mark them
25
+ Gem.loaded_specs.each do |name, spec|
26
+ @@framework_gems[name] = spec
27
+ end
28
+ true
29
+ end
30
+ end
31
+
32
+ def framework_gem?
33
+ @@framework_gems.has_key?(name)
34
+ end
35
+
36
+ def vendor_rails?
37
+ Gem.loaded_specs.has_key?(name) && Gem.loaded_specs[name].loaded_from.empty?
38
+ end
39
+
40
+ def vendor_gem?
41
+ Gem.loaded_specs.has_key?(name) && Gem.loaded_specs[name].loaded_from.include?(self.class.unpacked_path)
42
+ end
43
+
9
44
  def initialize(name, options = {})
10
45
  require 'rubygems' unless Object.const_defined?(:Gem)
11
46
 
12
47
  if options[:requirement]
13
- @requirement = options[:requirement]
48
+ req = options[:requirement]
14
49
  elsif options[:version]
15
- @requirement = Gem::Requirement.create(options[:version])
50
+ req = Gem::Requirement.create(options[:version])
51
+ else
52
+ req = Gem::Requirement.default
16
53
  end
17
54
 
18
- @version = @requirement.instance_variable_get("@requirements").first.last if @requirement
19
- @name = name.to_s
55
+ @dep = Gem::Dependency.new(name, req)
20
56
  @lib = options[:lib]
21
57
  @source = options[:source]
22
58
  @loaded = @frozen = @load_paths_added = false
23
- @unpack_directory = nil
24
- end
25
-
26
- def unpacked_paths
27
- Dir[File.join(self.class.unpacked_path, "#{@name}-#{@version || "*"}")]
28
59
  end
29
60
 
30
61
  def add_load_paths
62
+ self.class.add_frozen_gem_path
31
63
  return if @loaded || @load_paths_added
32
- unpacked_paths = self.unpacked_paths
33
- if unpacked_paths.empty?
34
- args = [@name]
35
- args << @requirement.to_s if @requirement
36
- gem *args
37
- else
38
- $LOAD_PATH.unshift File.join(unpacked_paths.first, 'lib')
39
- ext = File.join(unpacked_paths.first, 'ext')
40
- $LOAD_PATH.unshift(ext) if File.exist?(ext)
41
- @frozen = true
64
+ if framework_gem?
65
+ @load_paths_added = @loaded = @frozen = true
66
+ return
42
67
  end
68
+ gem @dep
69
+ @spec = Gem.loaded_specs[name]
70
+ @frozen = @spec.loaded_from.include?(self.class.unpacked_path) if @spec
43
71
  @load_paths_added = true
44
72
  rescue Gem::LoadError
45
73
  end
46
74
 
47
75
  def dependencies
76
+ return [] if framework_gem?
48
77
  all_dependencies = specification.dependencies.map do |dependency|
49
78
  GemDependency.new(dependency.name, :requirement => dependency.version_requirements)
50
79
  end
@@ -56,24 +85,59 @@ module Rails
56
85
  File.join(base_directory, specification.full_name)
57
86
  end
58
87
 
88
+ def spec_filename(base_directory)
89
+ File.join(gem_dir(base_directory), '.specification')
90
+ end
91
+
59
92
  def load
60
93
  return if @loaded || @load_paths_added == false
61
- require(@lib || @name) unless @lib == false
94
+ require(@lib || name) unless @lib == false
62
95
  @loaded = true
63
96
  rescue LoadError
64
97
  puts $!.to_s
65
98
  $!.backtrace.each { |b| puts b }
66
99
  end
67
100
 
101
+ def name
102
+ @dep.name.to_s
103
+ end
104
+
105
+ def requirement
106
+ r = @dep.version_requirements
107
+ (r == Gem::Requirement.default) ? nil : r
108
+ end
109
+
68
110
  def frozen?
69
- @frozen
111
+ @frozen ||= vendor_rails? || vendor_gem?
70
112
  end
71
113
 
72
114
  def loaded?
73
- @loaded
115
+ @loaded ||= begin
116
+ if vendor_rails?
117
+ true
118
+ elsif specification.nil?
119
+ false
120
+ else
121
+ # check if the gem is loaded by inspecting $"
122
+ # specification.files lists all the files contained in the gem
123
+ gem_files = specification.files
124
+ # select only the files contained in require_paths - typically in bin and lib
125
+ require_paths_regexp = Regexp.new("^(#{specification.require_paths*'|'})/")
126
+ gem_lib_files = gem_files.select { |f| require_paths_regexp.match(f) }
127
+ # chop the leading directory off - a typical file might be in
128
+ # lib/gem_name/file_name.rb, but it will be 'require'd as gem_name/file_name.rb
129
+ gem_lib_files.map! { |f| f.split('/', 2)[1] }
130
+ # if any of the files from the above list appear in $", the gem is assumed to
131
+ # have been loaded
132
+ !(gem_lib_files & $").empty?
133
+ end
134
+ end
74
135
  end
75
136
 
76
137
  def load_paths_added?
138
+ # always try to add load paths - even if a gem is loaded, it may not
139
+ # be a compatible version (ie random_gem 0.4 is loaded and a later spec
140
+ # needs >= 0.5 - gem 'random_gem' will catch this and error out)
77
141
  @load_paths_added
78
142
  end
79
143
 
@@ -89,21 +153,81 @@ module Rails
89
153
  Gem::GemRunner.new.run(unpack_command)
90
154
  end
91
155
 
156
+ # Gem.activate changes the spec - get the original
157
+ real_spec = Gem::Specification.load(specification.loaded_from)
158
+ write_spec(directory, real_spec)
159
+
160
+ end
161
+
162
+ def write_spec(directory, spec)
92
163
  # copy the gem's specification into GEMDIR/.specification so that
93
164
  # we can access information about the gem on deployment systems
94
165
  # without having the gem installed
95
- spec_filename = File.join(gem_dir(directory), '.specification')
96
- File.open(spec_filename, 'w') do |file|
97
- file.puts specification.to_yaml
166
+ File.open(spec_filename(directory), 'w') do |file|
167
+ file.puts spec.to_yaml
168
+ end
169
+ end
170
+
171
+ def refresh_spec(directory)
172
+ real_gems = Gem.source_index.installed_source_index
173
+ exact_dep = Gem::Dependency.new(name, "= #{specification.version}")
174
+ matches = real_gems.search(exact_dep)
175
+ installed_spec = matches.first
176
+ if File.exist?(File.dirname(spec_filename(directory)))
177
+ if installed_spec
178
+ # we have a real copy
179
+ # get a fresh spec - matches should only have one element
180
+ # note that there is no reliable method to check that the loaded
181
+ # spec is the same as the copy from real_gems - Gem.activate changes
182
+ # some of the fields
183
+ real_spec = Gem::Specification.load(matches.first.loaded_from)
184
+ write_spec(directory, real_spec)
185
+ puts "Reloaded specification for #{name} from installed gems."
186
+ else
187
+ # the gem isn't installed locally - write out our current specs
188
+ write_spec(directory, specification)
189
+ puts "Gem #{name} not loaded locally - writing out current spec."
190
+ end
191
+ else
192
+ if framework_gem?
193
+ puts "Gem directory for #{name} not found - check if it's loading before rails."
194
+ else
195
+ puts "Something bad is going on - gem directory not found for #{name}."
196
+ end
98
197
  end
99
198
  end
100
199
 
101
200
  def ==(other)
102
201
  self.name == other.name && self.requirement == other.requirement
103
202
  end
203
+ alias_method :"eql?", :"=="
204
+
205
+ def hash
206
+ @dep.hash
207
+ end
104
208
 
105
209
  def specification
106
- @spec ||= Gem.source_index.search(Gem::Dependency.new(@name, @requirement)).sort_by { |s| s.version }.last
210
+ # code repeated from Gem.activate. Find a matching spec, or the currently loaded version.
211
+ # error out if loaded version and requested version are incompatible.
212
+ @spec ||= begin
213
+ matches = Gem.source_index.search(@dep)
214
+ matches << @@framework_gems[name] if framework_gem?
215
+ if Gem.loaded_specs[name] then
216
+ # This gem is already loaded. If the currently loaded gem is not in the
217
+ # list of candidate gems, then we have a version conflict.
218
+ existing_spec = Gem.loaded_specs[name]
219
+ unless matches.any? { |spec| spec.version == existing_spec.version } then
220
+ raise Gem::Exception,
221
+ "can't activate #{@dep}, already activated #{existing_spec.full_name}"
222
+ end
223
+ # we're stuck with it, so change to match
224
+ @dep.version_requirements = Gem::Requirement.create("=#{existing_spec.version}")
225
+ existing_spec
226
+ else
227
+ # new load
228
+ matches.last
229
+ end
230
+ end
107
231
  end
108
232
 
109
233
  private
@@ -112,17 +236,15 @@ module Rails
112
236
  end
113
237
 
114
238
  def install_command
115
- cmd = %w(install) << @name
116
- cmd << "--version" << %("#{@requirement.to_s}") if @requirement
239
+ cmd = %w(install) << name
240
+ cmd << "--version" << %("#{requirement.to_s}") if requirement
117
241
  cmd << "--source" << @source if @source
118
242
  cmd
119
243
  end
120
244
 
121
245
  def unpack_command
122
- cmd = %w(unpack) << @name
123
- # We don't quote this requirement as it's run through GemRunner instead
124
- # of shelling out to gem
125
- cmd << "--version" << @requirement.to_s if @requirement
246
+ cmd = %w(unpack) << name
247
+ cmd << "--version" << "= "+specification.version.to_s if requirement
126
248
  cmd
127
249
  end
128
250
  end
@@ -44,7 +44,7 @@ module Rails
44
44
  env_location = "#{defaults[:cwd]}/config/environment"
45
45
  require env_location
46
46
 
47
- ActionController::AbstractRequest.relative_url_root = defaults[:prefix]
47
+ ActionController::Base.relative_url_root = defaults[:prefix]
48
48
  uri prefix, :handler => Rails::MongrelServer::RailsHandler.new
49
49
  end
50
50
  end
@@ -74,10 +74,18 @@ module Rails
74
74
  File.join(directory, 'lib')
75
75
  end
76
76
 
77
- def init_path
77
+ def classic_init_path
78
78
  File.join(directory, 'init.rb')
79
79
  end
80
80
 
81
+ def gem_init_path
82
+ File.join(directory, 'rails', 'init.rb')
83
+ end
84
+
85
+ def init_path
86
+ File.file?(gem_init_path) ? gem_init_path : classic_init_path
87
+ end
88
+
81
89
  def has_lib_directory?
82
90
  File.directory?(lib_path)
83
91
  end
@@ -104,7 +112,7 @@ module Rails
104
112
  class GemPlugin < Plugin
105
113
  # Initialize this plugin from a Gem::Specification.
106
114
  def initialize(spec, gem)
107
- directory = (gem.frozen? && gem.unpacked_paths.first) || File.join(spec.full_gem_path)
115
+ directory = spec.full_gem_path
108
116
  super(directory)
109
117
  @name = spec.name
110
118
  end
@@ -0,0 +1,6 @@
1
+ module Rails
2
+ module Rack
3
+ autoload :Logger, "rails/rack/logger"
4
+ autoload :Static, "rails/rack/static"
5
+ end
6
+ end
@@ -0,0 +1,28 @@
1
+ module Rails
2
+ module Rack
3
+ class Logger
4
+ EnvironmentLog = "#{File.expand_path(Rails.root)}/log/#{Rails.env}.log"
5
+
6
+ def initialize(app, log = nil)
7
+ @app = app
8
+ @path = Pathname.new(log || EnvironmentLog).cleanpath
9
+ @cursor = ::File.size(@path)
10
+ @last_checked = Time.now
11
+ end
12
+
13
+ def call(env)
14
+ response = @app.call(env)
15
+ ::File.open(@path, 'r') do |f|
16
+ f.seek @cursor
17
+ if f.mtime > @last_checked
18
+ contents = f.read
19
+ @last_checked = f.mtime
20
+ @cursor += contents.length
21
+ print contents
22
+ end
23
+ end
24
+ response
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,35 @@
1
+ module Rails
2
+ module Rack
3
+ class Static
4
+ FILE_METHODS = %w(GET HEAD).freeze
5
+
6
+ def initialize(app)
7
+ @app = app
8
+ @file_server = ::Rack::File.new(File.join(RAILS_ROOT, "public"))
9
+ end
10
+
11
+ def call(env)
12
+ path = env['PATH_INFO'].chomp('/')
13
+ method = env['REQUEST_METHOD']
14
+ cached_path = (path.empty? ? 'index' : path) + ::ActionController::Base.page_cache_extension
15
+
16
+ if FILE_METHODS.include?(method)
17
+ if file_exist?(path)
18
+ return @file_server.call(env)
19
+ elsif file_exist?(cached_path)
20
+ env['PATH_INFO'] = cached_path
21
+ return @file_server.call(env)
22
+ end
23
+ end
24
+
25
+ @app.call(env)
26
+ end
27
+
28
+ private
29
+ def file_exist?(path)
30
+ full_path = File.join(@file_server.root, ::Rack::Utils.unescape(path))
31
+ File.file?(full_path) && File.readable?(full_path)
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,140 @@
1
+ require 'rubygems'
2
+ require 'yaml'
3
+
4
+ module Rails
5
+
6
+ class VendorGemSourceIndex
7
+ # VendorGemSourceIndex acts as a proxy for the Gem source index, allowing
8
+ # gems to be loaded from vendor/gems. Rather than the standard gem repository format,
9
+ # vendor/gems contains unpacked gems, with YAML specifications in .specification in
10
+ # each gem directory.
11
+ include Enumerable
12
+
13
+ attr_reader :installed_source_index
14
+ attr_reader :vendor_source_index
15
+
16
+ @@silence_spec_warnings = false
17
+
18
+ def self.silence_spec_warnings
19
+ @@silence_spec_warnings
20
+ end
21
+
22
+ def self.silence_spec_warnings=(v)
23
+ @@silence_spec_warnings = v
24
+ end
25
+
26
+ def initialize(installed_index, vendor_dir=Rails::GemDependency.unpacked_path)
27
+ @installed_source_index = installed_index
28
+ @vendor_dir = vendor_dir
29
+ refresh!
30
+ end
31
+
32
+ def refresh!
33
+ # reload the installed gems
34
+ @installed_source_index.refresh!
35
+ vendor_gems = {}
36
+
37
+ # handle vendor Rails gems - they are identified by having loaded_from set to ""
38
+ # we add them manually to the list, so that other gems can find them via dependencies
39
+ Gem.loaded_specs.each do |n, s|
40
+ next unless s.loaded_from.empty?
41
+ vendor_gems[s.full_name] = s
42
+ end
43
+
44
+ # load specifications from vendor/gems
45
+ Dir[File.join(Rails::GemDependency.unpacked_path, '*')].each do |d|
46
+ dir_name = File.basename(d)
47
+ dir_version = version_for_dir(dir_name)
48
+ spec = load_specification(d)
49
+ if spec
50
+ if spec.full_name != dir_name
51
+ # mismatched directory name and gem spec - produced by 2.1.0-era unpack code
52
+ if dir_version
53
+ # fix the spec version - this is not optimal (spec.files may be wrong)
54
+ # but it's better than breaking apps. Complain to remind users to get correct specs.
55
+ # use ActiveSupport::Deprecation.warn, as the logger is not set yet
56
+ $stderr.puts("config.gem: Unpacked gem #{dir_name} in vendor/gems has a mismatched specification file."+
57
+ " Run 'rake gems:refresh_specs' to fix this.") unless @@silence_spec_warnings
58
+ spec.version = dir_version
59
+ else
60
+ $stderr.puts("config.gem: Unpacked gem #{dir_name} in vendor/gems is not in a versioned directory"+
61
+ "(should be #{spec.full_name}).") unless @@silence_spec_warnings
62
+ # continue, assume everything is OK
63
+ end
64
+ end
65
+ else
66
+ # no spec - produced by early-2008 unpack code
67
+ # emulate old behavior, and complain.
68
+ $stderr.puts("config.gem: Unpacked gem #{dir_name} in vendor/gems has no specification file."+
69
+ " Run 'rake gems:refresh_specs' to fix this.") unless @@silence_spec_warnings
70
+ if dir_version
71
+ spec = Gem::Specification.new
72
+ spec.version = dir_version
73
+ spec.require_paths = ['lib']
74
+ ext_path = File.join(d, 'ext')
75
+ spec.require_paths << 'ext' if File.exist?(ext_path)
76
+ spec.name = /^(.*)-[^-]+$/.match(dir_name)[1]
77
+ files = ['lib']
78
+ # set files to everything in lib/
79
+ files += Dir[File.join(d, 'lib', '*')].map { |v| v.gsub(/^#{d}\//, '') }
80
+ files += Dir[File.join(d, 'ext', '*')].map { |v| v.gsub(/^#{d}\//, '') } if ext_path
81
+ spec.files = files
82
+ else
83
+ $stderr.puts("config.gem: Unpacked gem #{dir_name} in vendor/gems not in a versioned directory."+
84
+ " Giving up.") unless @@silence_spec_warnings
85
+ next
86
+ end
87
+ end
88
+ spec.loaded_from = File.join(d, '.specification')
89
+ # finally, swap out full_gem_path
90
+ # it would be better to use a Gem::Specification subclass, but the YAML loads an explicit class
91
+ class << spec
92
+ def full_gem_path
93
+ path = File.join installation_path, full_name
94
+ return path if File.directory? path
95
+ File.join installation_path, original_name
96
+ end
97
+ end
98
+ vendor_gems[File.basename(d)] = spec
99
+ end
100
+ @vendor_source_index = Gem::SourceIndex.new(vendor_gems)
101
+ end
102
+
103
+ def version_for_dir(d)
104
+ matches = /-([^-]+)$/.match(d)
105
+ Gem::Version.new(matches[1]) if matches
106
+ end
107
+
108
+ def load_specification(gem_dir)
109
+ spec_file = File.join(gem_dir, '.specification')
110
+ YAML.load_file(spec_file) if File.exist?(spec_file)
111
+ end
112
+
113
+ def find_name(*args)
114
+ @installed_source_index.find_name(*args) + @vendor_source_index.find_name(*args)
115
+ end
116
+
117
+ def search(*args)
118
+ # look for vendor gems, and then installed gems - later elements take priority
119
+ @installed_source_index.search(*args) + @vendor_source_index.search(*args)
120
+ end
121
+
122
+ def each(&block)
123
+ @vendor_source_index.each(&block)
124
+ @installed_source_index.each(&block)
125
+ end
126
+
127
+ def add_spec(spec)
128
+ @vendor_source_index.add_spec spec
129
+ end
130
+
131
+ def remove_spec(spec)
132
+ @vendor_source_index.remove_spec spec
133
+ end
134
+
135
+ def size
136
+ @vendor_source_index.size + @installed_source_index.size
137
+ end
138
+
139
+ end
140
+ end