railties 3.0.0.beta4 → 3.0.0.rc

Sign up to get free protection for your applications and to get access to all the features.
Files changed (113) hide show
  1. data/CHANGELOG +24 -6
  2. data/README.rdoc +25 -0
  3. data/guides/assets/javascripts/code_highlighter.js +0 -0
  4. data/guides/assets/javascripts/guides.js +0 -0
  5. data/guides/assets/stylesheets/print.css +0 -0
  6. data/guides/assets/stylesheets/reset.css +0 -0
  7. data/guides/assets/stylesheets/style.css +0 -0
  8. data/guides/source/3_0_release_notes.textile +5 -3
  9. data/guides/source/action_controller_overview.textile +19 -0
  10. data/guides/source/active_record_basics.textile +27 -21
  11. data/guides/source/active_record_querying.textile +39 -37
  12. data/guides/source/{activerecord_validations_callbacks.textile → active_record_validations_callbacks.textile} +30 -29
  13. data/guides/source/active_support_core_extensions.textile +232 -107
  14. data/guides/source/api_documentation_guidelines.textile +187 -0
  15. data/guides/source/association_basics.textile +45 -1
  16. data/guides/source/configuring.textile +7 -7
  17. data/guides/source/contributing_to_rails.textile +42 -15
  18. data/guides/source/form_helpers.textile +1 -1
  19. data/guides/source/generators.textile +37 -37
  20. data/guides/source/getting_started.textile +11 -11
  21. data/guides/source/i18n.textile +1 -1
  22. data/guides/source/index.html.erb +14 -6
  23. data/guides/source/initialization.textile +130 -124
  24. data/guides/source/layout.html.erb +5 -2
  25. data/guides/source/layouts_and_rendering.textile +2 -2
  26. data/guides/source/migrations.textile +4 -3
  27. data/guides/source/plugins.textile +15 -15
  28. data/guides/source/rails_application_templates.textile +2 -2
  29. data/guides/source/routing.textile +83 -62
  30. data/guides/source/security.textile +2 -2
  31. data/guides/w3c_validator.rb +30 -6
  32. data/lib/rails.rb +3 -3
  33. data/lib/rails/application.rb +43 -19
  34. data/lib/rails/application/bootstrap.rb +2 -0
  35. data/lib/rails/application/configuration.rb +3 -3
  36. data/lib/rails/application/finisher.rb +6 -6
  37. data/lib/rails/cli.rb +1 -19
  38. data/lib/rails/commands.rb +5 -5
  39. data/lib/rails/commands/application.rb +1 -1
  40. data/lib/rails/commands/console.rb +1 -4
  41. data/lib/rails/commands/generate.rb +0 -0
  42. data/lib/rails/commands/plugin.rb +57 -52
  43. data/lib/rails/commands/runner.rb +2 -1
  44. data/lib/rails/commands/server.rb +6 -2
  45. data/lib/rails/configuration.rb +2 -3
  46. data/lib/rails/console/app.rb +0 -2
  47. data/lib/rails/engine.rb +14 -15
  48. data/lib/rails/engine/configuration.rb +5 -5
  49. data/lib/rails/generators.rb +2 -3
  50. data/lib/rails/generators/actions.rb +4 -4
  51. data/lib/rails/generators/base.rb +1 -1
  52. data/lib/rails/generators/erb/scaffold/scaffold_generator.rb +1 -6
  53. data/lib/rails/generators/erb/scaffold/templates/_form.html.erb +4 -4
  54. data/lib/rails/generators/erb/scaffold/templates/edit.html.erb +3 -3
  55. data/lib/rails/generators/erb/scaffold/templates/index.html.erb +7 -7
  56. data/lib/rails/generators/erb/scaffold/templates/new.html.erb +2 -2
  57. data/lib/rails/generators/erb/scaffold/templates/show.html.erb +3 -3
  58. data/lib/rails/generators/generated_attribute.rb +2 -1
  59. data/lib/rails/generators/named_base.rb +24 -0
  60. data/lib/rails/generators/rails/app/app_generator.rb +10 -9
  61. data/lib/rails/generators/rails/app/templates/Gemfile +4 -3
  62. data/lib/rails/generators/rails/app/templates/README +6 -31
  63. data/lib/rails/generators/rails/app/templates/Rakefile +1 -1
  64. data/lib/rails/generators/rails/app/templates/app/controllers/application_controller.rb +0 -1
  65. data/lib/rails/generators/rails/app/templates/app/mailers/.empty_directory +0 -0
  66. data/lib/rails/generators/rails/app/templates/config/application.rb +11 -11
  67. data/lib/rails/generators/rails/app/templates/config/databases/ibm_db.yml +36 -24
  68. data/lib/rails/generators/rails/app/templates/config/databases/mysql.yml +1 -1
  69. data/lib/rails/generators/rails/app/templates/config/databases/oracle.yml +1 -1
  70. data/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt +3 -0
  71. data/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt +3 -0
  72. data/lib/rails/generators/rails/app/templates/config/environments/test.rb.tt +3 -0
  73. data/lib/rails/generators/rails/app/templates/config/initializers/inflections.rb +1 -1
  74. data/lib/rails/generators/rails/app/templates/config/initializers/secret_token.rb.tt +2 -2
  75. data/lib/rails/generators/rails/app/templates/config/initializers/session_store.rb.tt +2 -2
  76. data/lib/rails/generators/rails/app/templates/config/routes.rb +1 -1
  77. data/lib/rails/generators/rails/app/templates/public/index.html +0 -17
  78. data/lib/rails/generators/rails/app/templates/public/javascripts/prototype.js +2027 -900
  79. data/lib/rails/generators/rails/app/templates/public/javascripts/rails.js +114 -57
  80. data/lib/rails/generators/rails/app/templates/test/test_helper.rb.tt +1 -1
  81. data/lib/rails/generators/rails/model/USAGE +1 -1
  82. data/lib/rails/generators/rails/resource/resource_generator.rb +4 -14
  83. data/lib/rails/generators/rails/scaffold_controller/scaffold_controller_generator.rb +0 -2
  84. data/lib/rails/generators/rails/scaffold_controller/templates/controller.rb +28 -30
  85. data/lib/rails/generators/resource_helpers.rb +1 -1
  86. data/lib/rails/generators/test_case.rb +25 -11
  87. data/lib/rails/generators/test_unit/model/model_generator.rb +1 -1
  88. data/lib/rails/generators/test_unit/scaffold/scaffold_generator.rb +0 -1
  89. data/lib/rails/generators/test_unit/scaffold/templates/functional_test.rb +13 -15
  90. data/lib/rails/info.rb +1 -2
  91. data/lib/rails/info_routes.rb +1 -1
  92. data/lib/rails/initializable.rb +3 -16
  93. data/lib/rails/paths.rb +31 -36
  94. data/lib/rails/plugin.rb +10 -6
  95. data/lib/rails/rack/logger.rb +11 -13
  96. data/lib/rails/railtie.rb +14 -42
  97. data/lib/rails/ruby_version_check.rb +19 -5
  98. data/lib/rails/script_rails_loader.rb +29 -0
  99. data/lib/rails/tasks/annotations.rake +2 -2
  100. data/lib/rails/tasks/documentation.rake +47 -16
  101. data/lib/rails/tasks/framework.rake +9 -9
  102. data/lib/rails/tasks/middleware.rake +1 -1
  103. data/lib/rails/tasks/misc.rake +5 -5
  104. data/lib/rails/tasks/routes.rake +1 -1
  105. data/lib/rails/tasks/tmp.rake +5 -5
  106. data/lib/rails/test_unit/testing.rake +38 -14
  107. data/lib/rails/version.rb +1 -1
  108. metadata +29 -17
  109. data/README +0 -281
  110. data/lib/rails/application/routes_reloader.rb +0 -46
  111. data/lib/rails/log_subscriber.rb +0 -115
  112. data/lib/rails/log_subscriber/test_helper.rb +0 -97
  113. data/lib/rails/webrick_server.rb +0 -156
@@ -17,7 +17,7 @@ This guide is designed for beginners who want to get started with a Rails applic
17
17
 
18
18
  * The "Ruby":http://www.ruby-lang.org/en/downloads language version 1.8.7 or higher
19
19
 
20
- TIP: Note that Ruby 1.8.7 p248 and p249 has marshaling bugs that crash Rails 3.0.0. Ruby Enterprise Edition have these fixed since release 1.8.7-2010.02 though. On the 1.9 front, Ruby 1.9.1 is not usable because it outright segfaults on Rails 3.0.0, so if you want to use Rails 3 with 1.9.x jump on 1.9.2 for smooth sailing.
20
+ TIP: Note that Ruby 1.8.7 p248 and p249 have marshaling bugs that crash Rails 3.0. Ruby Enterprise Edition have these fixed since release 1.8.7-2010.02 though. On the 1.9 front, Ruby 1.9.1 is not usable because it outright segfaults on Rails 3.0, so if you want to use Rails 3 with 1.9.x jump on 1.9.2 for smooth sailing.
21
21
 
22
22
  * The "RubyGems":http://rubyforge.org/frs/?group_id=126 packaging system
23
23
  * A working installation of the "SQLite3 Database":http://www.sqlite.org
@@ -227,7 +227,7 @@ development:
227
227
  timeout: 5000
228
228
  </yaml>
229
229
 
230
- NOTE: In this guide we are using an SQLite3 database for data storage, this is because it is a zero configuration database that just works. Rails also supports MySQL and PostgreSQL "out of the box", and has plugins for many database systems, if you are using a database in a production environment, Rails most likely has an adapter for it.
230
+ NOTE: In this guide we are using an SQLite3 database for data storage, because it is a zero configuration database that just works. Rails also supports MySQL and PostgreSQL "out of the box", and has plugins for many database systems. If you are using a database in a production environment Rails most likely has an adapter for it.
231
231
 
232
232
  h5. Configuring a MySQL Database
233
233
 
@@ -322,16 +322,15 @@ $ rm public/index.html
322
322
 
323
323
  We need to do this as Rails will deliver any static file in the +public+ directory in preference to any dynamic contact we generate from the controllers.
324
324
 
325
- Now, you have to tell Rails where your actual home page is located. Open the file +config/routes.rb+ in your editor. This is your application's _routing file_ which holds entries in a special DSL (domain-specific language) that tells Rails how to connect incoming requests to controllers and actions. There are only comments in this file, so we need to add at the top the following:
325
+ Now, you have to tell Rails where your actual home page is located. Open the file +config/routes.rb+ in your editor. This is your application's _routing file_ which holds entries in a special DSL (domain-specific language) that tells Rails how to connect incoming requests to controllers and actions. This file contains many sample routes on commented lines, and one of them actually shows you how to connect the root of your site to a specific controller and action. Find the line beginning with +:root to+, uncomment it and change it like the following:
326
326
 
327
327
  <ruby>
328
- Blog::Application.routes.draw do |map|
328
+ Blog::Application.routes.draw do
329
329
 
330
- root :to => "home#index"
331
-
332
- # The priority is based upon order of creation:
333
- # first created -> highest priority.
334
330
  #...
331
+ # You can have the root of your site routed with "root"
332
+ # just remember to delete public/index.html.
333
+ root :to => "home#index"
335
334
  </ruby>
336
335
 
337
336
  The +root :to => "home#index"+ tells Rails to map the root action to the home controller's index action.
@@ -475,7 +474,7 @@ $ rails console
475
474
  After the console loads, you can use it to work with your application's models:
476
475
 
477
476
  <shell>
478
- >> p = Post.create(:content => "A new post")
477
+ >> p = Post.new(:content => "A new post")
479
478
  => #<Post id: nil, name: nil, title: nil,
480
479
  content: "A new post", created_at: nil,
481
480
  updated_at: nil>
@@ -958,7 +957,7 @@ You'll see a bit more complexity here than you did in the controller for posts.
958
957
 
959
958
  In addition, the code takes advantage of some of the methods available for an association. We use the +create+ method on +@post.comments+ to create and save the comment. This will automatically link the comment so that it belongs to that particular post.
960
959
 
961
- Once we have made the new comment, we send the user back to the original post using the +post_path(@post)+ helper. As we have already seen, this calls the +show+ action of the +PostsController+ which in turn renders the +show.html.erb+ template. This is where we want the comment to show, so let's add that to the +app/view/posts/show.html.erb+.
960
+ Once we have made the new comment, we send the user back to the original post using the +post_path(@post)+ helper. As we have already seen, this calls the +show+ action of the +PostsController+ which in turn renders the +show.html.erb+ template. This is where we want the comment to show, so let's add that to the +app/views/posts/show.html.erb+.
962
961
 
963
962
  <erb>
964
963
  <p class="notice"><%= notice %></p>
@@ -1194,7 +1193,7 @@ The +destroy+ action will find the post we are looking at, locate the comment wi
1194
1193
 
1195
1194
  h4. Deleting Associated Objects
1196
1195
 
1197
- If you delete a post then it's associated comments will also need to be deleted. Otherwise they would simply occupy space in the database. Rails allows you to use the +dependent+ option of an association to achieve this. Modify the Post model, +app/models/post.rb+, as follows:
1196
+ If you delete a post then its associated comments will also need to be deleted. Otherwise they would simply occupy space in the database. Rails allows you to use the +dependent+ option of an association to achieve this. Modify the Post model, +app/models/post.rb+, as follows:
1198
1197
 
1199
1198
  <ruby>
1200
1199
  class Post < ActiveRecord::Base
@@ -1486,6 +1485,7 @@ h3. Changelog
1486
1485
 
1487
1486
  "Lighthouse ticket":http://rails.lighthouseapp.com/projects/16213-rails-guides/tickets/2
1488
1487
 
1488
+ * July 12, 2010: Fixes, editing and updating of code samples by "Jaime Iniesta":http://jaimeiniesta.com
1489
1489
  * May 16, 2010: Added a section on configuration gotchas to address common encoding problems that people might have by "Yehuda Katz":http://www.yehudakatz.com
1490
1490
  * April 30, 2010: Fixes, editing and updating of code samples by "Rohit Arondekar":http://rohitarondekar.com
1491
1491
  * April 25, 2010: Couple of more minor fixups "Mikel Lindsaar":credits.html#raasdnil
@@ -287,7 +287,7 @@ You most probably have something like this in one of your applications:
287
287
 
288
288
  <ruby>
289
289
  # config/routes.rb
290
- Yourapp::Application.routes.draw do |map|
290
+ Yourapp::Application.routes.draw do
291
291
  root :to => "home#index"
292
292
  end
293
293
 
@@ -47,7 +47,7 @@ Ruby on Rails Guides
47
47
  <p>This guide covers how you can use Active Record migrations to alter your database in a structured and organized manner.</p>
48
48
  <% end %>
49
49
 
50
- <%= guide("Active Record Validations and Callbacks", 'activerecord_validations_callbacks.html') do %>
50
+ <%= guide("Active Record Validations and Callbacks", 'active_record_validations_callbacks.html') do %>
51
51
  <p>This guide covers how you can use Active Record validations and callbacks.</p>
52
52
  <% end %>
53
53
 
@@ -68,7 +68,7 @@ Ruby on Rails Guides
68
68
  <% end %>
69
69
 
70
70
  <%= guide("Action View Form Helpers", 'form_helpers.html', :ticket => 1) do %>
71
- <p>Guide to using built in Form helpers.</p>
71
+ <p>Guide to using built-in Form helpers.</p>
72
72
  <% end %>
73
73
  </dl>
74
74
 
@@ -123,10 +123,6 @@ Ruby on Rails Guides
123
123
  <%= guide("Caching with Rails", 'caching_with_rails.html', :ticket => 10) do %>
124
124
  <p>Various caching techniques provided by Rails.</p>
125
125
  <% end %>
126
-
127
- <%= guide("Contributing to Rails", 'contributing_to_rails.html') do %>
128
- <p>Rails is not &quot;somebody else's framework.&quot; This guide covers a variety of ways that you can get involved in the ongoing development of Rails.</p>
129
- <% end %>
130
126
  </dl>
131
127
 
132
128
  <h3>Extending Rails</h3>
@@ -147,6 +143,18 @@ Ruby on Rails Guides
147
143
  <% end %>
148
144
  </dl>
149
145
 
146
+ <h3>Contributing to Rails</h3>
147
+
148
+ <dl>
149
+ <%= guide("Contributing to Rails", 'contributing_to_rails.html') do %>
150
+ <p>Rails is not &quot;somebody else's framework.&quot; This guide covers a variety of ways that you can get involved in the ongoing development of Rails.</p>
151
+ <% end %>
152
+
153
+ <%= guide('API Documentation Guidelines', 'api_documentation_guidelines.html') do %>
154
+ <p>This guide documents the Ruby on Rails API documentation guidelines.</p>
155
+ <% end %>
156
+ </dl>
157
+
150
158
  <h3>Release Notes</h3>
151
159
 
152
160
  <dl>
@@ -11,7 +11,7 @@ This guide first describes the process of +rails server+ then explains the Passe
11
11
 
12
12
  h3. Launch!
13
13
 
14
- As of Rails 3, +script/server+ has become +rails server+. This was done to centralise all rails related commands to one common file.
14
+ As of Rails 3, +script/server+ has become +rails server+. This was done to centralize all rails related commands to one common file.
15
15
 
16
16
  The actual +rails+ command is kept in _railties/bin/rails_ and goes like this:
17
17
 
@@ -58,11 +58,8 @@ In +script/rails+ we see the following:
58
58
  #!/usr/bin/env ruby
59
59
  # This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
60
60
 
61
- ENV_PATH = File.expand_path('../../config/environment', __FILE__)
62
- BOOT_PATH = File.expand_path('../../config/boot', __FILE__)
63
- APP_PATH = File.expand_path('../../config/application', __FILE__)
64
-
65
- require BOOT_PATH
61
+ APP_PATH = File.expand_path('../../config/application', __FILE__)
62
+ require File.expand_path('../../config/boot', __FILE__)
66
63
  require 'rails/commands'
67
64
  </ruby>
68
65
 
@@ -79,15 +76,19 @@ h3. _config/boot.rb_
79
76
  _config/boot.rb_ is the first stop for everything for initializing your application. This boot process does quite a bit of work for you and so this section attempts to go in-depth enough to explain what each of the pieces does.
80
77
 
81
78
  <ruby>
82
- # Use Bundler (preferred)
79
+ require 'rubygems'
80
+
81
+ # Set up gems listed in the Gemfile.
82
+ gemfile = File.expand_path('../../Gemfile', __FILE__)
83
83
  begin
84
- require File.expand_path('../../.bundle/environment', __FILE__)
85
- rescue LoadError
86
- require 'rubygems'
84
+ ENV['BUNDLE_GEMFILE'] = gemfile
87
85
  require 'bundler'
88
86
  Bundler.setup
89
- end
90
-
87
+ rescue Bundler::GemNotFound => e
88
+ STDERR.puts e.message
89
+ STDERR.puts "Try running `bundle install`."
90
+ exit!
91
+ end if File.exist?(gemfile)
91
92
  </ruby>
92
93
 
93
94
  h3. Bundled Rails (3.x)
@@ -102,7 +103,7 @@ Now with Rails 3 we have a Gemfile which defines the basics our application need
102
103
  <ruby>
103
104
  source 'http://rubygems.org'
104
105
 
105
- gem 'rails', '3.0.0.beta1'
106
+ gem 'rails', '3.0.0.beta4'
106
107
 
107
108
  # Bundle edge Rails instead:
108
109
  # gem 'rails', :git => 'git://github.com/rails/rails.git'
@@ -132,65 +133,40 @@ Now with Rails 3 we have a Gemfile which defines the basics our application need
132
133
  Here the only two gems we need are +rails+ and +sqlite3-ruby+, so it seems. This is until you run +bundle pack+. This command freezes all the gems required by your application into _vendor/cache_. The gems installed by default are:
133
134
 
134
135
  * abstract-1.0.0.gem
135
- * actionmailer-3.0.0.beta1.gem
136
- * actionpack-3.0.0.beta1.gem
137
- * activemodel-3.0.0.beta1.gem
138
- * activerecord-3.0.0.beta1.gem
139
- * activeresource-3.0.0.beta1.gem
140
- * activesupport-3.0.0.beta1.gem
141
- * arel-0.3.3.gem
136
+ * actionmailer-3.0.0.beta4.gem
137
+ * actionpack-3.0.0.beta4.gem
138
+ * activemodel-3.0.0.beta4.gem
139
+ * activerecord-3.0.0.beta4.gem
140
+ * activeresource-3.0.0.beta4.gem
141
+ * activesupport-3.0.0.beta4.gem
142
+ * arel-0.4.0.gem
142
143
  * builder-2.1.2.gem
143
- * bundler-0.9.14.gem
144
- * erubis-2.6.5.gem
145
- * i18n-0.3.6.gem
146
- * mail-2.1.5.3.gem
147
- * memcache-client-1.8.1.gem
144
+ * bundler-1.0.0.beta.5.gem
145
+ * erubis-2.6.6.gem
146
+ * i18n-0.4.1.gem
147
+ * mail-2.2.5.gem
148
+ * memcache-client-1.8.5.gem
148
149
  * mime-types-1.16.gem
150
+ * nokogiri-1.4.2.gem
149
151
  * polyglot-0.3.1.gem
150
- * rack-1.1.0.gem
151
- * rack-mount-0.6.3.gem
152
- * rack-test-0.5.3.gem
153
- * rails-3.0.0.beta1.gem
154
- * railties-3.0.0.beta1.gem
152
+ * rack-1.2.1.gem
153
+ * rack-mount-0.6.9.gem
154
+ * rack-test-0.5.4.gem
155
+ * rails-3.0.0.beta4.gem
156
+ * railties-3.0.0.beta4.gem
155
157
  * rake-0.8.7.gem
156
- * sqlite3-ruby-1.2.5.gem
158
+ * sqlite3-ruby-1.3.1.gem
157
159
  * text-format-1.0.0.gem
158
160
  * text-hyphen-1.0.0.gem
159
- * thor-0.13.4.gem
160
- * treetop-1.4.5.gem
161
- * tzinfo-0.3.18.gem
161
+ * thor-0.13.7.gem
162
+ * treetop-1.4.8.gem
163
+ * tzinfo-0.3.22.gem
162
164
 
163
165
  TODO: Prettify when it becomes more stable.
164
166
 
165
167
  I won't go into what each of these gems are, as that is really something that needs covering on a case-by-case basis. We will however just dig a little under the surface of Bundler.
166
168
 
167
- Back in _config/boot.rb_, the first line will try to include _.bundle/environment.rb_, which doesn't exist in a bare-bones Rails application and because this file does not exist Ruby will raise a +LoadError+ which will be rescued and run the following code:
168
-
169
- <ruby>
170
- require 'rubygems'
171
- require 'bundler'
172
- Bundler.setup
173
- </ruby>
174
-
175
- +Bundler.setup+ here will load and parse the +Gemfile+ and add the _lib_ directory of the gems mentioned **and** their dependencies (**and** their dependencies' dependencies, and so on) to the +$LOAD_PATH+.
176
-
177
- Now we will go down the alternate timeline where we generate a _.bundle/environment.rb_ file using the +bundle lock+ command. This command also creates a _Gemfile.lock_ file which is actually a YAML file loaded by this method in Bundler before it moves on to check for _Gemfile_:
178
-
179
- <ruby>
180
- def definition(gemfile = default_gemfile)
181
- configure
182
- root = Pathname.new(gemfile).dirname
183
- lockfile = root.join("Gemfile.lock")
184
- if lockfile.exist?
185
- Definition.from_lock(lockfile)
186
- else
187
- Definition.from_gemfile(gemfile)
188
- end
189
- end
190
- </ruby>
191
-
192
-
193
- The _.bundle/environment.rb_ file adds the _lib_ directory of all the gems specified in +Gemfile.lock+ to +$LOAD_PATH+.
169
+ Back in _config/boot.rb_, we call +Bundler.setup+ which will load and parse the +Gemfile+ and add the _lib_ directory of the gems mentioned **and** their dependencies (**and** their dependencies' dependencies, and so on) to the +$LOAD_PATH+.
194
170
 
195
171
  h3. Requiring Rails
196
172
 
@@ -326,6 +302,11 @@ As you can see for the duration of the +eager_autoload+ block the class variable
326
302
  module ActiveSupport
327
303
  extend ActiveSupport::Autoload
328
304
 
305
+ autoload :DescendantsTracker
306
+ autoload :FileUpdateChecker
307
+ autoload :LogSubscriber
308
+ autoload :Notifications
309
+
329
310
  # TODO: Narrow this list down
330
311
  eager_autoload do
331
312
  autoload :BacktraceCleaner
@@ -348,7 +329,6 @@ As you can see for the duration of the +eager_autoload+ block the class variable
348
329
  autoload :OptionMerger
349
330
  autoload :OrderedHash
350
331
  autoload :OrderedOptions
351
- autoload :Notifications
352
332
  autoload :Rescuable
353
333
  autoload :SecureRandom
354
334
  autoload :StringInquirer
@@ -589,19 +569,20 @@ This file (_railties/lib/rails.rb_) requires the very, very basics that Rails ne
589
569
  require 'action_dispatch/railtie'
590
570
  </ruby>
591
571
 
592
- +require 'pathname'+ requires the Pathname class which is used for returning a Pathname object for +Rails.root+ so that instead of doing:
572
+ +require 'pathname'+ requires the Pathname class which is used for returning a Pathname object for +Rails.root+. Although is coming to use this path name to generate paths as below:
593
573
 
594
574
  <ruby>
595
- File.join(Rails.root, "app/controllers")
575
+ Rails.root.join("app/controllers")
596
576
  </ruby>
597
577
 
598
- You may do:
578
+ Pathname can also be converted to string, so the following syntax is preferred:
599
579
 
600
580
  <ruby>
601
- Rails.root.join("app/controllers")
581
+ "#{Rails.root}/app/controllers"
602
582
  </ruby>
603
583
 
604
- Although this is not new to Rails 3 (it was available in 2.3.5), it is something worthwhile pointing out.
584
+
585
+ This works because Ruby automatically handles file path conversions. Although this is not new to Rails 3 (it was available in 2.3.5), it is something worthwhile pointing out.
605
586
 
606
587
  Inside this file there are other helpful helper methods defined, such as +Rails.root+, +Rails.env+, +Rails.logger+ and +Rails.application+.
607
588
 
@@ -1833,7 +1814,7 @@ We do not already have a +Rails.application+, so instead this resorts to calling
1833
1814
  end
1834
1815
  </ruby>
1835
1816
 
1836
- This +called_from+ setting looks a little overwhelming to begin with, but the short end of it is that it returns the route to your application's config directory, something like: _/home/you/yourapp/config_. After +called_from+ has been set, +super+ is again called and this means the +Rails::Railtie#inherited+ method (in _railties/lib/rails/railtie.rb_):
1817
+ This +called_from+ setting looks a little overwhelming to begin with, but the short end of it is that it returns your application's root, something like: _/home/you/yourapp_. After +called_from+ has been set, +super+ is again called and this means the +Rails::Railtie#inherited+ method (in _railties/lib/rails/railtie.rb_):
1837
1818
 
1838
1819
  <ruby>
1839
1820
  def inherited(base)
@@ -3588,28 +3569,24 @@ h3. Appendix A
3588
3569
 
3589
3570
  This file is _activesupport/lib/active_support/inflector/inflections.rb_ and defines the +ActiveSupport::Inflector::Inflections+ class which defines the +singularize+, +pluralize+, +humanize+, +tableize+, +titleize+ and +classify+ methods as well as the code to defining how to work out the irregular, singular, plural and human versions of words. These methods are called +irregular+, +singular+, +plural+ and +human+ respectively, as is the Rails way.
3590
3571
 
3591
- This file is _activesupport/lib/active_support/inflector/transliterate.rb_ and defines two methods, +transliterate+ and +parameterize+. What +transliterate+ does depends on your Ruby version. If you have something greater than 1.9 installed it will just print out a warning message using the +Kernel#warn+ method (simply called using +warn+) reading "Ruby 1.9 doesn't support Unicode normalization yet". If you're running something that's not 1.9 it will attempt to convert +"föö"+ to +foo+ and if that fails then it'll redefine it.
3572
+ This file is _activesupport/lib/active_support/inflector/transliterate.rb_ and defines two methods, +transliterate+ and +parameterize+.
3592
3573
 
3593
- This file first makes a require to _activesupport/lib/active_support/core_ext/string/multibyte.rb_ which then goes on to require _activesupport/lib/active_support/multibyte.rb_ and that requires _activesupport/core_ext/module/attribute_accessors.rb_. The _attribute_accessors.rb_ file is used to gain access to the +mattr_accessor+ (module attribute accessor) method which is called in _active_suport/multibyte.rb_. Also in _active_support/multibyte.rb_ there's a couple of autoloaded classes:
3574
+ This file first requires _activesupport/lib/active_support/core_ext/string/multibyte.rb_, which requires _activesupport/lib/active_support/multibyte.rb_, which subsequently requires _activesupport/core_ext/module/attribute_accessors.rb_. The _attribute_accessors.rb_ file is needed to gain access to the +mattr_accessor+ (module attribute accessor) method, which is called in _active_suport/multibyte.rb_. The file _active_support/multibyte.rb_ also autoloads three other classes:
3594
3575
 
3595
3576
  <ruby>
3596
3577
  module ActiveSupport #:nodoc:
3597
3578
  module Multibyte
3598
3579
  autoload :EncodingError, 'active_support/multibyte/exceptions'
3599
3580
  autoload :Chars, 'active_support/multibyte/chars'
3600
- autoload :UnicodeDatabase, 'active_support/multibyte/unicode_database'
3601
- autoload :Codepoint, 'active_support/multibyte/unicode_database'
3602
- autoload :UCD, 'active_support/multibyte/unicode_database'
3603
- ...
3581
+ autoload :Unicode, 'active_support/multibyte/unicode'
3582
+ ...
3604
3583
  end
3605
3584
  end
3606
3585
  </ruby>
3607
3586
 
3608
- There's also these method definitions:
3587
+ There are also these method definitions:
3609
3588
 
3610
3589
  <ruby>
3611
- self.default_normalization_form = :kc
3612
-
3613
3590
  # The proxy class returned when calling mb_chars. You can use this accessor to configure your own proxy
3614
3591
  # class so you can support other encodings. See the ActiveSupport::Multibyte::Chars implementation for
3615
3592
  # an example how to do this.
@@ -3628,63 +3605,92 @@ There's also these method definitions:
3628
3605
 
3629
3606
  These methods are used in _activesupport/lib/active_support/core_ext/string/multibyte.rb_.
3630
3607
 
3631
- If we go back to _activesupport/lib/active_support/core_ext/string/multibyte.rb_, this file makes a couple of extensions to the +String+ class based on if your version of Ruby's +String+ class responds to the +force_encoding+ method. This method was introduced in Ruby 1.9. If you're using 1.9 the methods are defined like this:
3632
-
3633
- <ruby>
3634
- def mb_chars #:nodoc
3635
- self
3636
- end
3637
-
3638
- def is_utf8? #:nodoc
3639
- case encoding
3640
- when Encoding::UTF_8
3641
- valid_encoding?
3642
- when Encoding::ASCII_8BIT, Encoding::US_ASCII
3643
- dup.force_encoding(Encoding::UTF_8).valid_encoding?
3644
- else
3645
- false
3646
- end
3647
- end
3648
- </ruby>
3649
-
3650
- You can see that calling +mb_chars+ on a +String+ instance in Ruby 1.9 will simply return that +String+ object. +String+ objects in Ruby 1.9 are already multibyte strings, so Rails does not need to do any conversion on them.
3651
-
3652
- The second method, +is_utf8?+ return +true+ if the +String+ object is of the UTF8 encoding or if it's able to be forced into that encoding and +false+ if it can't force its encoding or if the encoding of the string is neither +UTF8+, +ASCII_8BIT+ or +US_ASCII+.
3653
-
3654
- If you're using a Ruby version less than 1.9 there are 3 methods defined instead of 2, and they are defined like this:
3608
+ The file _activesupport/lib/active_support/core_ext/string/chars.rb_ defines the default proxy class that will be returned by +mb_chars+.
3609
+
3610
+ Because Ruby 1.9's +String+ class has support for multibyte encodings, some methods are defined only for Ruby 1.8:
3611
+
3612
+ * +self.wants?+
3613
+ * +++
3614
+ * +=~+
3615
+ * +=~+
3616
+ * +center+
3617
+ * +include?+
3618
+ * +index+
3619
+ * +insert+
3620
+ * +ljust+
3621
+ * +lstrip+, +lstrip!+
3622
+ * +ord+
3623
+ * +rindex+
3624
+ * +rjust+
3625
+ * +rstrip+, +rstrip!+
3626
+ * +size+
3627
+ * +strip+, +strip!+
3628
+
3629
+ However, Ruby 1.9 lacks support for some needed operations, so the following methods are defined for both Ruby 1.8 and Ruby 1.9:
3630
+
3631
+ * +<=>+
3632
+ * +[]=+
3633
+ * +capitalize+, +capitalize!+
3634
+ * +compose+
3635
+ * +decompose+
3636
+ * +downcase+, +downcase!+
3637
+ * +g_length+
3638
+ * +limit+
3639
+ * +normalize+
3640
+ * +reverse+, +reverse+!
3641
+ * +slice+, +slice!+
3642
+ * +split+
3643
+ * +tidy_bytes+, +tidy_bytes!+
3644
+ * +titleize+
3645
+ * +upcase+, +upcase!+
3646
+
3647
+ <ruby>
3648
+ class String
3649
+ if RUBY_VERSION >= "1.9"
3650
+ def mb_chars
3651
+ if ActiveSupport::Multibyte.proxy_class.consumes?(self)
3652
+ ActiveSupport::Multibyte.proxy_class.new(self)
3653
+ else
3654
+ self
3655
+ end
3656
+ end
3655
3657
 
3656
- <ruby>
3657
- def mb_chars
3658
- if ActiveSupport::Multibyte.proxy_class.wants?(self)
3659
- ActiveSupport::Multibyte.proxy_class.new(self)
3658
+ def is_utf8? #:nodoc
3659
+ case encoding
3660
+ when Encoding::UTF_8
3661
+ valid_encoding?
3662
+ when Encoding::ASCII_8BIT, Encoding::US_ASCII
3663
+ dup.force_encoding(Encoding::UTF_8).valid_encoding?
3664
+ else
3665
+ false
3666
+ end
3667
+ end
3660
3668
  else
3661
- self
3662
- end
3663
- end
3664
-
3665
- # Returns true if the string has UTF-8 semantics (a String used for purely byte resources is unlikely to have
3666
- # them), returns false otherwise.
3667
- def is_utf8?
3668
- ActiveSupport::Multibyte::Chars.consumes?(self)
3669
- end
3669
+ def mb_chars
3670
+ if ActiveSupport::Multibyte.proxy_class.wants?(self)
3671
+ ActiveSupport::Multibyte.proxy_class.new(self)
3672
+ else
3673
+ self
3674
+ end
3675
+ end
3670
3676
 
3671
- unless '1.8.7 and later'.respond_to?(:chars)
3672
- def chars
3673
- ActiveSupport::Deprecation.warn('String#chars has been deprecated in favor of String#mb_chars.', caller)
3674
- mb_chars
3677
+ # Returns true if the string has UTF-8 semantics (a String used for purely byte resources is unlikely to have
3678
+ # them), returns false otherwise.
3679
+ def is_utf8?
3680
+ ActiveSupport::Multibyte::Chars.consumes?(self)
3681
+ end
3675
3682
  end
3676
- end
3677
-
3678
3683
  </ruby>
3679
3684
 
3685
+ As you can see, +mb_chars+ is where the +proxy_class+ property comes in handy. This method will create a new instance of the configured proxy class using the instance of +String+ as a constructor argument. By default, the new +String+-like object will be an instance of the proxy class +ActiveSupport::Multibyte::Chars+. You can use +ActiveSupport::Multibyte.proxy_class=+ to set a different proxy class if you wish.
3680
3686
 
3681
- As you can see, +mb_chars+ is where the +proxy_class+ method comes in handy. This will create a new instance of that class and pass in the +String+ object in order to make it multibyte-compatible. In this case the new +String+ object will be an instance of the +ActiveSupport::Multibyte::Chars+ class. You can use +ActiveSupport::Multibyte.proxy_class=+ to set this to be a different class if you're that way inclined.
3682
-
3683
- Here, +is_utf8?+ calls a +consumes+ method on the not-yet-loaded +ActiveSupport::Multibyte::Chars+ class. The keen-eye would have seen this was specified as an auto-load earlier, so that is what is going to happen if we call this method or +mb_chars+. This means that it'll require the file located at _activesupport/lib/active_support/multibyte/chars.rb_. This file includes _activesupport/lib/active_support/string/access.rb_ which defines methods such as +at+, +from+, +to+, +first+ and +last+. These methods will return parts of the string depending on what is passed to them and they are defined differently depending on if you're using Ruby 1.9 or not. The second file included is _activesupport/lib/active_support/string/behaviour.rb_ which defines a single method +acts_like_string?+ on +String+ which always returns +true+. This method is used through the +acts_like?+ method which is passed a single argument representing the downcased and symbolised version of the class you want to know if it acts like. In this case the code would be +acts_like?(:string)+.
3687
+ Here, +mb_chars+ invokes +is_utf8?+ to checks if the string can be treated as UTF-8. On 1.9, the string's +encoding+ property is checked. On 1.8, +wants?+ checks to see if +$KCODE+ is "UTF-8" and, and +consumes?+ checks whether the string can be unpacked as UTF-8 without raising an error.
3684
3688
 
3685
- The +Chars+ class defines, along with +consumes?+, other methods such as the "spaceship" method +<=>+. This method is referenced by the methods defined in the included +Comparable+ module and will return either +-1+, +0+ or +1+ depending on if the word is before, identical or after the compared word. For example, +'é'.mb_chars <=> 'ü'.mb_chars+ returns +-1+ as e comes before u in the alphabet. Other methods are the commonly used +split+, +=~+, +insert+ and +include?+.
3689
+ The keen eye will have seen +ActiveSupport::Multibyte::Chars+ was specified as an +autoload+ earlier: _activesupport/lib/active_support/multibyte/chars.rb_ will be loaded without an explicit +require+ when we call +is_utf8+ on 1.8, or +mb_chars+ on any Ruby version. This file includes _activesupport/lib/active_support/string/access.rb_ which defines methods such as +at+, +from+, +to+, +first+ and +last+. These methods will return parts of the string depending on what is passed to them.
3686
3690
 
3691
+ The second file included is _activesupport/lib/active_support/string/behavior.rb_ which only defines +acts_like_string?+ on +String+, a method which always returns +true+. This method is used by +Object#acts_like?+, which accepts a single argument representing the downcased and symbolised version of a class, and returns true if the object's behavior is like that class. In this case the code would be +acts_like?(:string)+.
3687
3692
 
3693
+ The +Chars+ class also defines other important methods such as the "spaceship" method +<=>+, which is needed by the +Comparable+ module, in order to allow UTF-8-aware sorting.
3688
3694
 
3689
3695
  h3. Common Includes
3690
3696