rails 1.2.6 → 2.0.0

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 (148) hide show
  1. data/CHANGELOG +491 -12
  2. data/MIT-LICENSE +1 -1
  3. data/README +17 -25
  4. data/Rakefile +41 -18
  5. data/bin/about +1 -1
  6. data/bin/console +1 -1
  7. data/bin/destroy +1 -1
  8. data/bin/generate +1 -1
  9. data/bin/performance/request +3 -0
  10. data/bin/plugin +1 -1
  11. data/bin/runner +1 -1
  12. data/bin/server +1 -1
  13. data/builtin/rails_info/rails/info.rb +2 -2
  14. data/configs/apache.conf +1 -1
  15. data/configs/databases/mysql.yml +9 -3
  16. data/configs/databases/postgresql.yml +16 -12
  17. data/configs/initializers/inflections.rb +10 -0
  18. data/configs/initializers/mime_types.rb +5 -0
  19. data/configs/routes.rb +23 -11
  20. data/doc/README_FOR_APP +1 -1
  21. data/environments/boot.rb +95 -26
  22. data/environments/development.rb +2 -5
  23. data/environments/environment.rb +24 -25
  24. data/environments/test.rb +4 -1
  25. data/helpers/application.rb +5 -2
  26. data/helpers/test_helper.rb +10 -0
  27. data/html/422.html +30 -0
  28. data/html/500.html +1 -1
  29. data/html/index.html +2 -2
  30. data/html/javascripts/controls.js +484 -354
  31. data/html/javascripts/dragdrop.js +88 -58
  32. data/html/javascripts/effects.js +396 -364
  33. data/html/javascripts/prototype.js +2817 -1107
  34. data/html/robots.txt +5 -1
  35. data/lib/commands/console.rb +12 -5
  36. data/lib/commands/performance/request.rb +6 -0
  37. data/lib/commands/plugin.rb +15 -10
  38. data/lib/commands/process/spawner.rb +14 -4
  39. data/lib/commands/servers/base.rb +12 -0
  40. data/lib/commands/servers/mongrel.rb +5 -1
  41. data/lib/commands/servers/webrick.rb +14 -7
  42. data/lib/console_app.rb +5 -2
  43. data/lib/console_with_helpers.rb +5 -2
  44. data/lib/dispatcher.rb +3 -151
  45. data/lib/fcgi_handler.rb +79 -81
  46. data/lib/initializer.rb +125 -169
  47. data/lib/rails/plugin.rb +84 -0
  48. data/lib/rails/plugin/loader.rb +150 -0
  49. data/lib/rails/plugin/locator.rb +78 -0
  50. data/lib/rails/version.rb +3 -3
  51. data/lib/rails_generator/base.rb +11 -9
  52. data/lib/rails_generator/commands.rb +20 -10
  53. data/lib/rails_generator/generators/applications/app/USAGE +0 -7
  54. data/lib/rails_generator/generators/applications/app/app_generator.rb +25 -6
  55. data/lib/rails_generator/generators/components/controller/USAGE +11 -12
  56. data/lib/rails_generator/generators/components/controller/controller_generator.rb +2 -2
  57. data/lib/rails_generator/generators/components/controller/templates/functional_test.rb +1 -11
  58. data/lib/rails_generator/generators/components/controller/templates/{view.rhtml → view.html.erb} +0 -0
  59. data/lib/rails_generator/generators/components/integration_test/USAGE +5 -11
  60. data/lib/rails_generator/generators/components/mailer/USAGE +8 -10
  61. data/lib/rails_generator/generators/components/mailer/mailer_generator.rb +3 -3
  62. data/lib/rails_generator/generators/components/mailer/templates/fixture.erb +3 -0
  63. data/lib/rails_generator/generators/components/mailer/templates/fixture.rhtml +0 -3
  64. data/lib/rails_generator/generators/components/mailer/templates/unit_test.rb +8 -24
  65. data/lib/rails_generator/generators/components/mailer/templates/view.erb +3 -0
  66. data/lib/rails_generator/generators/components/mailer/templates/view.rhtml +0 -3
  67. data/lib/rails_generator/generators/components/migration/USAGE +23 -8
  68. data/lib/rails_generator/generators/components/migration/migration_generator.rb +15 -2
  69. data/lib/rails_generator/generators/components/migration/templates/migration.rb +6 -2
  70. data/lib/rails_generator/generators/components/model/USAGE +15 -14
  71. data/lib/rails_generator/generators/components/model/model_generator.rb +10 -3
  72. data/lib/rails_generator/generators/components/model/templates/fixtures.yml +11 -3
  73. data/lib/rails_generator/generators/components/model/templates/migration.rb +4 -1
  74. data/lib/rails_generator/generators/components/model/templates/unit_test.rb +1 -3
  75. data/lib/rails_generator/generators/components/observer/USAGE +5 -7
  76. data/lib/rails_generator/generators/components/observer/templates/unit_test.rb +0 -2
  77. data/lib/rails_generator/generators/components/plugin/USAGE +8 -18
  78. data/lib/rails_generator/generators/components/plugin/plugin_generator.rb +1 -0
  79. data/lib/rails_generator/generators/components/plugin/templates/MIT-LICENSE +20 -0
  80. data/lib/rails_generator/generators/components/plugin/templates/README +10 -1
  81. data/lib/rails_generator/generators/components/plugin/templates/USAGE +1 -1
  82. data/lib/rails_generator/generators/components/plugin/templates/init.rb +1 -1
  83. data/lib/rails_generator/generators/components/plugin/templates/plugin.rb +1 -1
  84. data/lib/rails_generator/generators/components/plugin/templates/tasks.rake +1 -1
  85. data/lib/rails_generator/generators/components/resource/USAGE +23 -0
  86. data/lib/rails_generator/generators/components/resource/resource_generator.rb +13 -15
  87. data/lib/rails_generator/generators/components/resource/templates/controller.rb +1 -1
  88. data/lib/rails_generator/generators/components/resource/templates/functional_test.rb +2 -14
  89. data/lib/rails_generator/generators/components/scaffold/USAGE +24 -31
  90. data/lib/rails_generator/generators/components/scaffold/scaffold_generator.rb +45 -146
  91. data/lib/rails_generator/generators/components/scaffold/templates/controller.rb +64 -37
  92. data/lib/rails_generator/generators/components/scaffold/templates/functional_test.rb +23 -80
  93. data/lib/rails_generator/generators/components/scaffold/templates/{layout.rhtml → layout.html.erb} +0 -0
  94. data/lib/rails_generator/generators/components/scaffold/templates/style.css +1 -1
  95. data/lib/rails_generator/generators/components/{scaffold_resource/templates/view_edit.rhtml → scaffold/templates/view_edit.html.erb} +4 -4
  96. data/lib/rails_generator/generators/components/{scaffold_resource/templates/view_index.rhtml → scaffold/templates/view_index.html.erb} +4 -4
  97. data/lib/rails_generator/generators/components/{scaffold_resource/templates/view_new.rhtml → scaffold/templates/view_new.html.erb} +3 -3
  98. data/lib/rails_generator/generators/components/{scaffold_resource/templates/view_show.rhtml → scaffold/templates/view_show.html.erb} +1 -1
  99. data/lib/rails_generator/generators/components/session_migration/USAGE +6 -11
  100. data/lib/rails_generator/generators/components/session_migration/templates/migration.rb +3 -3
  101. data/lib/rails_generator/lookup.rb +45 -10
  102. data/lib/rails_generator/scripts.rb +6 -3
  103. data/lib/rails_generator/scripts/destroy.rb +23 -0
  104. data/lib/rails_generator/secret_key_generator.rb +160 -0
  105. data/lib/rails_generator/spec.rb +1 -1
  106. data/lib/source_annotation_extractor.rb +62 -0
  107. data/lib/tasks/annotations.rake +23 -0
  108. data/lib/tasks/databases.rake +249 -83
  109. data/lib/tasks/documentation.rake +11 -13
  110. data/lib/tasks/framework.rake +1 -1
  111. data/lib/tasks/rails.rb +1 -1
  112. data/lib/tasks/testing.rake +5 -7
  113. data/lib/test_help.rb +4 -3
  114. data/lib/webrick_server.rb +3 -4
  115. metadata +31 -49
  116. data/bin/breakpointer +0 -3
  117. data/lib/binding_of_caller.rb +0 -85
  118. data/lib/breakpoint.rb +0 -553
  119. data/lib/breakpoint_client.rb +0 -196
  120. data/lib/commands/breakpointer.rb +0 -1
  121. data/lib/rails_generator/generators/components/resource/templates/USAGE +0 -18
  122. data/lib/rails_generator/generators/components/resource/templates/fixtures.yml +0 -11
  123. data/lib/rails_generator/generators/components/resource/templates/migration.rb +0 -13
  124. data/lib/rails_generator/generators/components/resource/templates/model.rb +0 -2
  125. data/lib/rails_generator/generators/components/resource/templates/unit_test.rb +0 -10
  126. data/lib/rails_generator/generators/components/scaffold/templates/form.rhtml +0 -3
  127. data/lib/rails_generator/generators/components/scaffold/templates/form_scaffolding.rhtml +0 -1
  128. data/lib/rails_generator/generators/components/scaffold/templates/view_edit.rhtml +0 -9
  129. data/lib/rails_generator/generators/components/scaffold/templates/view_list.rhtml +0 -27
  130. data/lib/rails_generator/generators/components/scaffold/templates/view_new.rhtml +0 -8
  131. data/lib/rails_generator/generators/components/scaffold/templates/view_show.rhtml +0 -8
  132. data/lib/rails_generator/generators/components/scaffold_resource/USAGE +0 -29
  133. data/lib/rails_generator/generators/components/scaffold_resource/scaffold_resource_generator.rb +0 -93
  134. data/lib/rails_generator/generators/components/scaffold_resource/templates/controller.rb +0 -79
  135. data/lib/rails_generator/generators/components/scaffold_resource/templates/fixtures.yml +0 -11
  136. data/lib/rails_generator/generators/components/scaffold_resource/templates/functional_test.rb +0 -57
  137. data/lib/rails_generator/generators/components/scaffold_resource/templates/helper.rb +0 -2
  138. data/lib/rails_generator/generators/components/scaffold_resource/templates/layout.rhtml +0 -17
  139. data/lib/rails_generator/generators/components/scaffold_resource/templates/migration.rb +0 -13
  140. data/lib/rails_generator/generators/components/scaffold_resource/templates/model.rb +0 -2
  141. data/lib/rails_generator/generators/components/scaffold_resource/templates/style.css +0 -74
  142. data/lib/rails_generator/generators/components/scaffold_resource/templates/unit_test.rb +0 -10
  143. data/lib/rails_generator/generators/components/web_service/USAGE +0 -28
  144. data/lib/rails_generator/generators/components/web_service/templates/api_definition.rb +0 -5
  145. data/lib/rails_generator/generators/components/web_service/templates/controller.rb +0 -8
  146. data/lib/rails_generator/generators/components/web_service/templates/functional_test.rb +0 -19
  147. data/lib/rails_generator/generators/components/web_service/web_service_generator.rb +0 -29
  148. data/lib/tasks/pre_namespace_aliases.rake +0 -53
@@ -1,58 +1,85 @@
1
1
  class <%= controller_class_name %>Controller < ApplicationController
2
- <% unless suffix -%>
2
+ # GET /<%= table_name %>
3
+ # GET /<%= table_name %>.xml
3
4
  def index
4
- list
5
- render :action => 'list'
6
- end
7
- <% end -%>
5
+ @<%= table_name %> = <%= class_name %>.find(:all)
8
6
 
9
- <% for action in unscaffolded_actions -%>
10
- def <%= action %><%= suffix %>
7
+ respond_to do |format|
8
+ format.html # index.html.erb
9
+ format.xml { render :xml => @<%= table_name %> }
10
+ end
11
11
  end
12
12
 
13
- <% end -%>
14
- # GETs should be safe (see http://www.w3.org/2001/tag/doc/whenToUseGet.html)
15
- verify :method => :post, :only => [ :destroy<%= suffix %>, :create<%= suffix %>, :update<%= suffix %> ],
16
- :redirect_to => { :action => :list<%= suffix %> }
13
+ # GET /<%= table_name %>/1
14
+ # GET /<%= table_name %>/1.xml
15
+ def show
16
+ @<%= file_name %> = <%= class_name %>.find(params[:id])
17
17
 
18
- def list<%= suffix %>
19
- @<%= singular_name %>_pages, @<%= plural_name %> = paginate :<%= plural_name %>, :per_page => 10
18
+ respond_to do |format|
19
+ format.html # show.html.erb
20
+ format.xml { render :xml => @<%= file_name %> }
21
+ end
20
22
  end
21
23
 
22
- def show<%= suffix %>
23
- @<%= singular_name %> = <%= model_name %>.find(params[:id])
24
- end
24
+ # GET /<%= table_name %>/new
25
+ # GET /<%= table_name %>/new.xml
26
+ def new
27
+ @<%= file_name %> = <%= class_name %>.new
25
28
 
26
- def new<%= suffix %>
27
- @<%= singular_name %> = <%= model_name %>.new
29
+ respond_to do |format|
30
+ format.html # new.html.erb
31
+ format.xml { render :xml => @<%= file_name %> }
32
+ end
28
33
  end
29
34
 
30
- def create<%= suffix %>
31
- @<%= singular_name %> = <%= model_name %>.new(params[:<%= singular_name %>])
32
- if @<%= singular_name %>.save
33
- flash[:notice] = '<%= model_name %> was successfully created.'
34
- redirect_to :action => 'list<%= suffix %>'
35
- else
36
- render :action => 'new<%= suffix %>'
37
- end
35
+ # GET /<%= table_name %>/1/edit
36
+ def edit
37
+ @<%= file_name %> = <%= class_name %>.find(params[:id])
38
38
  end
39
39
 
40
- def edit<%= suffix %>
41
- @<%= singular_name %> = <%= model_name %>.find(params[:id])
40
+ # POST /<%= table_name %>
41
+ # POST /<%= table_name %>.xml
42
+ def create
43
+ @<%= file_name %> = <%= class_name %>.new(params[:<%= file_name %>])
44
+
45
+ respond_to do |format|
46
+ if @<%= file_name %>.save
47
+ flash[:notice] = '<%= class_name %> was successfully created.'
48
+ format.html { redirect_to(@<%= file_name %>) }
49
+ format.xml { render :xml => @<%= file_name %>, :status => :created, :location => @<%= file_name %> }
50
+ else
51
+ format.html { render :action => "new" }
52
+ format.xml { render :xml => @<%= file_name %>.errors, :status => :unprocessable_entity }
53
+ end
54
+ end
42
55
  end
43
56
 
57
+ # PUT /<%= table_name %>/1
58
+ # PUT /<%= table_name %>/1.xml
44
59
  def update
45
- @<%= singular_name %> = <%= model_name %>.find(params[:id])
46
- if @<%= singular_name %>.update_attributes(params[:<%= singular_name %>])
47
- flash[:notice] = '<%= model_name %> was successfully updated.'
48
- redirect_to :action => 'show<%= suffix %>', :id => @<%= singular_name %>
49
- else
50
- render :action => 'edit<%= suffix %>'
60
+ @<%= file_name %> = <%= class_name %>.find(params[:id])
61
+
62
+ respond_to do |format|
63
+ if @<%= file_name %>.update_attributes(params[:<%= file_name %>])
64
+ flash[:notice] = '<%= class_name %> was successfully updated.'
65
+ format.html { redirect_to(@<%= file_name %>) }
66
+ format.xml { head :ok }
67
+ else
68
+ format.html { render :action => "edit" }
69
+ format.xml { render :xml => @<%= file_name %>.errors, :status => :unprocessable_entity }
70
+ end
51
71
  end
52
72
  end
53
73
 
54
- def destroy<%= suffix %>
55
- <%= model_name %>.find(params[:id]).destroy
56
- redirect_to :action => 'list<%= suffix %>'
74
+ # DELETE /<%= table_name %>/1
75
+ # DELETE /<%= table_name %>/1.xml
76
+ def destroy
77
+ @<%= file_name %> = <%= class_name %>.find(params[:id])
78
+ @<%= file_name %>.destroy
79
+
80
+ respond_to do |format|
81
+ format.html { redirect_to(<%= table_name %>_url) }
82
+ format.xml { head :ok }
83
+ end
57
84
  end
58
85
  end
@@ -1,102 +1,45 @@
1
- require File.dirname(__FILE__) + '<%= "/.." * controller_class_nesting_depth %>/../test_helper'
2
- require '<%= controller_file_path %>_controller'
1
+ require File.dirname(__FILE__) + '<%= '/..' * class_nesting_depth %>/../test_helper'
3
2
 
4
- # Re-raise errors caught by the controller.
5
- class <%= controller_class_name %>Controller; def rescue_action(e) raise e end; end
6
-
7
- class <%= controller_class_name %>ControllerTest < Test::Unit::TestCase
8
- fixtures :<%= table_name %>
9
-
10
- def setup
11
- @controller = <%= controller_class_name %>Controller.new
12
- @request = ActionController::TestRequest.new
13
- @response = ActionController::TestResponse.new
14
-
15
- @first_id = <%= plural_name %>(:first).id
16
- end
17
-
18
- <% for action in unscaffolded_actions -%>
19
- def test_<%= action %>
20
- get :<%= action %>
21
- assert_response :success
22
- assert_template '<%= action %>'
23
- end
24
-
25
- <% end -%>
26
- <% unless suffix -%>
27
- def test_index
3
+ class <%= controller_class_name %>ControllerTest < ActionController::TestCase
4
+ def test_should_get_index
28
5
  get :index
29
6
  assert_response :success
30
- assert_template 'list'
7
+ assert_not_nil assigns(:<%= table_name %>)
31
8
  end
32
9
 
33
- <% end -%>
34
- def test_list<%= suffix %>
35
- get :list<%= suffix %>
36
-
10
+ def test_should_get_new
11
+ get :new
37
12
  assert_response :success
38
- assert_template 'list<%= suffix %>'
39
-
40
- assert_not_nil assigns(:<%= plural_name %>)
41
13
  end
42
14
 
43
- def test_show<%= suffix %>
44
- get :show<%= suffix %>, :id => @first_id
45
-
46
- assert_response :success
47
- assert_template 'show'
15
+ def test_should_create_<%= file_name %>
16
+ assert_difference('<%= class_name %>.count') do
17
+ post :create, :<%= file_name %> => { }
18
+ end
48
19
 
49
- assert_not_nil assigns(:<%= singular_name %>)
50
- assert assigns(:<%= singular_name %>).valid?
20
+ assert_redirected_to <%= file_name %>_path(assigns(:<%= file_name %>))
51
21
  end
52
22
 
53
- def test_new<%= suffix %>
54
- get :new<%= suffix %>
55
-
23
+ def test_should_show_<%= file_name %>
24
+ get :show, :id => 1
56
25
  assert_response :success
57
- assert_template 'new<%= suffix %>'
58
-
59
- assert_not_nil assigns(:<%= singular_name %>)
60
26
  end
61
27
 
62
- def test_create
63
- num_<%= plural_name %> = <%= model_name %>.count
64
-
65
- post :create<%= suffix %>, :<%= singular_name %> => {}
66
-
67
- assert_response :redirect
68
- assert_redirected_to :action => 'list<%= suffix %>'
69
-
70
- assert_equal num_<%= plural_name %> + 1, <%= model_name %>.count
71
- end
72
-
73
- def test_edit<%= suffix %>
74
- get :edit<%= suffix %>, :id => @first_id
75
-
28
+ def test_should_get_edit
29
+ get :edit, :id => 1
76
30
  assert_response :success
77
- assert_template 'edit<%= suffix %>'
78
-
79
- assert_not_nil assigns(:<%= singular_name %>)
80
- assert assigns(:<%= singular_name %>).valid?
81
31
  end
82
32
 
83
- def test_update<%= suffix %>
84
- post :update<%= suffix %>, :id => @first_id
85
- assert_response :redirect
86
- assert_redirected_to :action => 'show<%= suffix %>', :id => @first_id
33
+ def test_should_update_<%= file_name %>
34
+ put :update, :id => 1, :<%= file_name %> => { }
35
+ assert_redirected_to <%= file_name %>_path(assigns(:<%= file_name %>))
87
36
  end
88
37
 
89
- def test_destroy<%= suffix %>
90
- assert_nothing_raised {
91
- <%= model_name %>.find(@first_id)
92
- }
93
-
94
- post :destroy, :id => @first_id
95
- assert_response :redirect
96
- assert_redirected_to :action => 'list<%= suffix %>'
38
+ def test_should_destroy_<%= file_name %>
39
+ assert_difference('<%= class_name %>.count', -1) do
40
+ delete :destroy, :id => 1
41
+ end
97
42
 
98
- assert_raise(ActiveRecord::RecordNotFound) {
99
- <%= model_name %>.find(@first_id)
100
- }
43
+ assert_redirected_to <%= table_name %>_path
101
44
  end
102
45
  end
@@ -62,7 +62,7 @@ div.progressBar {
62
62
 
63
63
  div.progressBar div.border {
64
64
  background-color: #fff;
65
- border: 1px solid grey;
65
+ border: 1px solid gray;
66
66
  width: 100%;
67
67
  }
68
68
 
@@ -2,7 +2,7 @@
2
2
 
3
3
  <%%= error_messages_for :<%= singular_name %> %>
4
4
 
5
- <%% form_for(:<%= singular_name %>, :url => <%= singular_name %>_path(@<%= singular_name %>), :html => { :method => :put }) do |f| %>
5
+ <%% form_for(@<%= singular_name %>) do |f| %>
6
6
  <% for attribute in attributes -%>
7
7
  <p>
8
8
  <b><%= attribute.column.human_name %></b><br />
@@ -11,9 +11,9 @@
11
11
 
12
12
  <% end -%>
13
13
  <p>
14
- <%%= submit_tag "Update" %>
14
+ <%%= f.submit "Update" %>
15
15
  </p>
16
16
  <%% end %>
17
17
 
18
- <%%= link_to 'Show', <%= singular_name %>_path(@<%= singular_name %>) %> |
19
- <%%= link_to 'Back', <%= plural_name %>_path %>
18
+ <%%= link_to 'Show', @<%= singular_name %> %> |
19
+ <%%= link_to 'Back', <%= plural_name %>_path %>
@@ -6,19 +6,19 @@
6
6
  <th><%= attribute.column.human_name %></th>
7
7
  <% end -%>
8
8
  </tr>
9
-
9
+
10
10
  <%% for <%= singular_name %> in @<%= plural_name %> %>
11
11
  <tr>
12
12
  <% for attribute in attributes -%>
13
13
  <td><%%=h <%= singular_name %>.<%= attribute.name %> %></td>
14
14
  <% end -%>
15
- <td><%%= link_to 'Show', <%= singular_name %>_path(<%= singular_name %>) %></td>
15
+ <td><%%= link_to 'Show', <%= singular_name %> %></td>
16
16
  <td><%%= link_to 'Edit', edit_<%= singular_name %>_path(<%= singular_name %>) %></td>
17
- <td><%%= link_to 'Destroy', <%= singular_name %>_path(<%= singular_name %>), :confirm => 'Are you sure?', :method => :delete %></td>
17
+ <td><%%= link_to 'Destroy', <%= singular_name %>, :confirm => 'Are you sure?', :method => :delete %></td>
18
18
  </tr>
19
19
  <%% end %>
20
20
  </table>
21
21
 
22
22
  <br />
23
23
 
24
- <%%= link_to 'New <%= singular_name %>', new_<%= singular_name %>_path %>
24
+ <%%= link_to 'New <%= singular_name %>', new_<%= singular_name %>_path %>
@@ -2,7 +2,7 @@
2
2
 
3
3
  <%%= error_messages_for :<%= singular_name %> %>
4
4
 
5
- <%% form_for(:<%= singular_name %>, :url => <%= plural_name %>_path) do |f| %>
5
+ <%% form_for(@<%= singular_name %>) do |f| %>
6
6
  <% for attribute in attributes -%>
7
7
  <p>
8
8
  <b><%= attribute.column.human_name %></b><br />
@@ -11,8 +11,8 @@
11
11
 
12
12
  <% end -%>
13
13
  <p>
14
- <%%= submit_tag "Create" %>
14
+ <%%= f.submit "Create" %>
15
15
  </p>
16
16
  <%% end %>
17
17
 
18
- <%%= link_to 'Back', <%= plural_name %>_path %>
18
+ <%%= link_to 'Back', <%= plural_name %>_path %>
@@ -7,4 +7,4 @@
7
7
  <% end -%>
8
8
 
9
9
  <%%= link_to 'Edit', edit_<%= singular_name %>_path(@<%= singular_name %>) %> |
10
- <%%= link_to 'Back', <%= plural_name %>_path %>
10
+ <%%= link_to 'Back', <%= plural_name %>_path %>
@@ -1,15 +1,10 @@
1
1
  Description:
2
- The session table migration generator creates a migration for adding a session table
3
- used by CGI::Session::ActiveRecordStore.
4
-
5
- The generator takes a migration name as its argument. The migration name may be
6
- given in CamelCase or under_score.
7
-
8
- The generator creates a migration class in db/migrate prefixed by its number
9
- in the queue.
2
+ Creates a migration to add the sessions table used by the Active Record
3
+ session store. Pass the migration name, either CamelCased or under_scored,
4
+ as an argument.
10
5
 
11
6
  Example:
12
- ./script/generate session_migration AddSessionTable
7
+ `./script/generate session_migration CreateSessionTable`
13
8
 
14
- With 4 existing migrations, this will create an AddSessionTable migration in the
15
- file db/migrate/005_add_session_table.rb
9
+ With 4 existing migrations, this creates the AddSessionTable migration
10
+ in db/migrate/005_add_session_table.rb
@@ -1,9 +1,9 @@
1
1
  class <%= class_name %> < ActiveRecord::Migration
2
2
  def self.up
3
3
  create_table :<%= session_table_name %> do |t|
4
- t.column :session_id, :string
5
- t.column :data, :text
6
- t.column :updated_at, :datetime
4
+ t.string :session_id, :null => false
5
+ t.text :data
6
+ t.timestamps
7
7
  end
8
8
 
9
9
  add_index :<%= session_table_name %>, :session_id
@@ -46,7 +46,7 @@ module Rails
46
46
  #
47
47
  # A spec is not a generator: it's a description of where to find
48
48
  # the generator and how to create it. A source is anything that
49
- # yields generators from #each. PathSource and GemSource are provided.
49
+ # yields generators from #each. PathSource and GemGeneratorSource are provided.
50
50
  module Lookup
51
51
  def self.included(base)
52
52
  base.extend(ClassMethods)
@@ -92,18 +92,26 @@ module Rails
92
92
  # 1. Rails application. If RAILS_ROOT is defined we know we're
93
93
  # generating in the context of a Rails application, so search
94
94
  # RAILS_ROOT/generators.
95
- # 2. User home directory. Search ~/.rails/generators.
96
- # 3. RubyGems. Search for gems named *_generator.
97
- # 4. Builtins. Model, controller, mailer, scaffold.
95
+ # 2. Look in plugins, either for generators/ or rails_generators/
96
+ # directories within each plugin
97
+ # 3. User home directory. Search ~/.rails/generators.
98
+ # 4. RubyGems. Search for gems named *_generator, and look for
99
+ # generators within any RubyGem's
100
+ # /rails_generators/<generator_name>_generator.rb file.
101
+ # 5. Builtins. Model, controller, mailer, scaffold, and so on.
98
102
  def use_component_sources!
99
103
  reset_sources
100
104
  if defined? ::RAILS_ROOT
101
105
  sources << PathSource.new(:lib, "#{::RAILS_ROOT}/lib/generators")
102
106
  sources << PathSource.new(:vendor, "#{::RAILS_ROOT}/vendor/generators")
103
- sources << PathSource.new(:plugins, "#{::RAILS_ROOT}/vendor/plugins/**/generators")
107
+ sources << PathSource.new(:plugins, "#{::RAILS_ROOT}/vendor/plugins/*/**/generators")
108
+ sources << PathSource.new(:plugins, "#{::RAILS_ROOT}/vendor/plugins/*/**/rails_generators")
104
109
  end
105
110
  sources << PathSource.new(:user, "#{Dir.user_home}/.rails/generators")
106
- sources << GemSource.new if Object.const_defined?(:Gem)
111
+ if Object.const_defined?(:Gem)
112
+ sources << GemGeneratorSource.new
113
+ sources << GemPathSource.new
114
+ end
107
115
  sources << PathSource.new(:builtin, "#{File.dirname(__FILE__)}/generators/components")
108
116
  end
109
117
 
@@ -185,14 +193,15 @@ module Rails
185
193
  end
186
194
  end
187
195
 
188
-
189
- # GemSource hits the mines to quarry for generators. The latest versions
190
- # of gems named *_generator are selected.
191
- class GemSource < Source
196
+ class AbstractGemSource < Source
192
197
  def initialize
193
198
  super :RubyGems
194
199
  end
200
+ end
195
201
 
202
+ # GemGeneratorSource hits the mines to quarry for generators. The latest versions
203
+ # of gems named *_generator are selected.
204
+ class GemGeneratorSource < AbstractGemSource
196
205
  # Yield latest versions of generator gems.
197
206
  def each
198
207
  Gem::cache.search(/_generator$/).inject({}) { |latest, gem|
@@ -205,5 +214,31 @@ module Rails
205
214
  end
206
215
  end
207
216
 
217
+ # GemPathSource looks for generators within any RubyGem's /rails_generators/<generator_name>_generator.rb file.
218
+ class GemPathSource < AbstractGemSource
219
+ # Yield each generator within rails_generator subdirectories.
220
+ def each
221
+ generator_full_paths.each do |generator|
222
+ yield Spec.new(File.basename(generator).sub(/_generator.rb$/, ''), File.dirname(generator), label)
223
+ end
224
+ end
225
+
226
+ private
227
+ def generator_full_paths
228
+ @generator_full_paths ||=
229
+ Gem::cache.inject({}) do |latest, name_gem|
230
+ name, gem = name_gem
231
+ hem = latest[gem.name]
232
+ latest[gem.name] = gem if hem.nil? or gem.version > hem.version
233
+ latest
234
+ end.values.inject([]) do |mem, gem|
235
+ Dir[gem.full_gem_path + '/{rails_,}generators/**/*_generator.rb'].each do |generator|
236
+ mem << generator
237
+ end
238
+ mem
239
+ end
240
+ end
241
+ end
242
+
208
243
  end
209
244
  end