railties 3.0.20 → 3.1.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (193) hide show
  1. data/CHANGELOG +36 -49
  2. data/README.rdoc +2 -1
  3. data/guides/assets/stylesheets/fixes.css +16 -0
  4. data/guides/rails_guides.rb +2 -2
  5. data/guides/rails_guides/generator.rb +8 -3
  6. data/guides/rails_guides/textile_extensions.rb +4 -2
  7. data/guides/source/2_2_release_notes.textile +3 -3
  8. data/guides/source/2_3_release_notes.textile +2 -2
  9. data/guides/source/3_0_release_notes.textile +14 -14
  10. data/guides/source/action_controller_overview.textile +54 -79
  11. data/guides/source/action_mailer_basics.textile +39 -9
  12. data/guides/source/action_view_overview.textile +257 -211
  13. data/guides/source/active_record_basics.textile +1 -1
  14. data/guides/source/active_record_querying.textile +217 -27
  15. data/guides/source/active_record_validations_callbacks.textile +94 -25
  16. data/guides/source/active_support_core_extensions.textile +109 -77
  17. data/guides/source/ajax_on_rails.textile +15 -150
  18. data/guides/source/api_documentation_guidelines.textile +12 -12
  19. data/guides/source/association_basics.textile +74 -60
  20. data/guides/source/caching_with_rails.textile +59 -60
  21. data/guides/source/command_line.textile +46 -47
  22. data/guides/source/configuring.textile +55 -37
  23. data/guides/source/contribute.textile +7 -7
  24. data/guides/source/contributing_to_ruby_on_rails.textile +14 -23
  25. data/guides/source/credits.html.erb +3 -3
  26. data/guides/source/debugging_rails_applications.textile +59 -46
  27. data/guides/source/form_helpers.textile +76 -31
  28. data/guides/source/generators.textile +39 -40
  29. data/guides/source/getting_started.textile +73 -94
  30. data/guides/source/i18n.textile +64 -58
  31. data/guides/source/index.html.erb +3 -3
  32. data/guides/source/initialization.textile +634 -3284
  33. data/guides/source/layout.html.erb +6 -7
  34. data/guides/source/layouts_and_rendering.textile +59 -60
  35. data/guides/source/migrations.textile +63 -59
  36. data/guides/source/nested_model_forms.textile +2 -2
  37. data/guides/source/performance_testing.textile +16 -16
  38. data/guides/source/plugins.textile +236 -1280
  39. data/guides/source/rails_application_templates.textile +37 -29
  40. data/guides/source/rails_on_rack.textile +4 -9
  41. data/guides/source/routing.textile +96 -75
  42. data/guides/source/ruby_on_rails_guides_guidelines.textile +19 -12
  43. data/guides/source/security.textile +57 -30
  44. data/guides/source/testing.textile +26 -24
  45. data/guides/w3c_validator.rb +2 -2
  46. data/lib/rails.rb +1 -7
  47. data/lib/rails/application.rb +46 -76
  48. data/lib/rails/application/bootstrap.rb +6 -11
  49. data/lib/rails/application/configuration.rb +43 -40
  50. data/lib/rails/application/finisher.rb +16 -4
  51. data/lib/rails/application/railties.rb +6 -24
  52. data/lib/rails/application/routes_reloader.rb +45 -0
  53. data/lib/rails/backtrace_cleaner.rb +1 -1
  54. data/lib/rails/cli.rb +7 -5
  55. data/lib/rails/commands.rb +27 -2
  56. data/lib/rails/commands/application.rb +14 -1
  57. data/lib/rails/commands/benchmarker.rb +3 -1
  58. data/lib/rails/commands/dbconsole.rb +2 -2
  59. data/lib/rails/commands/destroy.rb +3 -1
  60. data/lib/rails/commands/generate.rb +3 -1
  61. data/lib/rails/commands/plugin.rb +2 -7
  62. data/lib/rails/commands/plugin_new.rb +10 -0
  63. data/lib/rails/commands/profiler.rb +3 -1
  64. data/lib/rails/commands/server.rb +4 -0
  65. data/lib/rails/configuration.rb +8 -81
  66. data/lib/rails/console/app.rb +2 -2
  67. data/lib/rails/engine.rb +460 -78
  68. data/lib/rails/engine/configuration.rb +46 -49
  69. data/lib/rails/engine/railties.rb +33 -0
  70. data/lib/rails/generators.rb +11 -5
  71. data/lib/rails/generators/actions.rb +2 -27
  72. data/lib/rails/generators/app_base.rb +216 -0
  73. data/lib/rails/generators/base.rb +3 -2
  74. data/lib/rails/generators/erb/scaffold/templates/index.html.erb +1 -1
  75. data/lib/rails/generators/generated_attribute.rb +2 -1
  76. data/lib/rails/generators/migration.rb +6 -2
  77. data/lib/rails/generators/named_base.rb +79 -3
  78. data/lib/rails/generators/rails/app/app_generator.rb +44 -209
  79. data/lib/rails/generators/rails/app/templates/Gemfile +15 -31
  80. data/lib/rails/generators/rails/app/templates/README +2 -2
  81. data/lib/rails/generators/rails/app/templates/Rakefile +1 -1
  82. data/lib/rails/generators/rails/app/templates/{public → app/assets}/images/rails.png +0 -0
  83. data/lib/rails/generators/rails/app/templates/app/assets/javascripts/application.js.tt +8 -0
  84. data/lib/rails/generators/rails/app/templates/app/assets/stylesheets/application.css +5 -0
  85. data/lib/rails/generators/rails/app/templates/app/mailers/.empty_directory +0 -0
  86. data/lib/rails/generators/rails/app/templates/app/models/.empty_directory +0 -0
  87. data/lib/rails/generators/rails/app/templates/app/views/layouts/application.html.erb.tt +4 -4
  88. data/lib/rails/generators/rails/app/templates/config/application.rb +19 -3
  89. data/lib/rails/generators/rails/app/templates/config/databases/jdbcmysql.yml +4 -4
  90. data/lib/rails/generators/rails/app/templates/config/databases/jdbcpostgresql.yml +11 -6
  91. data/lib/rails/generators/rails/app/templates/config/databases/jdbcsqlite3.yml +3 -3
  92. data/lib/rails/generators/rails/app/templates/config/databases/oracle.yml +1 -1
  93. data/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt +1 -2
  94. data/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt +14 -11
  95. data/lib/rails/generators/rails/app/templates/config/environments/test.rb.tt +5 -1
  96. data/lib/rails/generators/rails/app/templates/config/initializers/session_store.rb.tt +1 -1
  97. data/lib/rails/generators/rails/app/templates/config/initializers/wrap_parameters.rb.tt +12 -0
  98. data/lib/rails/generators/rails/app/templates/config/locales/en.yml +1 -1
  99. data/lib/rails/generators/rails/app/templates/config/routes.rb +1 -1
  100. data/lib/rails/generators/rails/app/templates/db/{seeds.rb → seeds.rb.tt} +2 -2
  101. data/lib/rails/generators/rails/app/templates/public/index.html +10 -8
  102. data/lib/rails/generators/rails/app/templates/public/stylesheets/.empty_directory +0 -0
  103. data/lib/rails/generators/rails/app/templates/test/fixtures/.empty_directory +0 -0
  104. data/lib/rails/generators/rails/app/templates/test/functional/.empty_directory +0 -0
  105. data/lib/rails/generators/rails/app/templates/test/integration/.empty_directory +0 -0
  106. data/lib/rails/generators/rails/app/templates/test/{test_helper.rb.tt → test_helper.rb} +0 -0
  107. data/lib/rails/generators/rails/app/templates/test/unit/.empty_directory +0 -0
  108. data/lib/rails/generators/rails/assets/USAGE +20 -0
  109. data/lib/rails/generators/rails/assets/assets_generator.rb +39 -0
  110. data/lib/rails/generators/rails/assets/templates/javascript.js +2 -0
  111. data/lib/rails/generators/rails/assets/templates/javascript.js.coffee +3 -0
  112. data/lib/rails/generators/rails/assets/templates/stylesheet.css +4 -0
  113. data/lib/rails/generators/rails/assets/templates/stylesheet.css.scss +5 -0
  114. data/lib/rails/generators/rails/controller/controller_generator.rb +1 -1
  115. data/lib/rails/generators/rails/controller/templates/controller.rb +2 -0
  116. data/lib/rails/generators/rails/generator/generator_generator.rb +2 -2
  117. data/lib/rails/generators/rails/generator/templates/templates/.empty_directory +0 -0
  118. data/lib/rails/generators/rails/helper/templates/helper.rb +2 -0
  119. data/lib/rails/generators/rails/plugin/plugin_generator.rb +7 -0
  120. data/lib/rails/generators/rails/plugin/templates/Rakefile.tt +4 -4
  121. data/lib/rails/generators/rails/plugin_new/USAGE +10 -0
  122. data/lib/rails/generators/rails/plugin_new/plugin_new_generator.rb +303 -0
  123. data/lib/rails/generators/rails/plugin_new/templates/%name%.gemspec +9 -0
  124. data/lib/rails/generators/rails/plugin_new/templates/Gemfile +11 -0
  125. data/lib/rails/generators/rails/plugin_new/templates/MIT-LICENSE +20 -0
  126. data/lib/rails/generators/rails/plugin_new/templates/README.rdoc +3 -0
  127. data/lib/rails/generators/rails/plugin_new/templates/Rakefile +21 -0
  128. data/lib/rails/generators/rails/plugin_new/templates/app/controllers/%name%/application_controller.rb.tt +4 -0
  129. data/lib/rails/generators/rails/plugin_new/templates/app/helpers/%name%/application_helper.rb.tt +4 -0
  130. data/lib/rails/generators/rails/plugin_new/templates/app/models/.empty_directory +0 -0
  131. data/lib/rails/generators/rails/plugin_new/templates/config/routes.rb +6 -0
  132. data/lib/rails/generators/rails/plugin_new/templates/gitignore +6 -0
  133. data/lib/rails/generators/rails/plugin_new/templates/lib/%name%.rb +6 -0
  134. data/lib/rails/generators/rails/plugin_new/templates/lib/%name%/engine.rb +7 -0
  135. data/lib/rails/generators/rails/plugin_new/templates/lib/tasks/%name%_tasks.rake +4 -0
  136. data/lib/rails/generators/rails/plugin_new/templates/rails/application.rb +16 -0
  137. data/lib/rails/generators/rails/plugin_new/templates/rails/boot.rb +10 -0
  138. data/lib/rails/generators/rails/plugin_new/templates/rails/routes.rb +4 -0
  139. data/lib/rails/generators/rails/plugin_new/templates/script/rails.tt +5 -0
  140. data/lib/rails/generators/rails/plugin_new/templates/test/%name%_test.rb +7 -0
  141. data/lib/rails/generators/rails/plugin_new/templates/test/integration/navigation_test.rb +12 -0
  142. data/lib/rails/generators/rails/plugin_new/templates/test/test_helper.rb +10 -0
  143. data/lib/rails/generators/rails/resource/resource_generator.rb +2 -2
  144. data/lib/rails/generators/rails/scaffold/scaffold_generator.rb +20 -1
  145. data/lib/rails/generators/rails/{stylesheets → scaffold}/templates/scaffold.css +0 -0
  146. data/lib/rails/generators/rails/scaffold/templates/scaffold.css.scss +58 -0
  147. data/lib/rails/generators/rails/scaffold_controller/templates/controller.rb +21 -19
  148. data/lib/rails/generators/resource_helpers.rb +3 -3
  149. data/lib/rails/generators/test_case.rb +2 -20
  150. data/lib/rails/generators/test_unit/controller/templates/functional_test.rb +5 -4
  151. data/lib/rails/generators/test_unit/helper/templates/helper_test.rb +2 -0
  152. data/lib/rails/generators/test_unit/integration/templates/integration_test.rb +3 -4
  153. data/lib/rails/generators/test_unit/mailer/templates/functional_test.rb +5 -4
  154. data/lib/rails/generators/test_unit/model/templates/fixtures.yml +1 -1
  155. data/lib/rails/generators/test_unit/model/templates/unit_test.rb +5 -4
  156. data/lib/rails/generators/test_unit/observer/templates/unit_test.rb +5 -4
  157. data/lib/rails/generators/test_unit/plugin/templates/%file_name%_test.rb.tt +3 -4
  158. data/lib/rails/generators/test_unit/scaffold/templates/functional_test.rb +7 -5
  159. data/lib/rails/info.rb +0 -1
  160. data/lib/rails/paths.rb +119 -65
  161. data/lib/rails/plugin.rb +18 -19
  162. data/lib/rails/rack/log_tailer.rb +1 -1
  163. data/lib/rails/railtie.rb +50 -47
  164. data/lib/rails/railtie/configurable.rb +20 -10
  165. data/lib/rails/railtie/configuration.rb +20 -19
  166. data/lib/rails/source_annotation_extractor.rb +5 -5
  167. data/lib/rails/tasks.rb +1 -0
  168. data/lib/rails/tasks/assets.rake +10 -0
  169. data/lib/rails/tasks/documentation.rake +2 -8
  170. data/lib/rails/tasks/engine.rake +69 -0
  171. data/lib/rails/tasks/framework.rake +4 -21
  172. data/lib/rails/tasks/misc.rake +1 -1
  173. data/lib/rails/tasks/routes.rake +2 -1
  174. data/lib/rails/test_help.rb +17 -1
  175. data/lib/rails/test_unit/railtie.rb +1 -1
  176. data/lib/rails/test_unit/testing.rake +8 -3
  177. data/lib/rails/version.rb +3 -3
  178. metadata +128 -100
  179. checksums.yaml +0 -7
  180. data/lib/rails/application/configurable.rb +0 -19
  181. data/lib/rails/console/sandbox.rb +0 -6
  182. data/lib/rails/deprecation.rb +0 -41
  183. data/lib/rails/engine/configurable.rb +0 -25
  184. data/lib/rails/generators/rails/app/templates/config/databases/jdbc.yml +0 -62
  185. data/lib/rails/generators/rails/app/templates/public/javascripts/application.js +0 -2
  186. data/lib/rails/generators/rails/app/templates/public/javascripts/controls.js +0 -965
  187. data/lib/rails/generators/rails/app/templates/public/javascripts/dragdrop.js +0 -974
  188. data/lib/rails/generators/rails/app/templates/public/javascripts/effects.js +0 -1123
  189. data/lib/rails/generators/rails/app/templates/public/javascripts/prototype.js +0 -6001
  190. data/lib/rails/generators/rails/app/templates/public/javascripts/rails.js +0 -202
  191. data/lib/rails/generators/rails/stylesheets/USAGE +0 -5
  192. data/lib/rails/generators/rails/stylesheets/stylesheets_generator.rb +0 -9
  193. data/lib/rails/info_routes.rb +0 -3
@@ -1,11 +1,11 @@
1
1
  require 'test_helper'
2
2
 
3
+ <% module_namespacing do -%>
3
4
  class <%= class_name %>ControllerTest < ActionController::TestCase
4
5
  <% if actions.empty? -%>
5
- # Replace this with your real tests.
6
- test "the truth" do
7
- assert true
8
- end
6
+ # test "the truth" do
7
+ # assert true
8
+ # end
9
9
  <% else -%>
10
10
  <% for action in actions -%>
11
11
  test "should get <%= action %>" do
@@ -16,3 +16,4 @@ class <%= class_name %>ControllerTest < ActionController::TestCase
16
16
  <% end -%>
17
17
  <% end -%>
18
18
  end
19
+ <% end -%>
@@ -1,4 +1,6 @@
1
1
  require 'test_helper'
2
2
 
3
+ <% module_namespacing do -%>
3
4
  class <%= class_name %>HelperTest < ActionView::TestCase
4
5
  end
6
+ <% end -%>
@@ -3,8 +3,7 @@ require 'test_helper'
3
3
  class <%= class_name %>Test < ActionDispatch::IntegrationTest
4
4
  fixtures :all
5
5
 
6
- # Replace this with your real tests.
7
- test "the truth" do
8
- assert true
9
- end
6
+ # test "the truth" do
7
+ # assert true
8
+ # end
10
9
  end
@@ -1,5 +1,6 @@
1
1
  require 'test_helper'
2
2
 
3
+ <% module_namespacing do -%>
3
4
  class <%= class_name %>Test < ActionMailer::TestCase
4
5
  <% for action in actions -%>
5
6
  test "<%= action %>" do
@@ -12,9 +13,9 @@ class <%= class_name %>Test < ActionMailer::TestCase
12
13
 
13
14
  <% end -%>
14
15
  <% if actions.blank? -%>
15
- # replace this with your real tests
16
- test "the truth" do
17
- assert true
18
- end
16
+ # test "the truth" do
17
+ # assert true
18
+ # end
19
19
  <% end -%>
20
20
  end
21
+ <% end -%>
@@ -1,4 +1,4 @@
1
- # Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
1
+ # Read about fixtures at http://api.rubyonrails.org/classes/Fixtures.html
2
2
 
3
3
  <% unless attributes.empty? -%>
4
4
  one:
@@ -1,8 +1,9 @@
1
1
  require 'test_helper'
2
2
 
3
+ <% module_namespacing do -%>
3
4
  class <%= class_name %>Test < ActiveSupport::TestCase
4
- # Replace this with your real tests.
5
- test "the truth" do
6
- assert true
7
- end
5
+ # test "the truth" do
6
+ # assert true
7
+ # end
8
8
  end
9
+ <% end -%>
@@ -1,8 +1,9 @@
1
1
  require 'test_helper'
2
2
 
3
+ <% module_namespacing do -%>
3
4
  class <%= class_name %>ObserverTest < ActiveSupport::TestCase
4
- # Replace this with your real tests.
5
- test "the truth" do
6
- assert true
7
- end
5
+ # test "the truth" do
6
+ # assert true
7
+ # end
8
8
  end
9
+ <% end -%>
@@ -1,8 +1,7 @@
1
1
  require 'test_helper'
2
2
 
3
3
  class <%= class_name %>Test < ActiveSupport::TestCase
4
- # Replace this with your real tests.
5
- test "the truth" do
6
- assert true
7
- end
4
+ # test "the truth" do
5
+ # assert true
6
+ # end
8
7
  end
@@ -1,5 +1,6 @@
1
1
  require 'test_helper'
2
2
 
3
+ <% module_namespacing do -%>
3
4
  class <%= controller_class_name %>ControllerTest < ActionController::TestCase
4
5
  setup do
5
6
  @<%= singular_table_name %> = <%= table_name %>(:one)
@@ -18,32 +19,33 @@ class <%= controller_class_name %>ControllerTest < ActionController::TestCase
18
19
 
19
20
  test "should create <%= singular_table_name %>" do
20
21
  assert_difference('<%= class_name %>.count') do
21
- post :create, :<%= singular_table_name %> => @<%= singular_table_name %>.attributes
22
+ post :create, <%= key_value singular_table_name, "@#{singular_table_name}.attributes" %>
22
23
  end
23
24
 
24
25
  assert_redirected_to <%= singular_table_name %>_path(assigns(:<%= singular_table_name %>))
25
26
  end
26
27
 
27
28
  test "should show <%= singular_table_name %>" do
28
- get :show, :id => @<%= singular_table_name %>.to_param
29
+ get :show, <%= key_value :id, "@#{singular_table_name}.to_param" %>
29
30
  assert_response :success
30
31
  end
31
32
 
32
33
  test "should get edit" do
33
- get :edit, :id => @<%= singular_table_name %>.to_param
34
+ get :edit, <%= key_value :id, "@#{singular_table_name}.to_param" %>
34
35
  assert_response :success
35
36
  end
36
37
 
37
38
  test "should update <%= singular_table_name %>" do
38
- put :update, :id => @<%= singular_table_name %>.to_param, :<%= singular_table_name %> => @<%= singular_table_name %>.attributes
39
+ put :update, <%= key_value :id, "@#{singular_table_name}.to_param" %>, <%= key_value singular_table_name, "@#{singular_table_name}.attributes" %>
39
40
  assert_redirected_to <%= singular_table_name %>_path(assigns(:<%= singular_table_name %>))
40
41
  end
41
42
 
42
43
  test "should destroy <%= singular_table_name %>" do
43
44
  assert_difference('<%= class_name %>.count', -1) do
44
- delete :destroy, :id => @<%= singular_table_name %>.to_param
45
+ delete :destroy, <%= key_value :id, "@#{singular_table_name}.to_param" %>
45
46
  end
46
47
 
47
48
  assert_redirected_to <%= index_helper %>_path
48
49
  end
49
50
  end
51
+ <% end -%>
@@ -1,5 +1,4 @@
1
1
  require "cgi"
2
- require "active_support/core_ext/cgi"
3
2
 
4
3
  module Rails
5
4
  module Info
@@ -2,15 +2,17 @@ require 'set'
2
2
 
3
3
  module Rails
4
4
  module Paths
5
- module PathParent
6
- attr_reader :children
7
-
5
+ module PathParent #:nodoc:
8
6
  def method_missing(id, *args)
9
- name = id.to_s
7
+ match = id.to_s.match(/^(.*)=$/)
8
+ full = [@current, $1 || id].compact.join("/")
9
+
10
+ ActiveSupport::Deprecation.warn 'config.paths.app.controller API is deprecated in ' <<
11
+ 'favor of config.paths["app/controller"] API.'
10
12
 
11
- if name =~ /^(.*)=$/ || args.any?
12
- @children[$1 || name] = Path.new(@root, *args)
13
- elsif path = @children[name]
13
+ if match || args.any?
14
+ @root[full] = Path.new(@root, full, *args)
15
+ elsif path = @root[full]
14
16
  path
15
17
  else
16
18
  super
@@ -18,22 +20,72 @@ module Rails
18
20
  end
19
21
  end
20
22
 
21
- class Root
23
+ # This object is an extended hash that behaves as root of the Rails::Paths system.
24
+ # It allows you to collect information about how you want to structure your application
25
+ # paths by a Hash like API. It requires you to give a physical path on initialization.
26
+ #
27
+ # root = Root.new
28
+ # root.add "app/controllers", :eager_load => true
29
+ #
30
+ # 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:
32
+ #
33
+ # path = root["app/controllers"]
34
+ # path.eager_load? # => true
35
+ # path.is_a?(Rails::Paths::Path) # => true
36
+ #
37
+ # The Path object is simply an array and allows you to easily add extra paths:
38
+ #
39
+ # path.is_a?(Array) # => true
40
+ # path.inspect # => ["app/controllers"]
41
+ #
42
+ # path << "lib/controllers"
43
+ # path.inspect # => ["app/controllers", "lib/controllers"]
44
+ #
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,
47
+ # you may not want this behavior, so you can give :with as option.
48
+ #
49
+ # root.add "config/routes", :with => "config/routes.rb"
50
+ # root["config/routes"].inspect # => ["config/routes.rb"]
51
+ #
52
+ # #add also accepts the following options as argument: eager_load, autoload,
53
+ # autoload_once and glob.
54
+ #
55
+ # Finally, the Path object also provides a few helpers:
56
+ #
57
+ # root = Root.new
58
+ # root.path = "/rails"
59
+ # root.add "app/controllers"
60
+ #
61
+ # root["app/controllers"].expanded # => ["/rails/app/controllers"]
62
+ # root["app/controllers"].existent # => ["/rails/app/controllers"]
63
+ #
64
+ # Check the Path documentation for more information.
65
+ class Root < ::Hash
22
66
  include PathParent
23
-
24
67
  attr_accessor :path
25
68
 
26
69
  def initialize(path)
27
70
  raise if path.is_a?(Array)
28
- @children = {}
71
+ @current = nil
29
72
  @path = path
30
73
  @root = self
31
- @all_paths = []
74
+ super()
75
+ end
76
+
77
+ def []=(path, value)
78
+ value = Path.new(self, path, value) unless value.is_a?(Path)
79
+ super(path, value)
80
+ end
81
+
82
+ def add(path, options={})
83
+ with = options[:with] || path
84
+ self[path] = Path.new(self, path, with, options)
32
85
  end
33
86
 
34
87
  def all_paths
35
- @all_paths.uniq!
36
- @all_paths
88
+ values.tap { |v| v.uniq! }
37
89
  end
38
90
 
39
91
  def autoload_once
@@ -52,100 +104,102 @@ module Rails
52
104
  filter_by(:load_path?)
53
105
  end
54
106
 
55
- def push(*)
56
- raise "Application root can only have one physical path"
57
- end
58
-
59
- alias unshift push
60
- alias << push
61
- alias concat push
62
-
63
107
  protected
64
108
 
65
109
  def filter_by(constraint)
66
110
  all = []
67
111
  all_paths.each do |path|
68
112
  if path.send(constraint)
69
- paths = path.paths
70
- paths -= path.children.values.map { |p| p.send(constraint) ? [] : p.paths }.flatten
113
+ paths = path.existent
114
+ paths -= path.children.map { |p| p.send(constraint) ? [] : p.existent }.flatten
71
115
  all.concat(paths)
72
116
  end
73
117
  end
74
118
  all.uniq!
75
- all.reject! { |p| !File.exists?(p) }
76
119
  all
77
120
  end
78
121
  end
79
122
 
80
- class Path
81
- include PathParent, Enumerable
123
+ class Path < Array
124
+ include PathParent
82
125
 
83
126
  attr_reader :path
84
127
  attr_accessor :glob
85
128
 
86
- def initialize(root, *paths)
87
- options = paths.last.is_a?(::Hash) ? paths.pop : {}
88
- @children = {}
129
+ def initialize(root, current, *paths)
130
+ options = paths.last.is_a?(::Hash) ? paths.pop : {}
131
+ super(paths.flatten)
132
+
133
+ @current = current
89
134
  @root = root
90
- @paths = paths.flatten
91
135
  @glob = options[:glob]
92
136
 
93
- autoload_once! if options[:autoload_once]
94
- eager_load! if options[:eager_load]
95
- autoload! if options[:autoload]
96
- load_path! if options[:load_path]
97
-
98
- @root.all_paths << self
137
+ options[:autoload_once] ? autoload_once! : skip_autoload_once!
138
+ options[:eager_load] ? eager_load! : skip_eager_load!
139
+ options[:autoload] ? autoload! : skip_autoload!
140
+ options[:load_path] ? load_path! : skip_load_path!
99
141
  end
100
142
 
101
- def each
102
- to_a.each { |p| yield p }
143
+ def children
144
+ keys = @root.keys.select { |k| k.include?(@current) }
145
+ keys.delete(@current)
146
+ @root.values_at(*keys.sort)
103
147
  end
104
148
 
105
- def push(path)
106
- @paths.push path
149
+ def first
150
+ expanded.first
107
151
  end
108
152
 
109
- alias << push
110
-
111
- def unshift(path)
112
- @paths.unshift path
113
- end
114
-
115
- def concat(paths)
116
- @paths.concat paths
153
+ def last
154
+ expanded.last
117
155
  end
118
156
 
119
157
  %w(autoload_once eager_load autoload load_path).each do |m|
120
158
  class_eval <<-RUBY, __FILE__, __LINE__ + 1
121
- def #{m}!
122
- @#{m} = true
123
- end
124
-
125
- def skip_#{m}!
126
- @#{m} = false
127
- end
128
-
129
- def #{m}?
130
- @#{m}
131
- end
159
+ def #{m}! # def eager_load!
160
+ @#{m} = true # @eager_load = true
161
+ end # end
162
+ #
163
+ def skip_#{m}! # def skip_eager_load!
164
+ @#{m} = false # @eager_load = false
165
+ end # end
166
+ #
167
+ def #{m}? # def eager_load?
168
+ @#{m} # @eager_load
169
+ end # end
132
170
  RUBY
133
171
  end
134
172
 
135
- def paths
173
+ # Expands all paths against the root and return all unique values.
174
+ def expanded
136
175
  raise "You need to set a path root" unless @root.path
176
+ result = []
137
177
 
138
- result = @paths.map do |p|
178
+ each do |p|
139
179
  path = File.expand_path(p, @root.path)
140
- @glob ? Dir[File.join(path, @glob)] : path
180
+
181
+ if @glob
182
+ result.concat Dir[File.join(path, @glob)]
183
+ else
184
+ result << path
185
+ end
141
186
  end
142
187
 
143
- result.flatten!
144
188
  result.uniq!
145
189
  result
146
190
  end
147
191
 
148
- alias to_a paths
192
+ # Returns all expanded paths but only if they exist in the filesystem.
193
+ def existent
194
+ expanded.select { |f| File.exists?(f) }
195
+ end
196
+
197
+ def paths
198
+ ActiveSupport::Deprecation.warn "paths is deprecated. Please call expand instead."
199
+ expanded
200
+ end
201
+
202
+ alias to_a expanded
149
203
  end
150
204
  end
151
- end
205
+ end
@@ -18,6 +18,10 @@ module Rails
18
18
  # root during the boot process.
19
19
  #
20
20
  class Plugin < Engine
21
+ def self.global_plugins
22
+ @global_plugins ||= []
23
+ end
24
+
21
25
  def self.inherited(base)
22
26
  raise "You cannot inherit from Rails::Plugin"
23
27
  end
@@ -28,6 +32,11 @@ module Rails
28
32
  Dir["#{path}/*"].each do |plugin_path|
29
33
  plugin = new(plugin_path)
30
34
  next unless list.include?(plugin.name) || list.include?(:all)
35
+ if global_plugins.include?(plugin.name)
36
+ warn "WARNING: plugin #{plugin.name} from #{path} was not loaded. Plugin with the same name has been already loaded."
37
+ next
38
+ end
39
+ global_plugins << plugin.name
31
40
  plugins << plugin
32
41
  end
33
42
  end
@@ -39,17 +48,8 @@ module Rails
39
48
 
40
49
  attr_reader :name, :path
41
50
 
42
- def load_tasks
43
- super
44
- load_deprecated_tasks
45
- end
46
-
47
- def load_deprecated_tasks
48
- tasks = Dir["#{root}/{tasks,rails/tasks}/**/*.rake"].sort
49
- if tasks.any?
50
- ActiveSupport::Deprecation.warn "Rake tasks in #{tasks.to_sentence} are deprecated. Use lib/tasks instead"
51
- tasks.each { |ext| load(ext) }
52
- end
51
+ def railtie_name
52
+ name.to_s
53
53
  end
54
54
 
55
55
  def initialize(root)
@@ -62,23 +62,22 @@ module Rails
62
62
  end
63
63
 
64
64
  initializer :handle_lib_autoload, :before => :set_load_path do |app|
65
- paths = if app.config.reload_plugins
65
+ autoload = if app.config.reload_plugins
66
66
  config.autoload_paths
67
67
  else
68
68
  config.autoload_once_paths
69
69
  end
70
70
 
71
- paths.concat config.paths.lib.to_a
71
+ autoload.concat paths["lib"].existent
72
72
  end
73
73
 
74
74
  initializer :load_init_rb, :before => :load_config_initializers do |app|
75
- files = %w(rails/init.rb init.rb).map { |path| File.expand_path path, root }
76
- if initrb = files.find { |path| File.file? path }
77
- if initrb == files.first
78
- ActiveSupport::Deprecation.warn "Use toplevel init.rb; rails/init.rb is deprecated: #{initrb}"
79
- end
75
+ init_rb = File.expand_path("init.rb", root)
76
+ if File.file?(init_rb)
80
77
  config = app.config
81
- eval(File.read(initrb), binding, initrb)
78
+ # TODO: think about evaling initrb in context of Engine (currently it's
79
+ # always evaled in context of Rails::Application)
80
+ eval(File.read(init_rb), binding, init_rb)
82
81
  end
83
82
  end
84
83