rails 2.2.2 → 2.3.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 (229) hide show
  1. data/CHANGELOG +274 -189
  2. data/MIT-LICENSE +1 -1
  3. data/README +6 -19
  4. data/Rakefile +24 -71
  5. data/bin/rails +1 -0
  6. data/builtin/rails_info/rails/info.rb +12 -8
  7. data/configs/databases/mysql.yml +3 -0
  8. data/configs/initializers/backtrace_silencers.rb +7 -0
  9. data/configs/initializers/new_rails_defaults.rb +2 -0
  10. data/configs/initializers/session_store.rb +15 -0
  11. data/dispatches/config.ru +7 -0
  12. data/doc/README_FOR_APP +2 -5
  13. data/environments/boot.rb +1 -0
  14. data/environments/environment.rb +14 -48
  15. data/environments/production.rb +11 -7
  16. data/environments/test.rb +6 -0
  17. data/helpers/application_controller.rb +10 -0
  18. data/helpers/test_helper.rb +1 -1
  19. data/html/500.html +0 -3
  20. data/html/index.html +1 -0
  21. data/lib/commands/about.rb +1 -1
  22. data/lib/commands/dbconsole.rb +18 -2
  23. data/lib/commands/plugin.rb +4 -3
  24. data/lib/commands/runner.rb +13 -7
  25. data/lib/commands/server.rb +98 -33
  26. data/lib/console_app.rb +4 -4
  27. data/lib/console_with_helpers.rb +2 -23
  28. data/lib/dispatcher.rb +1 -1
  29. data/lib/fcgi_handler.rb +12 -10
  30. data/lib/initializer.rb +108 -41
  31. data/lib/rails/backtrace_cleaner.rb +54 -0
  32. data/lib/rails/gem_dependency.rb +124 -93
  33. data/lib/rails/plugin.rb +49 -6
  34. data/lib/rails/plugin/loader.rb +66 -27
  35. data/lib/rails/plugin/locator.rb +1 -1
  36. data/lib/rails/rack.rb +3 -1
  37. data/lib/rails/rack/debugger.rb +21 -0
  38. data/lib/rails/rack/log_tailer.rb +35 -0
  39. data/lib/rails/rack/metal.rb +51 -0
  40. data/lib/rails/rack/static.rb +15 -4
  41. data/lib/rails/version.rb +1 -1
  42. data/lib/rails_generator/base.rb +3 -0
  43. data/lib/rails_generator/commands.rb +8 -3
  44. data/lib/rails_generator/generators/applications/app/app_generator.rb +210 -136
  45. data/lib/rails_generator/generators/applications/app/scm/git.rb +16 -0
  46. data/lib/rails_generator/generators/applications/app/scm/scm.rb +8 -0
  47. data/lib/rails_generator/generators/applications/app/scm/svn.rb +7 -0
  48. data/lib/rails_generator/generators/applications/app/template_runner.rb +401 -0
  49. data/lib/rails_generator/generators/components/controller/USAGE +12 -11
  50. data/lib/rails_generator/generators/components/controller/controller_generator.rb +7 -1
  51. data/lib/rails_generator/generators/components/controller/templates/helper_test.rb +4 -0
  52. data/lib/rails_generator/generators/components/helper/USAGE +24 -0
  53. data/lib/rails_generator/generators/components/helper/helper_generator.rb +25 -0
  54. data/lib/rails_generator/generators/components/helper/templates/helper.rb +2 -0
  55. data/lib/rails_generator/generators/components/helper/templates/helper_test.rb +4 -0
  56. data/lib/rails_generator/generators/components/metal/USAGE +8 -0
  57. data/lib/rails_generator/generators/components/metal/metal_generator.rb +8 -0
  58. data/lib/rails_generator/generators/components/metal/templates/metal.rb +12 -0
  59. data/lib/rails_generator/generators/components/resource/USAGE +2 -2
  60. data/lib/rails_generator/generators/components/resource/resource_generator.rb +2 -0
  61. data/lib/rails_generator/generators/components/resource/templates/helper_test.rb +4 -0
  62. data/lib/rails_generator/generators/components/scaffold/scaffold_generator.rb +2 -0
  63. data/lib/rails_generator/generators/components/scaffold/templates/controller.rb +1 -1
  64. data/lib/rails_generator/generators/components/scaffold/templates/functional_test.rb +4 -4
  65. data/lib/rails_generator/generators/components/scaffold/templates/helper_test.rb +4 -0
  66. data/lib/rails_generator/generators/components/scaffold/templates/layout.html.erb +1 -1
  67. data/lib/rails_generator/generators/components/scaffold/templates/view_edit.html.erb +2 -2
  68. data/lib/rails_generator/generators/components/scaffold/templates/view_index.html.erb +2 -2
  69. data/lib/rails_generator/generators/components/scaffold/templates/view_new.html.erb +2 -2
  70. data/lib/rails_generator/generators/components/scaffold/templates/view_show.html.erb +1 -1
  71. data/lib/rails_generator/secret_key_generator.rb +2 -0
  72. data/lib/tasks/databases.rake +13 -6
  73. data/lib/tasks/documentation.rake +2 -9
  74. data/lib/tasks/framework.rake +26 -1
  75. data/lib/tasks/gems.rake +33 -48
  76. data/lib/tasks/middleware.rake +7 -0
  77. data/lib/tasks/misc.rake +7 -0
  78. data/lib/tasks/statistics.rake +0 -1
  79. data/lib/tasks/testing.rake +5 -5
  80. data/lib/tasks/tmp.rake +2 -2
  81. data/lib/test_help.rb +16 -8
  82. metadata +36 -170
  83. data/bin/performance/request +0 -3
  84. data/bin/process/inspector +0 -3
  85. data/bin/process/reaper +0 -3
  86. data/bin/process/spawner +0 -3
  87. data/config.ru +0 -17
  88. data/configs/apache.conf +0 -40
  89. data/configs/lighttpd.conf +0 -54
  90. data/doc/guides/html/2_2_release_notes.html +0 -1185
  91. data/doc/guides/html/actioncontroller_basics.html +0 -1270
  92. data/doc/guides/html/activerecord_validations_callbacks.html +0 -749
  93. data/doc/guides/html/association_basics.html +0 -2585
  94. data/doc/guides/html/authors.html +0 -240
  95. data/doc/guides/html/benchmarking_and_profiling.html +0 -1018
  96. data/doc/guides/html/caching_with_rails.html +0 -583
  97. data/doc/guides/html/command_line.html +0 -434
  98. data/doc/guides/html/configuring.html +0 -438
  99. data/doc/guides/html/creating_plugins.html +0 -1594
  100. data/doc/guides/html/debugging_rails_applications.html +0 -1175
  101. data/doc/guides/html/finders.html +0 -1090
  102. data/doc/guides/html/form_helpers.html +0 -638
  103. data/doc/guides/html/getting_started_with_rails.html +0 -2066
  104. data/doc/guides/html/index.html +0 -349
  105. data/doc/guides/html/layouts_and_rendering.html +0 -1406
  106. data/doc/guides/html/migrations.html +0 -921
  107. data/doc/guides/html/routing_outside_in.html +0 -2213
  108. data/doc/guides/html/security.html +0 -1346
  109. data/doc/guides/html/testing_rails_applications.html +0 -1859
  110. data/doc/guides/source/2_2_release_notes.txt +0 -435
  111. data/doc/guides/source/actioncontroller_basics/changelog.txt +0 -5
  112. data/doc/guides/source/actioncontroller_basics/cookies.txt +0 -34
  113. data/doc/guides/source/actioncontroller_basics/csrf.txt +0 -32
  114. data/doc/guides/source/actioncontroller_basics/filters.txt +0 -119
  115. data/doc/guides/source/actioncontroller_basics/http_auth.txt +0 -24
  116. data/doc/guides/source/actioncontroller_basics/index.txt +0 -40
  117. data/doc/guides/source/actioncontroller_basics/introduction.txt +0 -9
  118. data/doc/guides/source/actioncontroller_basics/methods.txt +0 -39
  119. data/doc/guides/source/actioncontroller_basics/parameter_filtering.txt +0 -14
  120. data/doc/guides/source/actioncontroller_basics/params.txt +0 -93
  121. data/doc/guides/source/actioncontroller_basics/request_response_objects.txt +0 -43
  122. data/doc/guides/source/actioncontroller_basics/rescue.txt +0 -67
  123. data/doc/guides/source/actioncontroller_basics/session.txt +0 -187
  124. data/doc/guides/source/actioncontroller_basics/streaming.txt +0 -91
  125. data/doc/guides/source/actioncontroller_basics/verification.txt +0 -40
  126. data/doc/guides/source/active_record_basics.txt +0 -181
  127. data/doc/guides/source/activerecord_validations_callbacks.txt +0 -404
  128. data/doc/guides/source/association_basics.txt +0 -1840
  129. data/doc/guides/source/authors.txt +0 -39
  130. data/doc/guides/source/benchmarking_and_profiling/appendix.txt +0 -95
  131. data/doc/guides/source/benchmarking_and_profiling/digging_deeper.txt +0 -105
  132. data/doc/guides/source/benchmarking_and_profiling/edge_rails_features.txt +0 -185
  133. data/doc/guides/source/benchmarking_and_profiling/gameplan.txt +0 -27
  134. data/doc/guides/source/benchmarking_and_profiling/index.txt +0 -242
  135. data/doc/guides/source/benchmarking_and_profiling/rubyprof.txt +0 -179
  136. data/doc/guides/source/benchmarking_and_profiling/statistics.txt +0 -57
  137. data/doc/guides/source/caching_with_rails.txt +0 -367
  138. data/doc/guides/source/command_line.txt +0 -147
  139. data/doc/guides/source/configuring.txt +0 -225
  140. data/doc/guides/source/creating_plugins/acts_as_yaffle.txt +0 -191
  141. data/doc/guides/source/creating_plugins/appendix.txt +0 -46
  142. data/doc/guides/source/creating_plugins/controllers.txt +0 -59
  143. data/doc/guides/source/creating_plugins/core_ext.txt +0 -123
  144. data/doc/guides/source/creating_plugins/custom_route.txt +0 -69
  145. data/doc/guides/source/creating_plugins/gem.txt +0 -1
  146. data/doc/guides/source/creating_plugins/generator_method.txt +0 -89
  147. data/doc/guides/source/creating_plugins/helpers.txt +0 -51
  148. data/doc/guides/source/creating_plugins/index.txt +0 -52
  149. data/doc/guides/source/creating_plugins/migration_generator.txt +0 -156
  150. data/doc/guides/source/creating_plugins/models.txt +0 -76
  151. data/doc/guides/source/creating_plugins/odds_and_ends.txt +0 -69
  152. data/doc/guides/source/creating_plugins/test_setup.txt +0 -230
  153. data/doc/guides/source/debugging_rails_applications.txt +0 -733
  154. data/doc/guides/source/finders.txt +0 -668
  155. data/doc/guides/source/form_helpers.txt +0 -345
  156. data/doc/guides/source/getting_started_with_rails.txt +0 -1256
  157. data/doc/guides/source/images/belongs_to.png +0 -0
  158. data/doc/guides/source/images/bullet.gif +0 -0
  159. data/doc/guides/source/images/csrf.png +0 -0
  160. data/doc/guides/source/images/habtm.png +0 -0
  161. data/doc/guides/source/images/has_many.png +0 -0
  162. data/doc/guides/source/images/has_many_through.png +0 -0
  163. data/doc/guides/source/images/has_one.png +0 -0
  164. data/doc/guides/source/images/has_one_through.png +0 -0
  165. data/doc/guides/source/images/header_backdrop.png +0 -0
  166. data/doc/guides/source/images/icons/README +0 -5
  167. data/doc/guides/source/images/icons/callouts/1.png +0 -0
  168. data/doc/guides/source/images/icons/callouts/10.png +0 -0
  169. data/doc/guides/source/images/icons/callouts/11.png +0 -0
  170. data/doc/guides/source/images/icons/callouts/12.png +0 -0
  171. data/doc/guides/source/images/icons/callouts/13.png +0 -0
  172. data/doc/guides/source/images/icons/callouts/14.png +0 -0
  173. data/doc/guides/source/images/icons/callouts/15.png +0 -0
  174. data/doc/guides/source/images/icons/callouts/2.png +0 -0
  175. data/doc/guides/source/images/icons/callouts/3.png +0 -0
  176. data/doc/guides/source/images/icons/callouts/4.png +0 -0
  177. data/doc/guides/source/images/icons/callouts/5.png +0 -0
  178. data/doc/guides/source/images/icons/callouts/6.png +0 -0
  179. data/doc/guides/source/images/icons/callouts/7.png +0 -0
  180. data/doc/guides/source/images/icons/callouts/8.png +0 -0
  181. data/doc/guides/source/images/icons/callouts/9.png +0 -0
  182. data/doc/guides/source/images/icons/caution.png +0 -0
  183. data/doc/guides/source/images/icons/example.png +0 -0
  184. data/doc/guides/source/images/icons/home.png +0 -0
  185. data/doc/guides/source/images/icons/important.png +0 -0
  186. data/doc/guides/source/images/icons/next.png +0 -0
  187. data/doc/guides/source/images/icons/note.png +0 -0
  188. data/doc/guides/source/images/icons/prev.png +0 -0
  189. data/doc/guides/source/images/icons/tip.png +0 -0
  190. data/doc/guides/source/images/icons/up.png +0 -0
  191. data/doc/guides/source/images/icons/warning.png +0 -0
  192. data/doc/guides/source/images/polymorphic.png +0 -0
  193. data/doc/guides/source/images/rails_logo_remix.gif +0 -0
  194. data/doc/guides/source/images/ruby_on_rails_by_mike_rundle2.gif +0 -0
  195. data/doc/guides/source/images/session_fixation.png +0 -0
  196. data/doc/guides/source/index.txt +0 -118
  197. data/doc/guides/source/layouts_and_rendering.txt +0 -982
  198. data/doc/guides/source/migrations/anatomy_of_a_migration.txt +0 -85
  199. data/doc/guides/source/migrations/changelog.txt +0 -5
  200. data/doc/guides/source/migrations/creating_a_migration.txt +0 -109
  201. data/doc/guides/source/migrations/foreign_keys.txt +0 -8
  202. data/doc/guides/source/migrations/index.txt +0 -22
  203. data/doc/guides/source/migrations/rakeing_around.txt +0 -111
  204. data/doc/guides/source/migrations/scheming.txt +0 -47
  205. data/doc/guides/source/migrations/using_models_in_migrations.txt +0 -46
  206. data/doc/guides/source/migrations/writing_a_migration.txt +0 -159
  207. data/doc/guides/source/routing_outside_in.txt +0 -986
  208. data/doc/guides/source/security.txt +0 -984
  209. data/doc/guides/source/stylesheets/base.css +0 -358
  210. data/doc/guides/source/stylesheets/forms.css +0 -35
  211. data/doc/guides/source/stylesheets/more.css +0 -82
  212. data/doc/guides/source/templates/guides.html.erb +0 -97
  213. data/doc/guides/source/templates/inline.css +0 -165
  214. data/doc/guides/source/testing_rails_applications.txt +0 -995
  215. data/helpers/application.rb +0 -15
  216. data/lib/commands/performance/request.rb +0 -6
  217. data/lib/commands/process/inspector.rb +0 -68
  218. data/lib/commands/process/reaper.rb +0 -149
  219. data/lib/commands/process/spawner.rb +0 -219
  220. data/lib/commands/process/spinner.rb +0 -57
  221. data/lib/commands/servers/base.rb +0 -31
  222. data/lib/commands/servers/lighttpd.rb +0 -94
  223. data/lib/commands/servers/mongrel.rb +0 -69
  224. data/lib/commands/servers/new_mongrel.rb +0 -16
  225. data/lib/commands/servers/thin.rb +0 -25
  226. data/lib/commands/servers/webrick.rb +0 -66
  227. data/lib/rails/mongrel_server/commands.rb +0 -342
  228. data/lib/rails/mongrel_server/handler.rb +0 -55
  229. data/lib/rails/rack/logger.rb +0 -28
@@ -0,0 +1,54 @@
1
+ module Rails
2
+ class BacktraceCleaner < ActiveSupport::BacktraceCleaner
3
+ ERB_METHOD_SIG = /:in `_run_erb_.*/
4
+
5
+ RAILS_GEMS = %w( actionpack activerecord actionmailer activesupport activeresource rails )
6
+
7
+ VENDOR_DIRS = %w( vendor/rails )
8
+ SERVER_DIRS = %w( lib/mongrel bin/mongrel
9
+ lib/passenger bin/passenger-spawn-server
10
+ lib/rack )
11
+ RAILS_NOISE = %w( script/server )
12
+ RUBY_NOISE = %w( rubygems/custom_require benchmark.rb )
13
+
14
+ ALL_NOISE = VENDOR_DIRS + SERVER_DIRS + RAILS_NOISE + RUBY_NOISE
15
+
16
+ def initialize
17
+ super
18
+ add_filter { |line| line.sub("#{RAILS_ROOT}/", '') }
19
+ add_filter { |line| line.sub(ERB_METHOD_SIG, '') }
20
+ add_filter { |line| line.sub('./', '/') } # for tests
21
+
22
+ add_gem_filters
23
+
24
+ add_silencer { |line| ALL_NOISE.any? { |dir| line.include?(dir) } }
25
+ add_silencer { |line| RAILS_GEMS.any? { |gem| line =~ /^#{gem} / } }
26
+ add_silencer { |line| line =~ %r(vendor/plugins/[^\/]+/lib) }
27
+ end
28
+
29
+
30
+ private
31
+ def add_gem_filters
32
+ Gem.path.each do |path|
33
+ # http://gist.github.com/30430
34
+ add_filter { |line| line.sub(/(#{path})\/gems\/([a-z]+)-([0-9.]+)\/(.*)/, '\2 (\3) \4')}
35
+ end
36
+
37
+ vendor_gems_path = Rails::GemDependency.unpacked_path.sub("#{RAILS_ROOT}/",'')
38
+ add_filter { |line| line.sub(/(#{vendor_gems_path})\/([a-z]+)-([0-9.]+)\/(.*)/, '\2 (\3) [v] \4')}
39
+ end
40
+ end
41
+
42
+ # For installing the BacktraceCleaner in the test/unit
43
+ module BacktraceFilterForTestUnit #:nodoc:
44
+ def self.included(klass)
45
+ klass.send :alias_method_chain, :filter_backtrace, :cleaning
46
+ end
47
+
48
+ def filter_backtrace_with_cleaning(backtrace, prefix=nil)
49
+ backtrace = filter_backtrace_without_cleaning(backtrace, prefix)
50
+ backtrace = backtrace.first.split("\n") if backtrace.size == 1
51
+ Rails.backtrace_cleaner.clean(backtrace)
52
+ end
53
+ end
54
+ end
@@ -7,8 +7,8 @@ module Gem
7
7
  end
8
8
 
9
9
  module Rails
10
- class GemDependency
11
- attr_accessor :lib, :source
10
+ class GemDependency < Gem::Dependency
11
+ attr_accessor :lib, :source, :dep
12
12
 
13
13
  def self.unpacked_path
14
14
  @unpacked_path ||= File.join(RAILS_ROOT, 'vendor', 'gems')
@@ -29,18 +29,6 @@ module Rails
29
29
  end
30
30
  end
31
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
-
44
32
  def initialize(name, options = {})
45
33
  require 'rubygems' unless Object.const_defined?(:Gem)
46
34
 
@@ -52,10 +40,11 @@ module Rails
52
40
  req = Gem::Requirement.default
53
41
  end
54
42
 
55
- @dep = Gem::Dependency.new(name, req)
56
43
  @lib = options[:lib]
57
44
  @source = options[:source]
58
45
  @loaded = @frozen = @load_paths_added = false
46
+
47
+ super(name, req)
59
48
  end
60
49
 
61
50
  def add_load_paths
@@ -65,7 +54,7 @@ module Rails
65
54
  @load_paths_added = @loaded = @frozen = true
66
55
  return
67
56
  end
68
- gem @dep
57
+ gem self
69
58
  @spec = Gem.loaded_specs[name]
70
59
  @frozen = @spec.loaded_from.include?(self.class.unpacked_path) if @spec
71
60
  @load_paths_added = true
@@ -74,43 +63,67 @@ module Rails
74
63
 
75
64
  def dependencies
76
65
  return [] if framework_gem?
77
- all_dependencies = specification.dependencies.map do |dependency|
66
+ return [] unless installed?
67
+ specification.dependencies.reject do |dependency|
68
+ dependency.type == :development
69
+ end.map do |dependency|
78
70
  GemDependency.new(dependency.name, :requirement => dependency.version_requirements)
79
71
  end
80
- all_dependencies += all_dependencies.map(&:dependencies).flatten
81
- all_dependencies.uniq
82
72
  end
83
73
 
84
- def gem_dir(base_directory)
85
- File.join(base_directory, specification.full_name)
86
- end
87
-
88
- def spec_filename(base_directory)
89
- File.join(gem_dir(base_directory), '.specification')
74
+ def specification
75
+ # code repeated from Gem.activate. Find a matching spec, or the currently loaded version.
76
+ # error out if loaded version and requested version are incompatible.
77
+ @spec ||= begin
78
+ matches = Gem.source_index.search(self)
79
+ matches << @@framework_gems[name] if framework_gem?
80
+ if Gem.loaded_specs[name] then
81
+ # This gem is already loaded. If the currently loaded gem is not in the
82
+ # list of candidate gems, then we have a version conflict.
83
+ existing_spec = Gem.loaded_specs[name]
84
+ unless matches.any? { |spec| spec.version == existing_spec.version } then
85
+ raise Gem::Exception,
86
+ "can't activate #{@dep}, already activated #{existing_spec.full_name}"
87
+ end
88
+ # we're stuck with it, so change to match
89
+ version_requirements = Gem::Requirement.create("=#{existing_spec.version}")
90
+ existing_spec
91
+ else
92
+ # new load
93
+ matches.last
94
+ end
95
+ end
90
96
  end
91
97
 
92
- def load
93
- return if @loaded || @load_paths_added == false
94
- require(@lib || name) unless @lib == false
95
- @loaded = true
96
- rescue LoadError
97
- puts $!.to_s
98
- $!.backtrace.each { |b| puts b }
98
+ def requirement
99
+ r = version_requirements
100
+ (r == Gem::Requirement.default) ? nil : r
99
101
  end
100
102
 
101
- def name
102
- @dep.name.to_s
103
+ def built?
104
+ # TODO: If Rubygems ever gives us a way to detect this, we should use it
105
+ false
103
106
  end
104
107
 
105
- def requirement
106
- r = @dep.version_requirements
107
- (r == Gem::Requirement.default) ? nil : r
108
+ def framework_gem?
109
+ @@framework_gems.has_key?(name)
108
110
  end
109
111
 
110
112
  def frozen?
111
113
  @frozen ||= vendor_rails? || vendor_gem?
112
114
  end
113
115
 
116
+ def installed?
117
+ Gem.loaded_specs.keys.include?(name)
118
+ end
119
+
120
+ def load_paths_added?
121
+ # always try to add load paths - even if a gem is loaded, it may not
122
+ # be a compatible version (ie random_gem 0.4 is loaded and a later spec
123
+ # needs >= 0.5 - gem 'random_gem' will catch this and error out)
124
+ @load_paths_added
125
+ end
126
+
114
127
  def loaded?
115
128
  @loaded ||= begin
116
129
  if vendor_rails?
@@ -134,46 +147,49 @@ module Rails
134
147
  end
135
148
  end
136
149
 
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)
141
- @load_paths_added
150
+ def vendor_rails?
151
+ Gem.loaded_specs.has_key?(name) && Gem.loaded_specs[name].loaded_from.empty?
142
152
  end
143
153
 
144
- def install
145
- cmd = "#{gem_command} #{install_command.join(' ')}"
146
- puts cmd
147
- puts %x(#{cmd})
154
+ def vendor_gem?
155
+ specification && File.exists?(unpacked_gem_directory)
148
156
  end
149
157
 
150
- def unpack_to(directory)
151
- FileUtils.mkdir_p directory
152
- Dir.chdir directory do
153
- Gem::GemRunner.new.run(unpack_command)
158
+ def build
159
+ require 'rails/gem_builder'
160
+ unless built?
161
+ return unless File.exists?(unpacked_specification_filename)
162
+ spec = YAML::load_file(unpacked_specification_filename)
163
+ Rails::GemBuilder.new(spec, unpacked_gem_directory).build_extensions
164
+ puts "Built gem: '#{unpacked_gem_directory}'"
154
165
  end
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
-
166
+ dependencies.each { |dep| dep.build }
160
167
  end
161
168
 
162
- def write_spec(directory, spec)
163
- # copy the gem's specification into GEMDIR/.specification so that
164
- # we can access information about the gem on deployment systems
165
- # without having the gem installed
166
- File.open(spec_filename(directory), 'w') do |file|
167
- file.puts spec.to_yaml
169
+ def install
170
+ unless installed?
171
+ cmd = "#{gem_command} #{install_command.join(' ')}"
172
+ puts cmd
173
+ puts %x(#{cmd})
168
174
  end
169
175
  end
170
176
 
171
- def refresh_spec(directory)
177
+ def load
178
+ return if @loaded || @load_paths_added == false
179
+ require(@lib || name) unless @lib == false
180
+ @loaded = true
181
+ rescue LoadError
182
+ puts $!.to_s
183
+ $!.backtrace.each { |b| puts b }
184
+ end
185
+
186
+ def refresh
187
+ Rails::VendorGemSourceIndex.silence_spec_warnings = true
172
188
  real_gems = Gem.source_index.installed_source_index
173
189
  exact_dep = Gem::Dependency.new(name, "= #{specification.version}")
174
190
  matches = real_gems.search(exact_dep)
175
191
  installed_spec = matches.first
176
- if File.exist?(File.dirname(spec_filename(directory)))
192
+ if frozen?
177
193
  if installed_spec
178
194
  # we have a real copy
179
195
  # get a fresh spec - matches should only have one element
@@ -181,11 +197,11 @@ module Rails
181
197
  # spec is the same as the copy from real_gems - Gem.activate changes
182
198
  # some of the fields
183
199
  real_spec = Gem::Specification.load(matches.first.loaded_from)
184
- write_spec(directory, real_spec)
200
+ write_specification(real_spec)
185
201
  puts "Reloaded specification for #{name} from installed gems."
186
202
  else
187
203
  # the gem isn't installed locally - write out our current specs
188
- write_spec(directory, specification)
204
+ write_specification(specification)
189
205
  puts "Gem #{name} not loaded locally - writing out current spec."
190
206
  end
191
207
  else
@@ -197,42 +213,44 @@ module Rails
197
213
  end
198
214
  end
199
215
 
200
- def ==(other)
201
- self.name == other.name && self.requirement == other.requirement
216
+ def unpack(options={})
217
+ unless frozen? || framework_gem?
218
+ FileUtils.mkdir_p unpack_base
219
+ Dir.chdir unpack_base do
220
+ Gem::GemRunner.new.run(unpack_command)
221
+ end
222
+ # Gem.activate changes the spec - get the original
223
+ real_spec = Gem::Specification.load(specification.loaded_from)
224
+ write_specification(real_spec)
225
+ end
226
+ dependencies.each { |dep| dep.unpack } if options[:recursive]
202
227
  end
203
- alias_method :"eql?", :"=="
204
228
 
205
- def hash
206
- @dep.hash
229
+ def write_specification(spec)
230
+ # copy the gem's specification into GEMDIR/.specification so that
231
+ # we can access information about the gem on deployment systems
232
+ # without having the gem installed
233
+ File.open(unpacked_specification_filename, 'w') do |file|
234
+ file.puts spec.to_yaml
235
+ end
207
236
  end
208
237
 
209
- def specification
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
238
+ def ==(other)
239
+ self.name == other.name && self.requirement == other.requirement
231
240
  end
241
+ alias_method :"eql?", :"=="
232
242
 
233
243
  private
244
+
234
245
  def gem_command
235
- RUBY_PLATFORM =~ /win32/ ? 'gem.bat' : 'gem'
246
+ case RUBY_PLATFORM
247
+ when /win32/
248
+ 'gem.bat'
249
+ when /java/
250
+ 'jruby -S gem'
251
+ else
252
+ 'gem'
253
+ end
236
254
  end
237
255
 
238
256
  def install_command
@@ -247,5 +265,18 @@ module Rails
247
265
  cmd << "--version" << "= "+specification.version.to_s if requirement
248
266
  cmd
249
267
  end
268
+
269
+ def unpack_base
270
+ Rails::GemDependency.unpacked_path
271
+ end
272
+
273
+ def unpacked_gem_directory
274
+ File.join(unpack_base, specification.full_name)
275
+ end
276
+
277
+ def unpacked_specification_filename
278
+ File.join(unpacked_gem_directory, '.specification')
279
+ end
280
+
250
281
  end
251
282
  end
data/lib/rails/plugin.rb CHANGED
@@ -28,15 +28,19 @@ module Rails
28
28
  end
29
29
 
30
30
  def valid?
31
- File.directory?(directory) && (has_lib_directory? || has_init_file?)
31
+ File.directory?(directory) && (has_app_directory? || has_lib_directory? || has_init_file?)
32
32
  end
33
33
 
34
34
  # Returns a list of paths this plugin wishes to make available in <tt>$LOAD_PATH</tt>.
35
35
  def load_paths
36
36
  report_nonexistant_or_empty_plugin! unless valid?
37
- has_lib_directory? ? [lib_path] : []
37
+
38
+ returning [] do |load_paths|
39
+ load_paths << lib_path if has_lib_directory?
40
+ load_paths << app_paths if has_app_directory?
41
+ end.flatten
38
42
  end
39
-
43
+
40
44
  # Evaluates a plugin's init.rb file.
41
45
  def load(initializer)
42
46
  return if loaded?
@@ -56,7 +60,35 @@ module Rails
56
60
  def about
57
61
  @about ||= load_about_information
58
62
  end
63
+
64
+ # Engines are plugins with an app/ directory.
65
+ def engine?
66
+ has_app_directory?
67
+ end
68
+
69
+ # Returns true if the engine ships with a routing file
70
+ def routed?
71
+ File.exist?(routing_file)
72
+ end
73
+
74
+
75
+ def view_path
76
+ File.join(directory, 'app', 'views')
77
+ end
78
+
79
+ def controller_path
80
+ File.join(directory, 'app', 'controllers')
81
+ end
82
+
83
+ def metal_path
84
+ File.join(directory, 'app', 'metal')
85
+ end
86
+
87
+ def routing_file
88
+ File.join(directory, 'config', 'routes.rb')
89
+ end
59
90
 
91
+
60
92
  private
61
93
  def load_about_information
62
94
  about_yml_path = File.join(@directory, "about.yml")
@@ -68,8 +100,13 @@ module Rails
68
100
 
69
101
  def report_nonexistant_or_empty_plugin!
70
102
  raise LoadError, "Can not find the plugin named: #{name}"
71
- end
72
-
103
+ end
104
+
105
+
106
+ def app_paths
107
+ [ File.join(directory, 'app', 'models'), File.join(directory, 'app', 'helpers'), controller_path, metal_path ]
108
+ end
109
+
73
110
  def lib_path
74
111
  File.join(directory, 'lib')
75
112
  end
@@ -86,6 +123,11 @@ module Rails
86
123
  File.file?(gem_init_path) ? gem_init_path : classic_init_path
87
124
  end
88
125
 
126
+
127
+ def has_app_directory?
128
+ File.directory?(File.join(directory, 'app'))
129
+ end
130
+
89
131
  def has_lib_directory?
90
132
  File.directory?(lib_path)
91
133
  end
@@ -94,6 +136,7 @@ module Rails
94
136
  File.file?(init_path)
95
137
  end
96
138
 
139
+
97
140
  def evaluate_init_rb(initializer)
98
141
  if has_init_file?
99
142
  silence_warnings do
@@ -121,4 +164,4 @@ module Rails
121
164
  File.join(directory, 'rails', 'init.rb')
122
165
  end
123
166
  end
124
- end
167
+ end