rails 2.2.3 → 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 +272 -191
  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 -94
  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 +2 -2
  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 +92 -159
  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
@@ -16,52 +16,91 @@ module Rails
16
16
  def initialize(initializer)
17
17
  @initializer = initializer
18
18
  end
19
-
19
+
20
20
  # Returns the plugins to be loaded, in the order they should be loaded.
21
21
  def plugins
22
22
  @plugins ||= all_plugins.select { |plugin| should_load?(plugin) }.sort { |p1, p2| order_plugins(p1, p2) }
23
23
  end
24
24
 
25
+ # Returns the plugins that are in engine-form (have an app/ directory)
26
+ def engines
27
+ @engines ||= plugins.select(&:engine?)
28
+ end
29
+
25
30
  # Returns all the plugins that could be found by the current locators.
26
31
  def all_plugins
27
32
  @all_plugins ||= locate_plugins
28
33
  @all_plugins
29
34
  end
30
-
35
+
31
36
  def load_plugins
32
- plugins.each do |plugin|
37
+ plugins.each do |plugin|
33
38
  plugin.load(initializer)
34
39
  register_plugin_as_loaded(plugin)
35
40
  end
41
+
42
+ configure_engines
43
+
36
44
  ensure_all_registered_plugins_are_loaded!
37
45
  end
38
-
46
+
39
47
  # Adds the load paths for every plugin into the $LOAD_PATH. Plugin load paths are
40
48
  # added *after* the application's <tt>lib</tt> directory, to ensure that an application
41
49
  # can always override code within a plugin.
42
50
  #
43
- # Plugin load paths are also added to Dependencies.load_paths, and Dependencies.load_once_paths.
51
+ # Plugin load paths are also added to Dependencies.load_paths, and Dependencies.load_once_paths.
44
52
  def add_plugin_load_paths
45
53
  plugins.each do |plugin|
46
54
  plugin.load_paths.each do |path|
47
55
  $LOAD_PATH.insert(application_lib_index + 1, path)
48
- ActiveSupport::Dependencies.load_paths << path
49
- unless Rails.configuration.reload_plugins?
56
+
57
+ ActiveSupport::Dependencies.load_paths << path
58
+
59
+ unless configuration.reload_plugins?
50
60
  ActiveSupport::Dependencies.load_once_paths << path
51
61
  end
52
62
  end
53
63
  end
64
+
54
65
  $LOAD_PATH.uniq!
55
- end
56
-
66
+ end
67
+
68
+ def engine_metal_paths
69
+ engines.collect(&:metal_path)
70
+ end
71
+
57
72
  protected
58
-
73
+ def configure_engines
74
+ if engines.any?
75
+ add_engine_routing_configurations
76
+ add_engine_controller_paths
77
+ add_engine_view_paths
78
+ end
79
+ end
80
+
81
+ def add_engine_routing_configurations
82
+ engines.select(&:routed?).collect(&:routing_file).each do |routing_file|
83
+ ActionController::Routing::Routes.add_configuration_file(routing_file)
84
+ end
85
+ end
86
+
87
+ def add_engine_controller_paths
88
+ ActionController::Routing.controller_paths += engines.collect(&:controller_path)
89
+ end
90
+
91
+ def add_engine_view_paths
92
+ # reverse it such that the last engine can overwrite view paths from the first, like with routes
93
+ paths = ActionView::PathSet.new(engines.collect(&:view_path).reverse)
94
+ ActionController::Base.view_paths.concat(paths)
95
+ ActionMailer::Base.view_paths.concat(paths) if configuration.frameworks.include?(:action_mailer)
96
+ end
97
+
59
98
  # The locate_plugins method uses each class in config.plugin_locators to
60
99
  # find the set of all plugins available to this Rails application.
61
100
  def locate_plugins
62
- configuration.plugin_locators.map { |locator|
101
+ configuration.plugin_locators.map do |locator|
63
102
  locator.new(initializer).plugins
64
- }.flatten
103
+ end.flatten
65
104
  # TODO: sorting based on config.plugins
66
105
  end
67
106
 
@@ -72,7 +111,7 @@ module Rails
72
111
  def configuration
73
112
  initializer.configuration
74
113
  end
75
-
114
+
76
115
  def should_load?(plugin)
77
116
  # uses Plugin#name and Plugin#valid?
78
117
  enabled?(plugin) && plugin.valid?
@@ -86,21 +125,21 @@ module Rails
86
125
  plugin_a <=> plugin_b
87
126
  else
88
127
  effective_order_of(plugin_a) <=> effective_order_of(plugin_b)
89
- end
128
+ end
90
129
  end
91
130
  end
92
-
131
+
93
132
  def effective_order_of(plugin)
94
133
  if explicitly_enabled?(plugin)
95
- registered_plugin_names.index(plugin.name)
134
+ registered_plugin_names.index(plugin.name)
96
135
  else
97
136
  registered_plugin_names.index('all')
98
- end
137
+ end
99
138
  end
100
139
 
101
140
  def application_lib_index
102
141
  $LOAD_PATH.index(File.join(RAILS_ROOT, 'lib')) || 0
103
- end
142
+ end
104
143
 
105
144
  def enabled?(plugin)
106
145
  !explicit_plugin_loading_order? || registered?(plugin)
@@ -121,32 +160,32 @@ module Rails
121
160
  def explicitly_registered?(plugin)
122
161
  explicit_plugin_loading_order? && registered_plugin_names.include?(plugin.name)
123
162
  end
124
-
163
+
125
164
  def registered_plugins_names_plugin?(plugin)
126
165
  registered_plugin_names.include?(plugin.name) || registered_plugin_names.include?('all')
127
166
  end
128
-
167
+
129
168
  # The plugins that have been explicitly listed with config.plugins. If this list is nil
130
- # then it means the client does not care which plugins or in what order they are loaded,
169
+ # then it means the client does not care which plugins or in what order they are loaded,
131
170
  # so we load all in alphabetical order. If it is an empty array, we load no plugins, if it is
132
171
  # non empty, we load the named plugins in the order specified.
133
172
  def registered_plugin_names
134
173
  configuration.plugins ? configuration.plugins.map(&:to_s) : nil
135
174
  end
136
-
175
+
137
176
  def loaded?(plugin_name)
138
177
  initializer.loaded_plugins.detect { |plugin| plugin.name == plugin_name.to_s }
139
178
  end
140
-
179
+
141
180
  def ensure_all_registered_plugins_are_loaded!
142
181
  if explicit_plugin_loading_order?
143
182
  if configuration.plugins.detect {|plugin| plugin != :all && !loaded?(plugin) }
144
- missing_plugins = configuration.plugins - (plugins + [:all])
145
- raise LoadError, "Could not locate the following plugins: #{missing_plugins.to_sentence}"
183
+ missing_plugins = configuration.plugins - (plugins.map{|p| p.name.to_sym} + [:all])
184
+ raise LoadError, "Could not locate the following plugins: #{missing_plugins.to_sentence(:locale => :en)}"
146
185
  end
147
186
  end
148
187
  end
149
-
188
+
150
189
  end
151
190
  end
152
- end
191
+ end
@@ -30,7 +30,7 @@ module Rails
30
30
  end
31
31
 
32
32
  # The Rails::Plugin::FileSystemLocator will try to locate plugins by examining the directories
33
- # the the paths given in configuration.plugin_paths. Any plugins that can be found are returned
33
+ # in the paths given in configuration.plugin_paths. Any plugins that can be found are returned
34
34
  # in a list.
35
35
  #
36
36
  # The criteria for a valid plugin in this case is found in Rails::Plugin#valid?, although
@@ -1,6 +1,8 @@
1
1
  module Rails
2
2
  module Rack
3
- autoload :Logger, "rails/rack/logger"
3
+ autoload :Debugger, "rails/rack/debugger"
4
+ autoload :LogTailer, "rails/rack/log_tailer"
5
+ autoload :Metal, "rails/rack/metal"
4
6
  autoload :Static, "rails/rack/static"
5
7
  end
6
8
  end
@@ -0,0 +1,21 @@
1
+ module Rails
2
+ module Rack
3
+ class Debugger
4
+ def initialize(app)
5
+ @app = app
6
+
7
+ require_library_or_gem 'ruby-debug'
8
+ ::Debugger.start
9
+ ::Debugger.settings[:autoeval] = true if ::Debugger.respond_to?(:settings)
10
+ puts "=> Debugger enabled"
11
+ rescue Exception
12
+ puts "You need to install ruby-debug to run the server in debugging mode. With gems, use 'gem install ruby-debug'"
13
+ exit
14
+ end
15
+
16
+ def call(env)
17
+ @app.call(env)
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,35 @@
1
+ module Rails
2
+ module Rack
3
+ class LogTailer
4
+ EnvironmentLog = "#{File.expand_path(Rails.root)}/log/#{Rails.env}.log"
5
+
6
+ def initialize(app, log = nil)
7
+ @app = app
8
+
9
+ path = Pathname.new(log || EnvironmentLog).cleanpath
10
+ @cursor = ::File.size(path)
11
+ @last_checked = Time.now.to_f
12
+
13
+ @file = ::File.open(path, 'r')
14
+ end
15
+
16
+ def call(env)
17
+ response = @app.call(env)
18
+ tail_log
19
+ response
20
+ end
21
+
22
+ def tail_log
23
+ @file.seek @cursor
24
+
25
+ mod = @file.mtime.to_f
26
+ if mod > @last_checked
27
+ contents = @file.read
28
+ @last_checked = mod
29
+ @cursor += contents.size
30
+ $stdout.print contents
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,51 @@
1
+ require 'active_support/ordered_hash'
2
+
3
+ module Rails
4
+ module Rack
5
+ class Metal
6
+ NotFoundResponse = [404, {}, []].freeze
7
+ NotFound = lambda { NotFoundResponse }
8
+
9
+ cattr_accessor :metal_paths
10
+ self.metal_paths = ["#{Rails.root}/app/metal"]
11
+ cattr_accessor :requested_metals
12
+
13
+ def self.metals
14
+ matcher = /#{Regexp.escape('/app/metal/')}(.*)\.rb\Z/
15
+ metal_glob = metal_paths.map{ |base| "#{base}/**/*.rb" }
16
+ all_metals = {}
17
+
18
+ metal_glob.each do |glob|
19
+ Dir[glob].sort.map do |file|
20
+ file = file.match(matcher)[1]
21
+ all_metals[file.camelize] = file
22
+ end
23
+ end
24
+
25
+ load_list = requested_metals || all_metals.keys
26
+
27
+ load_list.map do |requested_metal|
28
+ if metal = all_metals[requested_metal]
29
+ require metal
30
+ requested_metal.constantize
31
+ end
32
+ end.compact
33
+ end
34
+
35
+ def initialize(app)
36
+ @app = app
37
+ @metals = ActiveSupport::OrderedHash.new
38
+ self.class.metals.each { |app| @metals[app] = true }
39
+ freeze
40
+ end
41
+
42
+ def call(env)
43
+ @metals.keys.each do |app|
44
+ result = app.call(env)
45
+ return result unless result[0].to_i == 404
46
+ end
47
+ @app.call(env)
48
+ end
49
+ end
50
+ end
51
+ end
@@ -1,3 +1,5 @@
1
+ require 'rack/utils'
2
+
1
3
  module Rails
2
4
  module Rack
3
5
  class Static
@@ -11,14 +13,18 @@ module Rails
11
13
  def call(env)
12
14
  path = env['PATH_INFO'].chomp('/')
13
15
  method = env['REQUEST_METHOD']
14
- cached_path = (path.empty? ? 'index' : path) + ::ActionController::Base.page_cache_extension
15
16
 
16
17
  if FILE_METHODS.include?(method)
17
18
  if file_exist?(path)
18
19
  return @file_server.call(env)
19
- elsif file_exist?(cached_path)
20
- env['PATH_INFO'] = cached_path
21
- return @file_server.call(env)
20
+ else
21
+ cached_path = directory_exist?(path) ? "#{path}/index" : path
22
+ cached_path += ::ActionController::Base.page_cache_extension
23
+
24
+ if file_exist?(cached_path)
25
+ env['PATH_INFO'] = cached_path
26
+ return @file_server.call(env)
27
+ end
22
28
  end
23
29
  end
24
30
 
@@ -30,6 +36,11 @@ module Rails
30
36
  full_path = File.join(@file_server.root, ::Rack::Utils.unescape(path))
31
37
  File.file?(full_path) && File.readable?(full_path)
32
38
  end
39
+
40
+ def directory_exist?(path)
41
+ full_path = File.join(@file_server.root, ::Rack::Utils.unescape(path))
42
+ File.directory?(full_path) && File.readable?(full_path)
43
+ end
33
44
  end
34
45
  end
35
46
  end
@@ -1,8 +1,8 @@
1
1
  module Rails
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 2
4
- MINOR = 2
5
- TINY = 3
4
+ MINOR = 3
5
+ TINY = 2
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
@@ -154,6 +154,9 @@ module Rails
154
154
  File.join(destination_root, relative_destination)
155
155
  end
156
156
 
157
+ def after_generate
158
+ end
159
+
157
160
  protected
158
161
  # Convenience method for generator subclasses to record a manifest.
159
162
  def record
@@ -40,6 +40,7 @@ module Rails
40
40
  # Replay action manifest. RewindBase subclass rewinds manifest.
41
41
  def invoke!
42
42
  manifest.replay(self)
43
+ after_generate
43
44
  end
44
45
 
45
46
  def dependency(generator_name, args, runtime_options = {})
@@ -181,15 +182,19 @@ HELP
181
182
  nesting = class_name.split('::')
182
183
  name = nesting.pop
183
184
 
185
+ # Hack to limit const_defined? to non-inherited on 1.9.
186
+ extra = []
187
+ extra << false unless Object.method(:const_defined?).arity == 1
188
+
184
189
  # Extract the last Module in the nesting.
185
190
  last = nesting.inject(Object) { |last, nest|
186
- break unless last.const_defined?(nest)
191
+ break unless last.const_defined?(nest, *extra)
187
192
  last.const_get(nest)
188
193
  }
189
194
 
190
195
  # If the last Module exists, check whether the given
191
196
  # class exists and raise a collision if so.
192
- if last and last.const_defined?(name.camelize)
197
+ if last and last.const_defined?(name.camelize, *extra)
193
198
  raise_class_collision(class_name)
194
199
  end
195
200
  end
@@ -293,7 +298,7 @@ HELP
293
298
  file(relative_source, relative_destination, template_options) do |file|
294
299
  # Evaluate any assignments in a temporary, throwaway binding.
295
300
  vars = template_options[:assigns] || {}
296
- b = binding
301
+ b = template_options[:binding] || binding
297
302
  vars.each { |k,v| eval "#{k} = vars[:#{k}] || vars['#{k}']", b }
298
303
 
299
304
  # Render the source file with the temporary binding.
@@ -1,184 +1,258 @@
1
1
  require 'rbconfig'
2
+ require File.dirname(__FILE__) + '/template_runner'
2
3
  require 'digest/md5'
3
4
  require 'active_support/secure_random'
4
5
 
5
6
  class AppGenerator < Rails::Generator::Base
6
- DEFAULT_SHEBANG = File.join(Config::CONFIG['bindir'],
7
- Config::CONFIG['ruby_install_name'])
7
+ DEFAULT_SHEBANG = File.join(Config::CONFIG['bindir'], Config::CONFIG['ruby_install_name'])
8
8
 
9
- DATABASES = %w(mysql oracle postgresql sqlite2 sqlite3 frontbase ibm_db)
9
+ DATABASES = %w( mysql oracle postgresql sqlite2 sqlite3 frontbase ibm_db )
10
10
  DEFAULT_DATABASE = 'sqlite3'
11
11
 
12
- default_options :db => (ENV["RAILS_DEFAULT_DATABASE"] || DEFAULT_DATABASE),
13
- :shebang => DEFAULT_SHEBANG, :freeze => false
14
12
  mandatory_options :source => "#{File.dirname(__FILE__)}/../../../../.."
13
+ default_options :db => (ENV["RAILS_DEFAULT_DATABASE"] || DEFAULT_DATABASE),
14
+ :shebang => DEFAULT_SHEBANG, :with_dispatchers => false, :freeze => false
15
+
15
16
 
16
17
  def initialize(runtime_args, runtime_options = {})
17
18
  super
19
+
18
20
  usage if args.empty?
19
21
  usage("Databases supported for preconfiguration are: #{DATABASES.join(", ")}") if (options[:db] && !DATABASES.include?(options[:db]))
22
+
20
23
  @destination_root = args.shift
21
24
  @app_name = File.basename(File.expand_path(@destination_root))
22
25
  end
23
26
 
24
27
  def manifest
25
- # Use /usr/bin/env if no special shebang was specified
26
- script_options = { :chmod => 0755, :shebang => options[:shebang] == DEFAULT_SHEBANG ? nil : options[:shebang] }
27
- dispatcher_options = { :chmod => 0755, :shebang => options[:shebang] }
28
-
29
- # duplicate CGI::Session#generate_unique_id
30
- md5 = Digest::MD5.new
31
- now = Time.now
32
- md5 << now.to_s
33
- md5 << String(now.usec)
34
- md5 << String(rand(0))
35
- md5 << String($$)
36
- md5 << @app_name
37
-
38
- # Do our best to generate a secure secret key for CookieStore
39
- secret = ActiveSupport::SecureRandom.hex(64)
40
-
41
28
  record do |m|
42
- # Root directory and all subdirectories.
29
+ create_directories(m)
30
+ create_root_files(m)
31
+ create_app_files(m)
32
+ create_config_files(m)
33
+ create_script_files(m)
34
+ create_test_files(m)
35
+ create_public_files(m)
36
+ create_documentation_file(m)
37
+ create_log_files(m)
38
+ end
39
+ end
40
+
41
+ def after_generate
42
+ if options[:template]
43
+ Rails::TemplateRunner.new(options[:template], @destination_root)
44
+ end
45
+ end
46
+
47
+ protected
48
+ def banner
49
+ "Usage: #{$0} /path/to/your/app [options]"
50
+ end
51
+
52
+ def add_options!(opt)
53
+ opt.separator ''
54
+ opt.separator 'Options:'
55
+ opt.on("-r", "--ruby=path", String,
56
+ "Path to the Ruby binary of your choice (otherwise scripts use env, dispatchers current path).",
57
+ "Default: #{DEFAULT_SHEBANG}") { |v| options[:shebang] = v }
58
+
59
+ opt.on("-d", "--database=name", String,
60
+ "Preconfigure for selected database (options: #{DATABASES.join('/')}).",
61
+ "Default: #{DEFAULT_DATABASE}") { |v| options[:db] = v }
62
+
63
+ opt.on("-D", "--with-dispatchers",
64
+ "Add CGI/FastCGI/mod_ruby dispatches code to generated application skeleton",
65
+ "Default: false") { |v| options[:with_dispatchers] = v }
66
+
67
+ opt.on("-f", "--freeze",
68
+ "Freeze Rails in vendor/rails from the gems generating the skeleton",
69
+ "Default: false") { |v| options[:freeze] = v }
70
+
71
+ opt.on("-m", "--template=path", String,
72
+ "Use an application template that lives at path (can be a filesystem path or URL).",
73
+ "Default: (none)") { |v| options[:template] = v }
74
+
75
+ end
76
+
77
+
78
+ private
79
+ def create_directories(m)
43
80
  m.directory ''
44
- BASEDIRS.each { |path| m.directory path }
45
81
 
46
- # Root
82
+ # Intermediate directories are automatically created so don't sweat their absence here.
83
+ %w(
84
+ app/controllers
85
+ app/helpers
86
+ app/models
87
+ app/views/layouts
88
+ config/environments
89
+ config/initializers
90
+ config/locales
91
+ db
92
+ doc
93
+ lib
94
+ lib/tasks
95
+ log
96
+ public/images
97
+ public/javascripts
98
+ public/stylesheets
99
+ script/performance
100
+ test/fixtures
101
+ test/functional
102
+ test/integration
103
+ test/performance
104
+ test/unit
105
+ vendor
106
+ vendor/plugins
107
+ tmp/sessions
108
+ tmp/sockets
109
+ tmp/cache
110
+ tmp/pids
111
+ ).each { |path| m.directory(path) }
112
+ end
113
+
114
+ def create_root_files(m)
47
115
  m.file "fresh_rakefile", "Rakefile"
48
116
  m.file "README", "README"
117
+ end
118
+
119
+ def create_app_files(m)
120
+ m.file "helpers/application_controller.rb", "app/controllers/application_controller.rb"
121
+ m.file "helpers/application_helper.rb", "app/helpers/application_helper.rb"
122
+ end
123
+
124
+ def create_config_files(m)
125
+ create_database_configuration_file(m)
126
+ create_routes_file(m)
127
+ create_locale_file(m)
128
+ create_initializer_files(m)
129
+ create_environment_files(m)
130
+ end
49
131
 
50
- # Application
51
- m.template "helpers/application.rb", "app/controllers/application.rb", :assigns => { :app_name => @app_name, :app_secret => md5.hexdigest }
52
- m.template "helpers/application_helper.rb", "app/helpers/application_helper.rb"
53
- m.template "helpers/test_helper.rb", "test/test_helper.rb"
54
- m.template "helpers/performance_test.rb", "test/performance/browsing_test.rb"
132
+ def create_documentation_file(m)
133
+ m.file "doc/README_FOR_APP", "doc/README_FOR_APP"
134
+ end
135
+
136
+ def create_log_files(m)
137
+ %w( server production development test ).each do |file|
138
+ m.file "configs/empty.log", "log/#{file}.log", :chmod => 0666
139
+ end
140
+ end
55
141
 
56
- # database.yml and routes.rb
142
+ def create_public_files(m)
143
+ create_dispatch_files(m)
144
+ create_error_files(m)
145
+ create_welcome_file(m)
146
+ create_browser_convention_files(m)
147
+ create_rails_image(m)
148
+ create_javascript_files(m)
149
+ end
150
+
151
+ def create_script_files(m)
152
+ %w(
153
+ about console dbconsole destroy generate runner server plugin
154
+ performance/benchmarker performance/profiler
155
+ ).each do |file|
156
+ m.file "bin/#{file}", "script/#{file}", {
157
+ :chmod => 0755,
158
+ :shebang => options[:shebang] == DEFAULT_SHEBANG ? nil : options[:shebang]
159
+ }
160
+ end
161
+ end
162
+
163
+ def create_test_files(m)
164
+ m.file "helpers/test_helper.rb", "test/test_helper.rb"
165
+ m.file "helpers/performance_test.rb", "test/performance/browsing_test.rb"
166
+ end
167
+
168
+
169
+ def create_database_configuration_file(m)
57
170
  m.template "configs/databases/#{options[:db]}.yml", "config/database.yml", :assigns => {
58
171
  :app_name => @app_name,
59
- :socket => options[:db] == "mysql" ? mysql_socket_location : nil
60
- }
61
- m.template "configs/routes.rb", "config/routes.rb"
172
+ :socket => options[:db] == "mysql" ? mysql_socket_location : nil }
173
+ end
174
+
175
+ def create_routes_file(m)
176
+ m.file "configs/routes.rb", "config/routes.rb"
177
+ end
62
178
 
63
- # Initializers
64
- m.template "configs/initializers/inflections.rb", "config/initializers/inflections.rb"
65
- m.template "configs/initializers/mime_types.rb", "config/initializers/mime_types.rb"
66
- m.template "configs/initializers/new_rails_defaults.rb", "config/initializers/new_rails_defaults.rb"
179
+ def create_initializer_files(m)
180
+ %w(
181
+ backtrace_silencers
182
+ inflections
183
+ mime_types
184
+ new_rails_defaults
185
+ ).each do |initializer|
186
+ m.file "configs/initializers/#{initializer}.rb", "config/initializers/#{initializer}.rb"
187
+ end
67
188
 
68
- # Locale
69
- m.template "configs/locales/en.yml", "config/locales/en.yml"
189
+ m.template "configs/initializers/session_store.rb", "config/initializers/session_store.rb",
190
+ :assigns => { :app_name => @app_name, :app_secret => ActiveSupport::SecureRandom.hex(64) }
191
+ end
70
192
 
71
- # Environments
72
- m.file "environments/boot.rb", "config/boot.rb"
73
- m.template "environments/environment.rb", "config/environment.rb", :assigns => { :freeze => options[:freeze], :app_name => @app_name, :app_secret => secret }
193
+ def create_locale_file(m)
194
+ m.file "configs/locales/en.yml", "config/locales/en.yml"
195
+ end
196
+
197
+ def create_environment_files(m)
198
+ m.template "environments/environment.rb", "config/environment.rb",
199
+ :assigns => { :freeze => options[:freeze] }
200
+
201
+ m.file "environments/boot.rb", "config/boot.rb"
74
202
  m.file "environments/production.rb", "config/environments/production.rb"
75
203
  m.file "environments/development.rb", "config/environments/development.rb"
76
204
  m.file "environments/test.rb", "config/environments/test.rb"
205
+ end
77
206
 
78
- # Scripts
79
- %w( about console dbconsole destroy generate performance/benchmarker performance/profiler performance/request process/reaper process/spawner process/inspector runner server plugin ).each do |file|
80
- m.file "bin/#{file}", "script/#{file}", script_options
81
- end
82
207
 
83
- # Dispatches
84
- m.file "dispatches/dispatch.rb", "public/dispatch.rb", dispatcher_options
85
- m.file "dispatches/dispatch.rb", "public/dispatch.cgi", dispatcher_options
86
- m.file "dispatches/dispatch.fcgi", "public/dispatch.fcgi", dispatcher_options
208
+ def create_dispatch_files(m)
209
+ if options[:with_dispatchers]
210
+ dispatcher_options = { :chmod => 0755, :shebang => options[:shebang] }
87
211
 
88
- # HTML files
89
- %w(404 422 500 index).each do |file|
90
- m.template "html/#{file}.html", "public/#{file}.html"
212
+ m.file "dispatches/config.ru", "config.ru"
213
+ m.file "dispatches/dispatch.rb", "public/dispatch.rb", dispatcher_options
214
+ m.file "dispatches/dispatch.rb", "public/dispatch.cgi", dispatcher_options
215
+ m.file "dispatches/dispatch.fcgi", "public/dispatch.fcgi", dispatcher_options
91
216
  end
217
+ end
92
218
 
93
- m.template "html/favicon.ico", "public/favicon.ico"
94
- m.template "html/robots.txt", "public/robots.txt"
95
- m.file "html/images/rails.png", "public/images/rails.png"
96
-
97
- # Javascripts
98
- m.file "html/javascripts/prototype.js", "public/javascripts/prototype.js"
99
- m.file "html/javascripts/effects.js", "public/javascripts/effects.js"
100
- m.file "html/javascripts/dragdrop.js", "public/javascripts/dragdrop.js"
101
- m.file "html/javascripts/controls.js", "public/javascripts/controls.js"
102
- m.file "html/javascripts/application.js", "public/javascripts/application.js"
103
-
104
- # Docs
105
- m.file "doc/README_FOR_APP", "doc/README_FOR_APP"
106
-
107
- # Logs
108
- %w(server production development test).each { |file|
109
- m.file "configs/empty.log", "log/#{file}.log", :chmod => 0666
110
- }
219
+ def create_error_files(m)
220
+ %w( 404 422 500 ).each do |file|
221
+ m.file "html/#{file}.html", "public/#{file}.html"
222
+ end
111
223
  end
112
- end
113
224
 
114
- protected
115
- def banner
116
- "Usage: #{$0} /path/to/your/app [options]"
225
+ def create_welcome_file(m)
226
+ m.file 'html/index.html', 'public/index.html'
117
227
  end
118
228
 
119
- def add_options!(opt)
120
- opt.separator ''
121
- opt.separator 'Options:'
122
- opt.on("-r", "--ruby=path", String,
123
- "Path to the Ruby binary of your choice (otherwise scripts use env, dispatchers current path).",
124
- "Default: #{DEFAULT_SHEBANG}") { |v| options[:shebang] = v }
229
+ def create_browser_convention_files(m)
230
+ m.file "html/favicon.ico", "public/favicon.ico"
231
+ m.file "html/robots.txt", "public/robots.txt"
232
+ end
125
233
 
126
- opt.on("-d", "--database=name", String,
127
- "Preconfigure for selected database (options: #{DATABASES.join('/')}).",
128
- "Default: #{DEFAULT_DATABASE}") { |v| options[:db] = v }
234
+ def create_rails_image(m)
235
+ m.file "html/images/rails.png", "public/images/rails.png"
236
+ end
129
237
 
130
- opt.on("-f", "--freeze",
131
- "Freeze Rails in vendor/rails from the gems generating the skeleton",
132
- "Default: false") { |v| options[:freeze] = v }
238
+ def create_javascript_files(m)
239
+ %w( prototype effects dragdrop controls application ).each do |javascript|
240
+ m.file "html/javascripts/#{javascript}.js", "public/javascripts/#{javascript}.js"
241
+ end
133
242
  end
134
243
 
244
+
135
245
  def mysql_socket_location
136
- MYSQL_SOCKET_LOCATIONS.find { |f| File.exist?(f) } unless RUBY_PLATFORM =~ /(:?mswin|mingw)/
137
- end
138
-
139
-
140
- # Installation skeleton. Intermediate directories are automatically
141
- # created so don't sweat their absence here.
142
- BASEDIRS = %w(
143
- app/controllers
144
- app/helpers
145
- app/models
146
- app/views/layouts
147
- config/environments
148
- config/initializers
149
- config/locales
150
- db
151
- doc
152
- lib
153
- lib/tasks
154
- log
155
- public/images
156
- public/javascripts
157
- public/stylesheets
158
- script/performance
159
- script/process
160
- test/fixtures
161
- test/functional
162
- test/integration
163
- test/performance
164
- test/unit
165
- vendor
166
- vendor/plugins
167
- tmp/sessions
168
- tmp/sockets
169
- tmp/cache
170
- tmp/pids
171
- )
172
-
173
- MYSQL_SOCKET_LOCATIONS = [
174
- "/tmp/mysql.sock", # default
175
- "/var/run/mysqld/mysqld.sock", # debian/gentoo
176
- "/var/tmp/mysql.sock", # freebsd
177
- "/var/lib/mysql/mysql.sock", # fedora
178
- "/opt/local/lib/mysql/mysql.sock", # fedora
179
- "/opt/local/var/run/mysqld/mysqld.sock", # mac + darwinports + mysql
180
- "/opt/local/var/run/mysql4/mysqld.sock", # mac + darwinports + mysql4
181
- "/opt/local/var/run/mysql5/mysqld.sock", # mac + darwinports + mysql5
182
- "/opt/lampp/var/mysql/mysql.sock" # xampp for linux
183
- ]
184
- end
246
+ [
247
+ "/tmp/mysql.sock", # default
248
+ "/var/run/mysqld/mysqld.sock", # debian/gentoo
249
+ "/var/tmp/mysql.sock", # freebsd
250
+ "/var/lib/mysql/mysql.sock", # fedora
251
+ "/opt/local/lib/mysql/mysql.sock", # fedora
252
+ "/opt/local/var/run/mysqld/mysqld.sock", # mac + darwinports + mysql
253
+ "/opt/local/var/run/mysql4/mysqld.sock", # mac + darwinports + mysql4
254
+ "/opt/local/var/run/mysql5/mysqld.sock", # mac + darwinports + mysql5
255
+ "/opt/lampp/var/mysql/mysql.sock" # xampp for linux
256
+ ].find { |f| File.exist?(f) } unless RUBY_PLATFORM =~ /(:?mswin|mingw)/
257
+ end
258
+ end