railties 3.1.12 → 3.2.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (210) hide show
  1. data/CHANGELOG.md +2292 -41
  2. data/README.rdoc +14 -5
  3. data/bin/rails +7 -0
  4. data/guides/code/getting_started/Gemfile +27 -0
  5. data/guides/code/getting_started/README.rdoc +261 -0
  6. data/guides/code/getting_started/Rakefile +7 -0
  7. data/guides/code/getting_started/app/assets/images/rails.png +0 -0
  8. data/guides/code/getting_started/app/assets/javascripts/application.js +9 -0
  9. data/guides/code/getting_started/app/assets/javascripts/comments.js.coffee +3 -0
  10. data/guides/code/getting_started/app/assets/javascripts/home.js.coffee +3 -0
  11. data/guides/code/getting_started/app/assets/javascripts/posts.js.coffee +3 -0
  12. data/guides/code/getting_started/app/assets/stylesheets/application.css +7 -0
  13. data/guides/code/getting_started/app/assets/stylesheets/comments.css.scss +3 -0
  14. data/guides/code/getting_started/app/assets/stylesheets/home.css.scss +3 -0
  15. data/guides/code/getting_started/app/assets/stylesheets/posts.css.scss +3 -0
  16. data/guides/code/getting_started/app/assets/stylesheets/scaffolds.css.scss +56 -0
  17. data/guides/code/getting_started/app/controllers/application_controller.rb +3 -0
  18. data/guides/code/getting_started/app/controllers/comments_controller.rb +16 -0
  19. data/guides/code/getting_started/app/controllers/home_controller.rb +5 -0
  20. data/guides/code/getting_started/app/controllers/posts_controller.rb +84 -0
  21. data/guides/code/getting_started/app/helpers/application_helper.rb +2 -0
  22. data/guides/code/getting_started/app/helpers/comments_helper.rb +2 -0
  23. data/guides/code/getting_started/app/helpers/home_helper.rb +2 -0
  24. data/guides/code/getting_started/app/helpers/posts_helper.rb +5 -0
  25. data/guides/code/getting_started/app/models/comment.rb +3 -0
  26. data/guides/code/getting_started/app/models/post.rb +11 -0
  27. data/guides/code/getting_started/app/models/tag.rb +3 -0
  28. data/guides/code/getting_started/app/views/comments/_comment.html.erb +15 -0
  29. data/guides/code/getting_started/app/views/comments/_form.html.erb +13 -0
  30. data/guides/code/getting_started/app/views/home/index.html.erb +2 -0
  31. data/guides/code/getting_started/app/views/layouts/application.html.erb +14 -0
  32. data/guides/code/getting_started/app/views/posts/_form.html.erb +32 -0
  33. data/guides/code/getting_started/app/views/posts/edit.html.erb +6 -0
  34. data/guides/code/getting_started/app/views/posts/index.html.erb +27 -0
  35. data/guides/code/getting_started/app/views/posts/new.html.erb +5 -0
  36. data/guides/code/getting_started/app/views/posts/show.html.erb +31 -0
  37. data/guides/code/getting_started/app/views/tags/_form.html.erb +12 -0
  38. data/guides/code/getting_started/config.ru +4 -0
  39. data/guides/code/getting_started/config/application.rb +53 -0
  40. data/guides/code/getting_started/config/boot.rb +6 -0
  41. data/guides/code/getting_started/config/database.yml +25 -0
  42. data/guides/code/getting_started/config/environment.rb +5 -0
  43. data/guides/code/getting_started/config/environments/development.rb +37 -0
  44. data/guides/code/getting_started/config/environments/production.rb +67 -0
  45. data/guides/code/getting_started/config/environments/test.rb +37 -0
  46. data/guides/code/getting_started/config/initializers/backtrace_silencers.rb +7 -0
  47. data/guides/code/getting_started/config/initializers/inflections.rb +10 -0
  48. data/guides/code/getting_started/config/initializers/mime_types.rb +5 -0
  49. data/guides/code/getting_started/config/initializers/secret_token.rb +7 -0
  50. data/guides/code/getting_started/config/initializers/session_store.rb +8 -0
  51. data/guides/code/getting_started/config/initializers/wrap_parameters.rb +14 -0
  52. data/guides/code/getting_started/config/locales/en.yml +5 -0
  53. data/guides/code/getting_started/config/routes.rb +64 -0
  54. data/guides/code/getting_started/db/migrate/20110901012504_create_posts.rb +11 -0
  55. data/guides/code/getting_started/db/migrate/20110901012815_create_comments.rb +12 -0
  56. data/guides/code/getting_started/db/migrate/20110901013701_create_tags.rb +11 -0
  57. data/guides/code/getting_started/db/schema.rb +43 -0
  58. data/guides/code/getting_started/db/seeds.rb +7 -0
  59. data/guides/code/getting_started/doc/README_FOR_APP +2 -0
  60. data/guides/code/getting_started/public/404.html +26 -0
  61. data/guides/code/getting_started/public/422.html +26 -0
  62. data/guides/code/getting_started/public/500.html +26 -0
  63. data/guides/code/getting_started/public/favicon.ico +0 -0
  64. data/guides/code/getting_started/public/robots.txt +5 -0
  65. data/guides/code/getting_started/script/rails +6 -0
  66. data/guides/code/getting_started/test/fixtures/comments.yml +11 -0
  67. data/guides/code/getting_started/test/fixtures/posts.yml +11 -0
  68. data/guides/code/getting_started/test/fixtures/tags.yml +9 -0
  69. data/guides/code/getting_started/test/functional/comments_controller_test.rb +7 -0
  70. data/guides/code/getting_started/test/functional/home_controller_test.rb +9 -0
  71. data/guides/code/getting_started/test/functional/posts_controller_test.rb +49 -0
  72. data/guides/code/getting_started/test/performance/browsing_test.rb +12 -0
  73. data/guides/code/getting_started/test/test_helper.rb +13 -0
  74. data/guides/code/getting_started/test/unit/comment_test.rb +7 -0
  75. data/guides/code/getting_started/test/unit/helpers/comments_helper_test.rb +4 -0
  76. data/guides/code/getting_started/test/unit/helpers/home_helper_test.rb +4 -0
  77. data/guides/code/getting_started/test/unit/helpers/posts_helper_test.rb +4 -0
  78. data/guides/code/getting_started/test/unit/post_test.rb +7 -0
  79. data/guides/code/getting_started/test/unit/tag_test.rb +7 -0
  80. data/guides/rails_guides/generator.rb +2 -1
  81. data/guides/source/3_0_release_notes.textile +2 -2
  82. data/guides/source/3_1_release_notes.textile +3 -110
  83. data/guides/source/action_controller_overview.textile +11 -13
  84. data/guides/source/action_mailer_basics.textile +7 -18
  85. data/guides/source/action_view_overview.textile +78 -9
  86. data/guides/source/active_model_basics.textile +205 -0
  87. data/guides/source/active_record_basics.textile +31 -31
  88. data/guides/source/active_record_querying.textile +288 -67
  89. data/guides/source/active_record_validations_callbacks.textile +69 -75
  90. data/guides/source/active_resource_basics.textile +48 -2
  91. data/guides/source/active_support_core_extensions.textile +145 -24
  92. data/guides/source/ajax_on_rails.textile +65 -7
  93. data/guides/source/api_documentation_guidelines.textile +0 -6
  94. data/guides/source/asset_pipeline.textile +2 -2
  95. data/guides/source/association_basics.textile +25 -34
  96. data/guides/source/caching_with_rails.textile +12 -17
  97. data/guides/source/command_line.textile +29 -19
  98. data/guides/source/configuring.textile +40 -18
  99. data/guides/source/contributing_to_ruby_on_rails.textile +11 -18
  100. data/guides/source/debugging_rails_applications.textile +10 -21
  101. data/guides/source/engines.textile +618 -0
  102. data/guides/source/form_helpers.textile +1 -12
  103. data/guides/source/generators.textile +9 -11
  104. data/guides/source/getting_started.textile +152 -152
  105. data/guides/source/i18n.textile +4 -5
  106. data/guides/source/index.html.erb +0 -1
  107. data/guides/source/initialization.textile +26 -26
  108. data/guides/source/layouts_and_rendering.textile +97 -61
  109. data/guides/source/migrations.textile +380 -161
  110. data/guides/source/performance_testing.textile +4 -10
  111. data/guides/source/plugins.textile +11 -19
  112. data/guides/source/rails_application_templates.textile +12 -4
  113. data/guides/source/rails_on_rack.textile +25 -19
  114. data/guides/source/routing.textile +6 -13
  115. data/guides/source/ruby_on_rails_guides_guidelines.textile +0 -5
  116. data/guides/source/security.textile +11 -15
  117. data/guides/source/testing.textile +1 -9
  118. data/lib/rails/application.rb +107 -42
  119. data/lib/rails/application/bootstrap.rb +12 -11
  120. data/lib/rails/application/configuration.rb +27 -21
  121. data/lib/rails/application/finisher.rb +40 -17
  122. data/lib/rails/application/route_inspector.rb +75 -0
  123. data/lib/rails/application/routes_reloader.rb +15 -4
  124. data/lib/rails/code_statistics.rb +16 -5
  125. data/lib/rails/commands.rb +6 -5
  126. data/lib/rails/commands/application.rb +8 -1
  127. data/lib/rails/commands/console.rb +2 -0
  128. data/lib/rails/commands/dbconsole.rb +2 -2
  129. data/lib/rails/commands/destroy.rb +0 -2
  130. data/lib/rails/commands/generate.rb +3 -3
  131. data/lib/rails/commands/plugin.rb +161 -159
  132. data/lib/rails/commands/plugin_new.rb +3 -2
  133. data/lib/rails/commands/runner.rb +4 -0
  134. data/lib/rails/console/app.rb +26 -22
  135. data/lib/rails/console/helpers.rb +9 -5
  136. data/lib/rails/engine.rb +70 -34
  137. data/lib/rails/engine/commands.rb +39 -0
  138. data/lib/rails/engine/configuration.rb +1 -1
  139. data/lib/rails/generators.rb +3 -14
  140. data/lib/rails/generators/actions.rb +36 -9
  141. data/lib/rails/generators/app_base.rb +34 -38
  142. data/lib/rails/generators/base.rb +4 -4
  143. data/lib/rails/generators/generated_attribute.rb +1 -1
  144. data/lib/rails/generators/named_base.rb +1 -3
  145. data/lib/rails/generators/rails/app/USAGE +6 -0
  146. data/lib/rails/generators/rails/app/app_generator.rb +6 -2
  147. data/lib/rails/generators/rails/app/templates/Gemfile +4 -3
  148. data/lib/rails/generators/rails/app/templates/app/assets/javascripts/application.js.tt +9 -3
  149. data/lib/rails/generators/rails/app/templates/app/assets/stylesheets/application.css +11 -5
  150. data/lib/rails/generators/rails/app/templates/app/mailers/.empty_directory +0 -0
  151. data/lib/rails/generators/rails/app/templates/app/models/.empty_directory +0 -0
  152. data/lib/rails/generators/rails/app/templates/app/views/layouts/application.html.erb.tt +1 -1
  153. data/lib/rails/generators/rails/app/templates/config/application.rb +11 -0
  154. data/lib/rails/generators/rails/app/templates/config/databases/jdbcpostgresql.yml +1 -1
  155. data/lib/rails/generators/rails/app/templates/config/databases/postgresql.yml +1 -1
  156. data/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt +10 -1
  157. data/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt +10 -1
  158. data/lib/rails/generators/rails/app/templates/config/environments/test.rb.tt +6 -6
  159. data/lib/rails/generators/rails/app/templates/config/initializers/inflections.rb +5 -0
  160. data/lib/rails/generators/rails/app/templates/config/routes.rb +1 -1
  161. data/lib/rails/generators/rails/app/templates/public/500.html +0 -1
  162. data/lib/rails/generators/rails/app/templates/public/index.html +1 -1
  163. data/lib/rails/generators/rails/app/templates/public/stylesheets/.empty_directory +0 -0
  164. data/lib/rails/generators/rails/app/templates/test/fixtures/.empty_directory +0 -0
  165. data/lib/rails/generators/rails/app/templates/test/functional/.empty_directory +0 -0
  166. data/lib/rails/generators/rails/app/templates/test/integration/.empty_directory +0 -0
  167. data/lib/rails/generators/rails/app/templates/test/unit/.empty_directory +0 -0
  168. data/lib/rails/generators/rails/controller/templates/controller.rb +1 -1
  169. data/lib/rails/generators/rails/generator/templates/templates/.empty_directory +0 -0
  170. data/lib/rails/generators/rails/plugin_new/plugin_new_generator.rb +17 -5
  171. data/lib/rails/generators/rails/plugin_new/templates/Rakefile +1 -0
  172. data/lib/rails/generators/rails/plugin_new/templates/app/mailers/.empty_directory +0 -0
  173. data/lib/rails/generators/rails/plugin_new/templates/app/models/.empty_directory +0 -0
  174. data/lib/rails/generators/rails/plugin_new/templates/app/views/layouts/%name%/application.html.erb.tt +1 -1
  175. data/lib/rails/generators/rails/plugin_new/templates/gitignore +4 -3
  176. data/lib/rails/generators/rails/plugin_new/templates/lib/%name%/engine.rb +1 -1
  177. data/lib/rails/generators/rails/plugin_new/templates/rails/application.rb +1 -1
  178. data/lib/rails/generators/rails/plugin_new/templates/script/rails.tt +5 -3
  179. data/lib/rails/generators/rails/scaffold_controller/templates/controller.rb +2 -2
  180. data/lib/rails/generators/rails/task/USAGE +9 -0
  181. data/lib/rails/generators/rails/task/task_generator.rb +12 -0
  182. data/lib/rails/generators/rails/task/templates/task.rb +8 -0
  183. data/lib/rails/generators/resource_helpers.rb +3 -3
  184. data/lib/rails/generators/test_unit/integration/templates/integration_test.rb +0 -2
  185. data/lib/rails/generators/test_unit/scaffold/templates/functional_test.rb +4 -4
  186. data/lib/rails/paths.rb +11 -38
  187. data/lib/rails/rack/debugger.rb +3 -4
  188. data/lib/rails/rack/logger.rb +26 -12
  189. data/lib/rails/railtie.rb +6 -1
  190. data/lib/rails/railtie/configuration.rb +12 -5
  191. data/lib/rails/source_annotation_extractor.rb +12 -10
  192. data/lib/rails/tasks/documentation.rake +3 -1
  193. data/lib/rails/tasks/engine.rake +1 -0
  194. data/lib/rails/tasks/misc.rake +1 -1
  195. data/lib/rails/tasks/routes.rake +3 -23
  196. data/lib/rails/test_help.rb +1 -2
  197. data/lib/rails/test_unit/testing.rake +8 -4
  198. data/lib/rails/version.rb +3 -3
  199. metadata +131 -61
  200. checksums.yaml +0 -7
  201. data/lib/rails/generators/rails/plugin/USAGE +0 -13
  202. data/lib/rails/generators/rails/plugin/plugin_generator.rb +0 -54
  203. data/lib/rails/generators/rails/plugin/templates/MIT-LICENSE.tt +0 -20
  204. data/lib/rails/generators/rails/plugin/templates/README.tt +0 -13
  205. data/lib/rails/generators/rails/plugin/templates/Rakefile.tt +0 -23
  206. data/lib/rails/generators/rails/plugin/templates/init.rb +0 -1
  207. data/lib/rails/generators/rails/plugin/templates/install.rb +0 -1
  208. data/lib/rails/generators/rails/plugin/templates/lib/%file_name%.rb.tt +0 -1
  209. data/lib/rails/generators/rails/plugin/templates/lib/tasks/%file_name%_tasks.rake.tt +0 -4
  210. data/lib/rails/generators/rails/plugin/templates/uninstall.rb +0 -1
@@ -0,0 +1,9 @@
1
+ Description:
2
+ Stubs out a new Rake task. Pass the namespace name, and a list of tasks as arguments.
3
+
4
+ This generates a task file in lib/tasks.
5
+
6
+ Example:
7
+ `rails generate task feeds fetch erase add`
8
+
9
+ Task: lib/tasks/feeds.rake
@@ -0,0 +1,12 @@
1
+ module Rails
2
+ module Generators
3
+ class TaskGenerator < NamedBase
4
+ argument :actions, :type => :array, :default => [], :banner => "action action"
5
+
6
+ def create_task_files
7
+ template 'task.rb', File.join('lib/tasks', "#{file_name}.rake")
8
+ end
9
+
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,8 @@
1
+ namespace :<%= file_name %> do
2
+ <% actions.each do |action| -%>
3
+ desc "TODO"
4
+ task :<%= action %> => :environment do
5
+ end
6
+
7
+ <% end -%>
8
+ end
@@ -64,8 +64,8 @@ module Rails
64
64
  end
65
65
 
66
66
  begin
67
- "#{options[:orm].to_s.classify}::Generators::ActiveModel".constantize
68
- rescue NameError => e
67
+ "#{options[:orm].to_s.camelize}::Generators::ActiveModel".constantize
68
+ rescue NameError
69
69
  Rails::Generators::ActiveModel
70
70
  end
71
71
  end
@@ -73,7 +73,7 @@ module Rails
73
73
 
74
74
  # Initialize ORM::Generators::ActiveModel to access instance methods.
75
75
  def orm_instance(name=singular_table_name)
76
- @orm_instance ||= @orm_class.new(name)
76
+ @orm_instance ||= orm_class.new(name)
77
77
  end
78
78
  end
79
79
  end
@@ -1,8 +1,6 @@
1
1
  require 'test_helper'
2
2
 
3
3
  class <%= class_name %>Test < ActionDispatch::IntegrationTest
4
- fixtures :all
5
-
6
4
  # test "the truth" do
7
5
  # assert true
8
6
  # end
@@ -26,23 +26,23 @@ class <%= controller_class_name %>ControllerTest < ActionController::TestCase
26
26
  end
27
27
 
28
28
  test "should show <%= singular_table_name %>" do
29
- get :show, <%= key_value :id, "@#{singular_table_name}.to_param" %>
29
+ get :show, <%= key_value :id, "@#{singular_table_name}" %>
30
30
  assert_response :success
31
31
  end
32
32
 
33
33
  test "should get edit" do
34
- get :edit, <%= key_value :id, "@#{singular_table_name}.to_param" %>
34
+ get :edit, <%= key_value :id, "@#{singular_table_name}" %>
35
35
  assert_response :success
36
36
  end
37
37
 
38
38
  test "should update <%= singular_table_name %>" do
39
- put :update, <%= key_value :id, "@#{singular_table_name}.to_param" %>, <%= key_value singular_table_name, "@#{singular_table_name}.attributes" %>
39
+ put :update, <%= key_value :id, "@#{singular_table_name}" %>, <%= key_value singular_table_name, "@#{singular_table_name}.attributes" %>
40
40
  assert_redirected_to <%= singular_table_name %>_path(assigns(:<%= singular_table_name %>))
41
41
  end
42
42
 
43
43
  test "should destroy <%= singular_table_name %>" do
44
44
  assert_difference('<%= class_name %>.count', -1) do
45
- delete :destroy, <%= key_value :id, "@#{singular_table_name}.to_param" %>
45
+ delete :destroy, <%= key_value :id, "@#{singular_table_name}" %>
46
46
  end
47
47
 
48
48
  assert_redirected_to <%= index_helper %>_path
@@ -2,39 +2,21 @@ require 'set'
2
2
 
3
3
  module Rails
4
4
  module Paths
5
- module PathParent #:nodoc:
6
- def method_missing(id, *args)
7
- match = id.to_s.match(/^(.*)=$/)
8
- full = [@current, $1 || id].compact.join("/")
9
-
10
- ActiveSupport::Deprecation.warn 'Accessing paths using dot style as in `config.paths.app.controller` is deprecated. Please use ' <<
11
- '`config.paths["app/controller"]` style instead.'
12
-
13
- if match || args.any?
14
- @root[full] = Path.new(@root, full, *args)
15
- elsif path = @root[full]
16
- path
17
- else
18
- super
19
- end
20
- end
21
- end
22
-
23
- # This object is an extended hash that behaves as root of the Rails::Paths system.
5
+ # This object is an extended hash that behaves as root of the <tt>Rails::Paths</tt> system.
24
6
  # It allows you to collect information about how you want to structure your application
25
7
  # paths by a Hash like API. It requires you to give a physical path on initialization.
26
8
  #
27
- # root = Root.new
9
+ # root = Root.new "/rails"
28
10
  # root.add "app/controllers", :eager_load => true
29
11
  #
30
12
  # The command above creates a new root object and add "app/controllers" as a path.
31
- # This means we can get a Path object back like below:
13
+ # This means we can get a +Rails::Paths::Path+ object back like below:
32
14
  #
33
15
  # path = root["app/controllers"]
34
16
  # path.eager_load? # => true
35
17
  # path.is_a?(Rails::Paths::Path) # => true
36
18
  #
37
- # The Path object is simply an array and allows you to easily add extra paths:
19
+ # The +Path+ object is simply an array and allows you to easily add extra paths:
38
20
  #
39
21
  # path.is_a?(Array) # => true
40
22
  # path.inspect # => ["app/controllers"]
@@ -42,32 +24,30 @@ module Rails
42
24
  # path << "lib/controllers"
43
25
  # path.inspect # => ["app/controllers", "lib/controllers"]
44
26
  #
45
- # Notice that when you add a path using #add, the path object created already
46
- # contains the path with the same path value given to #add. In some situations,
27
+ # Notice that when you add a path using +add+, the path object created already
28
+ # contains the path with the same path value given to +add+. In some situations,
47
29
  # you may not want this behavior, so you can give :with as option.
48
30
  #
49
31
  # root.add "config/routes", :with => "config/routes.rb"
50
32
  # root["config/routes"].inspect # => ["config/routes.rb"]
51
33
  #
52
- # The #add method accepts the following options as arguments:
34
+ # The +add+ method accepts the following options as arguments:
53
35
  # eager_load, autoload, autoload_once and glob.
54
36
  #
55
- # Finally, the Path object also provides a few helpers:
37
+ # Finally, the +Path+ object also provides a few helpers:
56
38
  #
57
- # root = Root.new
58
- # root.path = "/rails"
39
+ # root = Root.new "/rails"
59
40
  # root.add "app/controllers"
60
41
  #
61
42
  # root["app/controllers"].expanded # => ["/rails/app/controllers"]
62
43
  # root["app/controllers"].existent # => ["/rails/app/controllers"]
63
44
  #
64
- # Check the Path documentation for more information.
45
+ # Check the <tt>Rails::Paths::Path</tt> documentation for more information.
65
46
  class Root < ::Hash
66
- include PathParent
67
47
  attr_accessor :path
68
48
 
69
49
  def initialize(path)
70
- raise if path.is_a?(Array)
50
+ raise "Argument should be a String of the physical root path" if path.is_a?(Array)
71
51
  @current = nil
72
52
  @path = path
73
53
  @root = self
@@ -121,8 +101,6 @@ module Rails
121
101
  end
122
102
 
123
103
  class Path < Array
124
- include PathParent
125
-
126
104
  attr_reader :path
127
105
  attr_accessor :glob
128
106
 
@@ -198,11 +176,6 @@ module Rails
198
176
  expanded.select { |d| File.directory?(d) }
199
177
  end
200
178
 
201
- def paths
202
- ActiveSupport::Deprecation.warn "paths is deprecated. Please call expand instead."
203
- expanded
204
- end
205
-
206
179
  alias to_a expanded
207
180
  end
208
181
  end
@@ -1,5 +1,3 @@
1
- require 'active_support/core_ext/kernel/requires'
2
-
3
1
  module Rails
4
2
  module Rack
5
3
  class Debugger
@@ -8,11 +6,12 @@ module Rails
8
6
 
9
7
  ARGV.clear # clear ARGV so that rails server options aren't passed to IRB
10
8
 
11
- require_library_or_gem 'ruby-debug'
9
+ require 'ruby-debug'
10
+
12
11
  ::Debugger.start
13
12
  ::Debugger.settings[:autoeval] = true if ::Debugger.respond_to?(:settings)
14
13
  puts "=> Debugger enabled"
15
- rescue Exception
14
+ rescue LoadError
16
15
  puts "You need to install ruby-debug to run the server in debugging mode. With gems, use 'gem install ruby-debug'"
17
16
  exit
18
17
  end
@@ -1,32 +1,46 @@
1
1
  require 'active_support/core_ext/time/conversions'
2
+ require 'active_support/core_ext/object/blank'
2
3
 
3
4
  module Rails
4
5
  module Rack
5
6
  # Log the request started and flush all loggers after it.
6
7
  class Logger < ActiveSupport::LogSubscriber
7
- def initialize(app)
8
- @app = app
8
+ def initialize(app, tags=nil)
9
+ @app, @tags = app, tags.presence
9
10
  end
10
11
 
11
12
  def call(env)
12
- before_dispatch(env)
13
- @app.call(env)
14
- ensure
15
- after_dispatch(env)
13
+ if @tags
14
+ Rails.logger.tagged(compute_tags(env)) { call_app(env) }
15
+ else
16
+ call_app(env)
17
+ end
16
18
  end
17
19
 
18
20
  protected
19
21
 
20
- def before_dispatch(env)
22
+ def call_app(env)
21
23
  request = ActionDispatch::Request.new(env)
22
24
  path = request.filtered_path
23
-
24
- info "\n\nStarted #{request.request_method} \"#{path}\" " \
25
- "for #{request.ip} at #{Time.now.to_default_s}"
25
+ Rails.logger.info "\n\nStarted #{request.request_method} \"#{path}\" for #{request.ip} at #{Time.now.to_default_s}"
26
+ @app.call(env)
27
+ ensure
28
+ ActiveSupport::LogSubscriber.flush_all!
26
29
  end
27
30
 
28
- def after_dispatch(env)
29
- ActiveSupport::LogSubscriber.flush_all!
31
+ def compute_tags(env)
32
+ request = ActionDispatch::Request.new(env)
33
+
34
+ @tags.collect do |tag|
35
+ case tag
36
+ when Proc
37
+ tag.call(request)
38
+ when Symbol
39
+ request.send(tag)
40
+ else
41
+ tag
42
+ end
43
+ end
30
44
  end
31
45
  end
32
46
  end
@@ -1,6 +1,7 @@
1
1
  require 'rails/initializable'
2
2
  require 'rails/configuration'
3
3
  require 'active_support/inflector'
4
+ require 'active_support/core_ext/module/introspection'
4
5
  require 'active_support/core_ext/module/delegation'
5
6
 
6
7
  module Rails
@@ -180,7 +181,7 @@ module Rails
180
181
 
181
182
  def load_tasks(app=self)
182
183
  extend Rake::DSL if defined? Rake::DSL
183
- self.class.rake_tasks.each { |block| block.call(app) }
184
+ self.class.rake_tasks.each { |block| self.instance_exec(app, &block) }
184
185
 
185
186
  # load also tasks from all superclasses
186
187
  klass = self.class.superclass
@@ -193,5 +194,9 @@ module Rails
193
194
  def load_generators(app=self)
194
195
  self.class.generators.each { |block| block.call(app) }
195
196
  end
197
+
198
+ def railtie_namespace
199
+ @railtie_namespace ||= self.class.parents.detect { |n| n.respond_to?(:railtie_namespace) }
200
+ end
196
201
  end
197
202
  end
@@ -7,6 +7,18 @@ module Rails
7
7
  @@options ||= {}
8
8
  end
9
9
 
10
+ # Add files that should be watched for change.
11
+ def watchable_files
12
+ @@watchable_files ||= []
13
+ end
14
+
15
+ # Add directories that should be watched for change.
16
+ # The key of the hashes should be directories and the values should
17
+ # be an array of extensions to match in each directory.
18
+ def watchable_dirs
19
+ @@watchable_dirs ||= {}
20
+ end
21
+
10
22
  # This allows you to modify the application's middlewares from Engines.
11
23
  #
12
24
  # All operations you run on the app_middleware will be replayed on the
@@ -26,11 +38,6 @@ module Rails
26
38
  @@app_generators
27
39
  end
28
40
 
29
- def generators(&block) #:nodoc
30
- ActiveSupport::Deprecation.warn "config.generators in Rails::Railtie is deprecated. Please use config.app_generators instead."
31
- app_generators(&block)
32
- end
33
-
34
41
  # First configurable block to run. Called before any initializers are run.
35
42
  def before_configuration(&block)
36
43
  ActiveSupport.on_load(:before_configuration, :yield => true, &block)
@@ -28,9 +28,9 @@ class SourceAnnotationExtractor
28
28
  end
29
29
  end
30
30
 
31
- # Prints all annotations with tag +tag+ under the root directories +app+, +lib+,
32
- # and +test+ (recursively). Only filenames with extension +.builder+, +.rb+,
33
- # +.rxml+, +.rhtml+, or +.erb+ are taken into account. The +options+
31
+ # Prints all annotations with tag +tag+ under the root directories +app+, +config+, +lib+,
32
+ # +script+, and +test+ (recursively). Only filenames with extension
33
+ # +.builder+, +.rb+, and +.erb+ are taken into account. The +options+
34
34
  # hash is passed to each annotation's +to_s+.
35
35
  #
36
36
  # This class method is the single entry point for the rake tasks.
@@ -46,16 +46,14 @@ class SourceAnnotationExtractor
46
46
  end
47
47
 
48
48
  # Returns a hash that maps filenames under +dirs+ (recursively) to arrays
49
- # with their annotations. Only files with annotations are included, and only
50
- # those with extension +.builder+, +.rb+, +.rxml+, +.rhtml+, and +.erb+
51
- # are taken into account.
52
- def find(dirs=%w(app lib test))
49
+ # with their annotations.
50
+ def find(dirs=%w(app config lib script test))
53
51
  dirs.inject({}) { |h, dir| h.update(find_in(dir)) }
54
52
  end
55
53
 
56
54
  # Returns a hash that maps filenames under +dir+ (recursively) to arrays
57
55
  # with their annotations. Only files with annotations are included, and only
58
- # those with extension +.builder+, +.rb+, +.rxml+, +.rhtml+, and +.erb+
56
+ # those with extension +.builder+, +.rb+, +.erb+, +.haml+ and +.slim+
59
57
  # are taken into account.
60
58
  def find_in(dir)
61
59
  results = {}
@@ -65,10 +63,14 @@ class SourceAnnotationExtractor
65
63
 
66
64
  if File.directory?(item)
67
65
  results.update(find_in(item))
68
- elsif item =~ /\.(builder|(r(?:b|xml|js)))$/
66
+ elsif item =~ /\.(builder|rb)$/
69
67
  results.update(extract_annotations_from(item, /#\s*(#{tag}):?\s*(.*)$/))
70
- elsif item =~ /\.(rhtml|erb)$/
68
+ elsif item =~ /\.erb$/
71
69
  results.update(extract_annotations_from(item, /<%\s*#\s*(#{tag}):?\s*(.*?)\s*%>/))
70
+ elsif item =~ /\.haml$/
71
+ results.update(extract_annotations_from(item, /-\s*#\s*(#{tag}):?\s*(.*)$/))
72
+ elsif item =~ /\.slim$/
73
+ results.update(extract_annotations_from(item, /\/\s*\s*(#{tag}):?\s*(.*)$/))
72
74
  end
73
75
  end
74
76
 
@@ -8,6 +8,8 @@ end
8
8
 
9
9
  # Monkey-patch to remove redoc'ing and clobber descriptions to cut down on rake -T noise
10
10
  class RDocTaskWithoutDescriptions < RDoc::Task
11
+ include ::Rake::DSL
12
+
11
13
  def define
12
14
  task rdoc_task_name
13
15
 
@@ -61,7 +63,7 @@ namespace :doc do
61
63
  rdoc.template = "#{ENV['template']}.rb" if ENV['template']
62
64
  rdoc.title = "Rails Framework Documentation"
63
65
  rdoc.options << '--line-numbers'
64
- rdoc.rdoc_files.include('README.rdoc')
66
+ rdoc.rdoc_files.include('README')
65
67
 
66
68
  gem_path('actionmailer') do |actionmailer|
67
69
  %w(README.rdoc CHANGELOG.md MIT-LICENSE lib/action_mailer/base.rb).each do |file|
@@ -2,6 +2,7 @@ task "load_app" do
2
2
  namespace :app do
3
3
  load APP_RAKEFILE
4
4
  end
5
+ task :environment => "app:environment"
5
6
 
6
7
  if !defined?(ENGINE_PATH) || !ENGINE_PATH
7
8
  ENGINE_PATH = find_engine_path(APP_RAKEFILE)
@@ -7,7 +7,7 @@ end
7
7
 
8
8
  desc 'Generate a cryptographically secure secret key (this is typically used to generate a secret for cookie sessions).'
9
9
  task :secret do
10
- require 'active_support/secure_random'
10
+ require 'securerandom'
11
11
  puts SecureRandom.hex(64)
12
12
  end
13
13
 
@@ -3,27 +3,7 @@ task :routes => :environment do
3
3
  Rails.application.reload_routes!
4
4
  all_routes = Rails.application.routes.routes
5
5
 
6
- if ENV['CONTROLLER']
7
- all_routes = all_routes.select{ |route| route.defaults[:controller] == ENV['CONTROLLER'] }
8
- end
9
-
10
- routes = all_routes.collect do |route|
11
-
12
- reqs = route.requirements.dup
13
- reqs[:to] = route.app unless route.app.class.name.to_s =~ /^ActionDispatch::Routing/
14
- reqs = reqs.empty? ? "" : reqs.inspect
15
-
16
- {:name => route.name.to_s, :verb => route.verb.to_s, :path => route.path, :reqs => reqs}
17
- end
18
-
19
- # Skip the route if it's internal info route
20
- routes.reject! { |r| r[:path] =~ %r{/rails/info/properties|^/assets} }
21
-
22
- name_width = routes.map{ |r| r[:name].length }.max
23
- verb_width = routes.map{ |r| r[:verb].length }.max
24
- path_width = routes.map{ |r| r[:path].length }.max
25
-
26
- routes.each do |r|
27
- puts "#{r[:name].rjust(name_width)} #{r[:verb].ljust(verb_width)} #{r[:path].ljust(path_width)} #{r[:reqs]}"
28
- end
6
+ require 'rails/application/route_inspector'
7
+ inspector = Rails::Application::RouteInspector.new
8
+ puts inspector.format(all_routes, ENV['CONTROLLER']).join "\n"
29
9
  end