From 3e332948c70b8828d39817bd7c8850680de8f9c6 Mon Sep 17 00:00:00 2001 From: Mikel Lindsaar Date: Sun, 2 May 2010 20:38:09 +1000 Subject: [PATCH 01/20] Adding more docs to ActionMailer --- actionmailer/lib/action_mailer/base.rb | 62 +++++++++++++++++++++----- 1 file changed, 50 insertions(+), 12 deletions(-) diff --git a/actionmailer/lib/action_mailer/base.rb b/actionmailer/lib/action_mailer/base.rb index e566132f4e..0a794dc50b 100644 --- a/actionmailer/lib/action_mailer/base.rb +++ b/actionmailer/lib/action_mailer/base.rb @@ -196,21 +196,59 @@ module ActionMailer #:nodoc: # the delivery agents. Your object should make and needed modifications directly to the passed # in Mail::Message instance. # + # = Default Hash + # + # ActionMailer provides some intelligent defaults for your emails, these are usually specified in a + # default method inside the class definition: + # + # class Notifier < ActionMailer::Base + # default :sender => 'system@example.com' + # end + # + # You can pass in any header value that a Mail::Message, out of the box, ActionMailer::Base + # sets the following: + # + # * :mime_version => "1.0" + # * :charset => "UTF-8", + # * :content_type => "text/plain", + # * :parts_order => [ "text/plain", "text/enriched", "text/html" ] + # + # parts_order and charset are not actually valid Mail::Message header fields, + # but ActionMailer translates them appropriately and sets the correct values. + # + # As you can pass in any header, you need to either quote the header as a string, or pass it in as + # an underscorised symbol, so the following will work: + # + # class Notifier < ActionMailer::Base + # default 'Content-Transfer-Encoding' => '7bit', + # :content_description => 'This is a description' + # end + # + # Finally, ActionMailer also supports passing Proc objects into the default hash, so you + # can define methods that evaluate as the message is being generated: + # + # class Notifier < ActionMailer::Base + # default 'X-Special-Header' => Proc.new { my_method } + # + # private + # + # def my_method + # 'some complex call' + # end + # end + # + # Note that the proc is evaluated right at the start of the mail message generation, so if you + # set something in the defaults using a proc, and then set the same thing inside of your + # mailer method, it will get over written by the mailer method. + # # = Configuration options # - # These options are specified on the class level, like ActionMailer::Base.template_root = "/my/templates" - # - # * default - This is a class wide hash of :key => value pairs containing - # default values for the specified header fields of the Mail::Message. You can - # specify a default for any valid header for Mail::Message and it will be used if - # you do not override it. You pass in the header value as a symbol, all lower case with under - # scores instead of hyphens, so Content-Transfer-Encoding: - # becomes :content_transfer_encoding. The defaults set by Action Mailer are: - # * :mime_version => "1.0" - # * :charset => "UTF-8", - # * :content_type => "text/plain", - # * :parts_order => [ "text/plain", "text/enriched", "text/html" ] + # These options are specified on the class level, like + # ActionMailer::Base.template_root = "/my/templates" # + # * default - You can pass this in at a class level as well as within the class itself as + # per the above section. + # # * logger - the logger is used for generating information on the mailing run if available. # Can be set to nil for no logging. Compatible with both Ruby's own Logger and Log4r loggers. # From 07a5fdedd4b392ec172a3cf6294900afd75495b6 Mon Sep 17 00:00:00 2001 From: Mikel Lindsaar Date: Sun, 2 May 2010 21:48:46 +1000 Subject: [PATCH 02/20] Cleaning up Action Mailer spelling with and without the space --- actionmailer/lib/action_mailer.rb | 2 +- actionmailer/lib/action_mailer/base.rb | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/actionmailer/lib/action_mailer.rb b/actionmailer/lib/action_mailer.rb index 46168d9a4a..70cc312634 100644 --- a/actionmailer/lib/action_mailer.rb +++ b/actionmailer/lib/action_mailer.rb @@ -27,7 +27,7 @@ $:.unshift(actionpack_path) if File.directory?(actionpack_path) && !$:.include?( require 'abstract_controller' require 'action_view' -# Common ActiveSupport usage in ActionMailer +# Common Active Support usage in Action Mailer require 'active_support/core_ext/class' require 'active_support/core_ext/object/blank' require 'active_support/core_ext/array/uniq_by' diff --git a/actionmailer/lib/action_mailer/base.rb b/actionmailer/lib/action_mailer/base.rb index 0a794dc50b..efef5da6d7 100644 --- a/actionmailer/lib/action_mailer/base.rb +++ b/actionmailer/lib/action_mailer/base.rb @@ -13,7 +13,7 @@ module ActionMailer #:nodoc: # # $ rails generate mailer Notifier # - # The generated model inherits from ActionMailer::Base. Emails are defined by creating methods + # The generated model inherits from ActionMailer::Base. Emails are defined by creating methods # within the model which are then used to set variables to be used in the mail template, to # change options on the mail, or to add attachments. # @@ -185,7 +185,7 @@ module ActionMailer #:nodoc: # # = Observing and Intercepting Mails # - # ActionMailer provides hooks into the Mail observer and interceptor methods. These allow you to + # Action Mailer provides hooks into the Mail observer and interceptor methods. These allow you to # register objects that are called during the mail delivery life cycle. # # An observer object must implement the :delivered_email(message) method which will be @@ -198,7 +198,7 @@ module ActionMailer #:nodoc: # # = Default Hash # - # ActionMailer provides some intelligent defaults for your emails, these are usually specified in a + # Action Mailer provides some intelligent defaults for your emails, these are usually specified in a # default method inside the class definition: # # class Notifier < ActionMailer::Base @@ -214,7 +214,7 @@ module ActionMailer #:nodoc: # * :parts_order => [ "text/plain", "text/enriched", "text/html" ] # # parts_order and charset are not actually valid Mail::Message header fields, - # but ActionMailer translates them appropriately and sets the correct values. + # but Action Mailer translates them appropriately and sets the correct values. # # As you can pass in any header, you need to either quote the header as a string, or pass it in as # an underscorised symbol, so the following will work: @@ -224,7 +224,7 @@ module ActionMailer #:nodoc: # :content_description => 'This is a description' # end # - # Finally, ActionMailer also supports passing Proc objects into the default hash, so you + # Finally, Action Mailer also supports passing Proc objects into the default hash, so you # can define methods that evaluate as the message is being generated: # # class Notifier < ActionMailer::Base @@ -478,7 +478,7 @@ module ActionMailer #:nodoc: # Both methods accept a headers hash. This hash allows you to specify the most used headers # in an email message, these are: # - # * :subject - The subject of the message, if this is omitted, ActionMailer will + # * :subject - The subject of the message, if this is omitted, Action Mailer will # ask the Rails I18n class for a translated :subject in the scope of # [:actionmailer, mailer_scope, action_name] or if this is missing, will translate the # humanized version of the action_name From 2a09b8ecc7df94db28dbcaff43ce0c5cdd5acfdc Mon Sep 17 00:00:00 2001 From: Joe Hannon Date: Sun, 2 May 2010 15:55:58 -0700 Subject: [PATCH 03/20] grammatical error 'uses' -> 'use' --- railties/guides/source/active_record_querying.textile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/railties/guides/source/active_record_querying.textile b/railties/guides/source/active_record_querying.textile index e47615f070..1cfec1cf77 100644 --- a/railties/guides/source/active_record_querying.textile +++ b/railties/guides/source/active_record_querying.textile @@ -17,7 +17,7 @@ If you're used to using raw SQL to find database records then, generally, you wi Code examples throughout this guide will refer to one or more of the following models: -TIP: All of the following models uses +id+ as the primary key, unless specified otherwise. +TIP: All of the following models use +id+ as the primary key, unless specified otherwise.
From 6658c958972da2c56f2be9001fe22c8f2875ba3c Mon Sep 17 00:00:00 2001 From: logylaps Date: Tue, 4 May 2010 02:17:36 -0700 Subject: [PATCH 04/20] typo 'main.cs' -> 'main.css' --- railties/guides/source/layouts_and_rendering.textile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/railties/guides/source/layouts_and_rendering.textile b/railties/guides/source/layouts_and_rendering.textile index 92b36ab3e4..f6b6a1a7cc 100644 --- a/railties/guides/source/layouts_and_rendering.textile +++ b/railties/guides/source/layouts_and_rendering.textile @@ -747,7 +747,7 @@ You can even use dynamic paths such as +cache/#{current_site}/main/display+. h5. Linking to CSS Files with +stylesheet_link_tag+ -The +stylesheet_link_tag+ helper returns an HTML +<link>+ tag for each source provided. Rails looks in +public/stylesheets+ for these files by default, but you can specify a full path relative to the document root, or a URL, if you prefer. For example, to include +public/stylesheets/main.cs+: +The +stylesheet_link_tag+ helper returns an HTML +<link>+ tag for each source provided. Rails looks in +public/stylesheets+ for these files by default, but you can specify a full path relative to the document root, or a URL, if you prefer. For example, to include +public/stylesheets/main.css+: <%= stylesheet_link_tag "main" %> From 387e16afa905eff2943a94d08a471d402404eb78 Mon Sep 17 00:00:00 2001 From: logylaps Date: Tue, 4 May 2010 02:23:49 -0700 Subject: [PATCH 05/20] textile typo 'h6(:has_many-group)' -> 'h6(#has_many-group)' --- railties/guides/source/association_basics.textile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/railties/guides/source/association_basics.textile b/railties/guides/source/association_basics.textile index f13f6db6ee..335d17579d 100644 --- a/railties/guides/source/association_basics.textile +++ b/railties/guides/source/association_basics.textile @@ -1262,7 +1262,7 @@ end TIP: In any case, Rails will not create foreign key columns for you. You need to explicitly define them as part of your migrations. -h6(:has_many-group). +:group+ +h6(#has_many-group). +:group+ The +:group+ option supplies an attribute name to group the result set by, using a +GROUP BY+ clause in the finder SQL. From 8770b8c955c599282fd3257e2f1a4deaed9230e8 Mon Sep 17 00:00:00 2001 From: logylaps Date: Tue, 4 May 2010 02:25:55 -0700 Subject: [PATCH 06/20] typo. missing 'if' --- railties/guides/source/active_record_querying.textile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/railties/guides/source/active_record_querying.textile b/railties/guides/source/active_record_querying.textile index 1cfec1cf77..e18dbc9c42 100644 --- a/railties/guides/source/active_record_querying.textile +++ b/railties/guides/source/active_record_querying.textile @@ -802,7 +802,7 @@ will either assign an existing client object with the name "Ryan" to the client h3. Finding by SQL -If you'd like to use your own SQL to find records in a table you can use +find_by_sql+. The +find_by_sql+ method will return an array of objects even the underlying query returns just a single record. For example you could run this query: +If you'd like to use your own SQL to find records in a table you can use +find_by_sql+. The +find_by_sql+ method will return an array of objects even if the underlying query returns just a single record. For example you could run this query: Client.find_by_sql("SELECT * FROM clients From 1357b659bbcb0fbc7c559da536af76d164f147b5 Mon Sep 17 00:00:00 2001 From: mica eked Date: Tue, 4 May 2010 02:46:21 -0700 Subject: [PATCH 07/20] typo "" -> "" --- railties/guides/source/layouts_and_rendering.textile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/railties/guides/source/layouts_and_rendering.textile b/railties/guides/source/layouts_and_rendering.textile index f6b6a1a7cc..11d7ed0a3c 100644 --- a/railties/guides/source/layouts_and_rendering.textile +++ b/railties/guides/source/layouts_and_rendering.textile @@ -806,7 +806,7 @@ You can even use dynamic paths such as +cache/#{current_site}/main/display+. h5. Linking to Images with +image_tag+ -The +image_tag+ helper builds an HTML +<image />+ tag to the specified file. By default, files are loaded from +public/images+, note, you must specify the extension, previous versions of Rails would allow you to just call the image name and would append +.png+ if no extension was given, Rails 3.0 does not. +The +image_tag+ helper builds an HTML +<img />+ tag to the specified file. By default, files are loaded from +public/images+, note, you must specify the extension, previous versions of Rails would allow you to just call the image name and would append +.png+ if no extension was given, Rails 3.0 does not. <%= image_tag "header.png" %> From 3190fcb5216851d64f709ab6cf3fe468558f1020 Mon Sep 17 00:00:00 2001 From: mica eked Date: Tue, 4 May 2010 03:10:41 -0700 Subject: [PATCH 08/20] typo 'follow' -> 'following' --- railties/guides/source/layouts_and_rendering.textile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/railties/guides/source/layouts_and_rendering.textile b/railties/guides/source/layouts_and_rendering.textile index 11d7ed0a3c..7be369453e 100644 --- a/railties/guides/source/layouts_and_rendering.textile +++ b/railties/guides/source/layouts_and_rendering.textile @@ -1154,7 +1154,7 @@ h4. Using Nested Layouts You may find that your application requires a layout that differs slightly from your regular application layout to support one particular controller. Rather than repeating the main layout and editing it, you can accomplish this by using nested layouts (sometimes called sub-templates). Here's an example: -Suppose you have the follow +ApplicationController+ layout: +Suppose you have the following +ApplicationController+ layout: * +app/views/layouts/application.html.erb+ From 015114cbbbd29935a901640070957ddca5e00bde Mon Sep 17 00:00:00 2001 From: Josiah Ivey Date: Tue, 4 May 2010 09:52:31 -0500 Subject: [PATCH 09/20] image_tag should be audio_tag --- railties/guides/source/layouts_and_rendering.textile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/railties/guides/source/layouts_and_rendering.textile b/railties/guides/source/layouts_and_rendering.textile index 7be369453e..e1adbe5bdc 100644 --- a/railties/guides/source/layouts_and_rendering.textile +++ b/railties/guides/source/layouts_and_rendering.textile @@ -898,7 +898,7 @@ The +audio_tag+ helper builds an HTML 5 +<audio>+ tag to the specified fil You can supply a path to the image if you like: -<%= image_tag "music/first_song.mp3" %> +<%= audio_tag "music/first_song.mp3" %> You can also supply a hash of additional options, such as +:id+, +:class+ etc. From 44a98967676492995d19fd4d541dbc9d52bf6b53 Mon Sep 17 00:00:00 2001 From: Josiah Ivey Date: Tue, 4 May 2010 09:55:44 -0500 Subject: [PATCH 10/20] Change typo 'image' to 'audio file' --- railties/guides/source/layouts_and_rendering.textile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/railties/guides/source/layouts_and_rendering.textile b/railties/guides/source/layouts_and_rendering.textile index e1adbe5bdc..a874fa0ca7 100644 --- a/railties/guides/source/layouts_and_rendering.textile +++ b/railties/guides/source/layouts_and_rendering.textile @@ -895,7 +895,7 @@ The +audio_tag+ helper builds an HTML 5 +<audio>+ tag to the specified fil <%= audio_tag "music.mp3" %> -You can supply a path to the image if you like: +You can supply a path to the audio file if you like: <%= audio_tag "music/first_song.mp3" %> From b38639ab7146a84bba92036ab05d325e4c3111be Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Wed, 5 May 2010 00:55:44 -0300 Subject: [PATCH 11/20] typo 'Provivdes' -> 'Provides' --- activemodel/lib/active_model/attribute_methods.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/activemodel/lib/active_model/attribute_methods.rb b/activemodel/lib/active_model/attribute_methods.rb index b7c368ad8d..9bacc2a511 100644 --- a/activemodel/lib/active_model/attribute_methods.rb +++ b/activemodel/lib/active_model/attribute_methods.rb @@ -80,7 +80,7 @@ module ActiveModel # # end # - # Provivdes you with: + # Provides you with: # # AttributePerson.primary_key # # => "sysid" From 6071b4720ce2a8ae0193da44536ab1b9f1b76eb0 Mon Sep 17 00:00:00 2001 From: Anil Wadghule Date: Thu, 6 May 2010 01:26:25 +0530 Subject: [PATCH 12/20] Updated guide to inform issues with unsupported Ruby versions. --- railties/guides/source/getting_started.textile | 3 +++ 1 file changed, 3 insertions(+) diff --git a/railties/guides/source/getting_started.textile b/railties/guides/source/getting_started.textile index 7e3f2cc931..5da7ff7daa 100644 --- a/railties/guides/source/getting_started.textile +++ b/railties/guides/source/getting_started.textile @@ -16,6 +16,9 @@ h3. Guide Assumptions This guide is designed for beginners who want to get started with a Rails application from scratch. It does not assume that you have any prior experience with Rails. However, to get the most out of it, you need to have some prerequisites installed: * The "Ruby":http://www.ruby-lang.org/en/downloads language version 1.8.7 or higher + +TIP: Note that Ruby 1.8.7 p248 and p249 has marshaling bugs that crash Rails 3.0.0. Ruby 1.9.1 outright segfaults on Rails 3.0.0, so if you want to use Rails 3 with 1.9.x, jump on 1.9.2 trunk for smooth sailing. + * The "RubyGems":http://rubyforge.org/frs/?group_id=126 packaging system * A working installation of the "SQLite3 Database":http://www.sqlite.org From d3e405cdbc5fabe1325d5cbc9f52c8288f2d6024 Mon Sep 17 00:00:00 2001 From: Rohit Arondekar Date: Thu, 6 May 2010 20:33:24 -0700 Subject: [PATCH 13/20] Migrations, rewrote a sentence for clarity. --- railties/guides/source/migrations.textile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/railties/guides/source/migrations.textile b/railties/guides/source/migrations.textile index 6f88ed6b3f..a7316eab91 100644 --- a/railties/guides/source/migrations.textile +++ b/railties/guides/source/migrations.textile @@ -82,7 +82,7 @@ On databases that support transactions with statements that change the schema (s h4. What's in a Name -Migrations are stored in files in +db/migrate+, one for each migration class. The name of the file is of the form +YYYYMMDDHHMMSS_create_products.rb+, that is to say a UTC timestamp identifying the migration followed by an underscore followed by the name of the migration. The migration class' name must match (the camelcased version of) the latter part of the file name. For example +20080906120000_create_products.rb+ should define +CreateProducts+ and +20080906120001_add_details_to_products.rb+ should define +AddDetailsToProducts+. If you do feel the need to change the file name then you have to update the name of the class inside or Rails will complain about a missing class. +Migrations are stored in files in +db/migrate+, one for each migration class. The name of the file is of the form +YYYYMMDDHHMMSS_create_products.rb+, that is to say a UTC timestamp identifying the migration followed by an underscore followed by the name of the migration. The name of the migration class (CamelCased version) should match the latter part of the file name. For example +20080906120000_create_products.rb+ should define +CreateProducts+ and +20080906120001_add_details_to_products.rb+ should define +AddDetailsToProducts+. If you do feel the need to change the file name then you have to update the name of the class inside or Rails will complain about a missing class. Internally Rails only uses the migration's number (the timestamp) to identify them. Prior to Rails 2.1 the migration number started at 1 and was incremented each time a migration was generated. With multiple developers it was easy for these to clash requiring you to rollback migrations and renumber them. With Rails 2.1 this is largely avoided by using the creation time of the migration to identify them. You can revert to the old numbering scheme by setting +config.active_record.timestamped_migrations+ to +false+ in +config/environment.rb+. From 2cc1686bda5ff8f3e8976883ac2e8583713959a0 Mon Sep 17 00:00:00 2001 From: Rohit Arondekar Date: Fri, 7 May 2010 00:03:16 -0700 Subject: [PATCH 14/20] migration, correct file and created a code sample out of it. --- railties/guides/source/migrations.textile | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/railties/guides/source/migrations.textile b/railties/guides/source/migrations.textile index a7316eab91..f05c0589b5 100644 --- a/railties/guides/source/migrations.textile +++ b/railties/guides/source/migrations.textile @@ -84,7 +84,11 @@ h4. What's in a Name Migrations are stored in files in +db/migrate+, one for each migration class. The name of the file is of the form +YYYYMMDDHHMMSS_create_products.rb+, that is to say a UTC timestamp identifying the migration followed by an underscore followed by the name of the migration. The name of the migration class (CamelCased version) should match the latter part of the file name. For example +20080906120000_create_products.rb+ should define +CreateProducts+ and +20080906120001_add_details_to_products.rb+ should define +AddDetailsToProducts+. If you do feel the need to change the file name then you have to update the name of the class inside or Rails will complain about a missing class. -Internally Rails only uses the migration's number (the timestamp) to identify them. Prior to Rails 2.1 the migration number started at 1 and was incremented each time a migration was generated. With multiple developers it was easy for these to clash requiring you to rollback migrations and renumber them. With Rails 2.1 this is largely avoided by using the creation time of the migration to identify them. You can revert to the old numbering scheme by setting +config.active_record.timestamped_migrations+ to +false+ in +config/environment.rb+. +Internally Rails only uses the migration's number (the timestamp) to identify them. Prior to Rails 2.1 the migration number started at 1 and was incremented each time a migration was generated. With multiple developers it was easy for these to clash requiring you to rollback migrations and renumber them. With Rails 2.1 this is largely avoided by using the creation time of the migration to identify them. You can revert to the old numbering scheme by adding the following line to +config/application.rb+. + + +config.active_record.timestamped_migrations = false + The combination of timestamps and recording which migrations have been run allows Rails to handle common situations that occur with multiple developers. From 7a5aa35ed09dbdf306adbe5786cca7019a10bf98 Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Sun, 9 May 2010 02:28:13 +0300 Subject: [PATCH 15/20] AS guide: documents some Date calculations (calendar reform details pending) --- .../active_support_core_extensions.textile | 51 ++++++++++++++++++- 1 file changed, 49 insertions(+), 2 deletions(-) diff --git a/railties/guides/source/active_support_core_extensions.textile b/railties/guides/source/active_support_core_extensions.textile index 32738fe070..a3cb864796 100644 --- a/railties/guides/source/active_support_core_extensions.textile +++ b/railties/guides/source/active_support_core_extensions.textile @@ -2648,11 +2648,58 @@ NOTE: Defined in +active_support/core_ext/proc.rb+. h3. Extensions to +Date+ -... +h4. Calculations + +All the following methods are defined in +active_support/core_ext/date/calculations.rb+. + +h5. +Date.current+ + +Active Support defines +Date.current+ to be today in the current time zone. That's like +Date.today+, except that it honors +Time.zone_default+. It also defines +Date.yesterday+ and +Date.tomorrow+, and the instance predicates +past?+, +today?+, and +future?+, all of them relative to +Date.current+. + +h5. Named dates + +h6. +last_year+, +next_year+ + +The methods +last_year+ and +next_year+ return a date with the same day/month in the last or next year: + + +d = Date.new(2010, 5, 8) # => Sat, 08 May 2010 +d.last_year # => Fri, 08 May 2009 +d.next_year # => Sun, 08 May 2011 + + +If date is the 29th of February of a leap year, you obtain the 28th: + + +d = Date.new(2000, 2, 29) # => Tue, 29 Feb 2000 +d.last_year # => Sun, 28 Feb 1999 +d.next_year # => Wed, 28 Feb 2001 + + +h6. +last_month+, +next_month+ + +The methods +last_month+ and +next_month+ return the a date with the same day in the last or next month: + + +d = Date.new(2010, 5, 8) # => Sat, 08 May 2010 +d.last_month # => Thu, 08 Apr 2010 +d.next_month # => Tue, 08 Jun 2010 + + +If such a day does not exist, the last day of the corresponding month is returned: + + +Date.new(2000, 5, 31).last_month # => Sun, 30 Apr 2000 +Date.new(2000, 3, 31).last_month # => Tue, 29 Feb 2000 +Date.new(2000, 5, 31).next_month # => Fri, 30 Jun 2000 +Date.new(2000, 1, 31).next_month # => Tue, 29 Feb 2000 + + +h4. Conversions h3. Extensions to +DateTime+ -... +NOTE TO SELF: Since +DateTime+ is a subclass of +Date+, you get inherited methods that return +DateTime+ objects. h3. Extensions to +Time+ From c31b386a8834130471a297faa720bfe4ff2e884e Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Sat, 8 May 2010 21:41:41 -0300 Subject: [PATCH 16/20] Updates bundler information, now bundler has a homepage --- railties/guides/source/3_0_release_notes.textile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/railties/guides/source/3_0_release_notes.textile b/railties/guides/source/3_0_release_notes.textile index 622032e1ea..4b66baae1c 100644 --- a/railties/guides/source/3_0_release_notes.textile +++ b/railties/guides/source/3_0_release_notes.textile @@ -87,7 +87,7 @@ h4. Vendoring Gems Rails now uses a +Gemfile+ in the application root to determine the gems you require for your application to start. This +Gemfile+ is processed by the "Bundler":http://github.com/carlhuda/bundler, which then installs all your dependencies. It can even install all the dependencies locally to your application so that it doesn't depend on the system gems. -More information: - "bundler README on Github":http://github.com/carlhuda/bundler +More information: - "bundler homepage":http://gembundler.com h4. Living on the Edge From 345c38a5277400e96a0b6992192037f0eaa81718 Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Sun, 9 May 2010 11:39:57 +0300 Subject: [PATCH 17/20] AS guide: adds a catchall note about date calculations around the calendar reform --- railties/guides/source/active_support_core_extensions.textile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/railties/guides/source/active_support_core_extensions.textile b/railties/guides/source/active_support_core_extensions.textile index a3cb864796..091a639270 100644 --- a/railties/guides/source/active_support_core_extensions.textile +++ b/railties/guides/source/active_support_core_extensions.textile @@ -2652,6 +2652,8 @@ h4. Calculations All the following methods are defined in +active_support/core_ext/date/calculations.rb+. +WARNING: The following calculation methods have edge cases in November 1582, since days 5..14 just do not exist. This guide does not document their behavior around those days for brevity, but it is enough to say that they do what you would expect. That is, +Date.new(1582, 10, 4).tomorrow+ returns +Date.new(1582, 10, 15)+ and so on. Please check +test/core_ext/date_ext_test.rb+ in the Active Support test suite for expected behavior. + h5. +Date.current+ Active Support defines +Date.current+ to be today in the current time zone. That's like +Date.today+, except that it honors +Time.zone_default+. It also defines +Date.yesterday+ and +Date.tomorrow+, and the instance predicates +past?+, +today?+, and +future?+, all of them relative to +Date.current+. From 08d991ad409295a2d91b10bca4c7080fdbe7b5b9 Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Sun, 9 May 2010 11:44:22 +0300 Subject: [PATCH 18/20] AS guide: you know, the 10th is not November --- railties/guides/source/active_support_core_extensions.textile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/railties/guides/source/active_support_core_extensions.textile b/railties/guides/source/active_support_core_extensions.textile index 091a639270..d321e3db72 100644 --- a/railties/guides/source/active_support_core_extensions.textile +++ b/railties/guides/source/active_support_core_extensions.textile @@ -2652,7 +2652,7 @@ h4. Calculations All the following methods are defined in +active_support/core_ext/date/calculations.rb+. -WARNING: The following calculation methods have edge cases in November 1582, since days 5..14 just do not exist. This guide does not document their behavior around those days for brevity, but it is enough to say that they do what you would expect. That is, +Date.new(1582, 10, 4).tomorrow+ returns +Date.new(1582, 10, 15)+ and so on. Please check +test/core_ext/date_ext_test.rb+ in the Active Support test suite for expected behavior. +INFO: The following calculation methods have edge cases in October 1582, since days 5..14 just do not exist. This guide does not document their behavior around those days for brevity, but it is enough to say that they do what you would expect. That is, +Date.new(1582, 10, 4).tomorrow+ returns +Date.new(1582, 10, 15)+ and so on. Please check +test/core_ext/date_ext_test.rb+ in the Active Support test suite for expected behavior. h5. +Date.current+ From df508bd97062b871fe25eda8d1bb61cd43d79bc4 Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Sun, 9 May 2010 11:16:34 +0200 Subject: [PATCH 19/20] aliases Date#sunday to Date#end_of_week, for symmetry with existing alias Date#monday -> Date#beginning_of_week --- activesupport/CHANGELOG | 2 ++ activesupport/lib/active_support/core_ext/date/calculations.rb | 1 + 2 files changed, 3 insertions(+) diff --git a/activesupport/CHANGELOG b/activesupport/CHANGELOG index 1e01cfc45f..6146cc6a97 100644 --- a/activesupport/CHANGELOG +++ b/activesupport/CHANGELOG @@ -1,5 +1,7 @@ *Rails 3.0.0 [beta 4/release candidate] (unreleased)* +* Aliases Date#sunday to Date#end_of_week. [fxn] + * Backports Date#>> from 1.9 so that calculations do the right thing around the calendar reform. [fxn] * Date#to_time handles properly years in the range 0..138. [fxn] diff --git a/activesupport/lib/active_support/core_ext/date/calculations.rb b/activesupport/lib/active_support/core_ext/date/calculations.rb index 2612dca93a..3038729d34 100644 --- a/activesupport/lib/active_support/core_ext/date/calculations.rb +++ b/activesupport/lib/active_support/core_ext/date/calculations.rb @@ -181,6 +181,7 @@ class Date result = self + days_to_sunday.days self.acts_like?(:time) ? result.end_of_day : result end + alias :sunday :end_of_week alias :at_end_of_week :end_of_week # Returns a new Date/DateTime representing the start of the given day in next week (default is Monday). From 1ff3d951e620ddeeb97e87e2024391470e886467 Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Sun, 9 May 2010 12:45:21 +0300 Subject: [PATCH 20/20] AS guide: more date calculation utilities --- .../active_support_core_extensions.textile | 60 ++++++++++++++++++- 1 file changed, 59 insertions(+), 1 deletion(-) diff --git a/railties/guides/source/active_support_core_extensions.textile b/railties/guides/source/active_support_core_extensions.textile index d321e3db72..b7b5f47eef 100644 --- a/railties/guides/source/active_support_core_extensions.textile +++ b/railties/guides/source/active_support_core_extensions.textile @@ -2680,7 +2680,7 @@ d.next_year # => Wed, 28 Feb 2001 h6. +last_month+, +next_month+ -The methods +last_month+ and +next_month+ return the a date with the same day in the last or next month: +The methods +last_month+ and +next_month+ return the date with the same day in the last or next month: d = Date.new(2010, 5, 8) # => Sat, 08 May 2010 @@ -2697,6 +2697,64 @@ Date.new(2000, 5, 31).next_month # => Fri, 30 Jun 2000 Date.new(2000, 1, 31).next_month # => Tue, 29 Feb 2000 +h6. +beginning_of_week+, +end_of_week+ + +The methods +beginning_of_week+ and +end_of_week+ return the dates for the beginning and end of week, assuming weeks start on Monday: + + +d = Date.new(2010, 5, 8) # => Sat, 08 May 2010 +d.beginning_of_week # => Mon, 03 May 2010 +d.end_of_week # => Sun, 09 May 2010 + + ++beginning_of_week+ is aliased to +monday+ and +at_beginning_of_week+. +end_of_week+ is aliased to +sunday+ and +at_end_of_week+. + +h6. +next_week+ + ++next_week+ receives a symbol with a day name in English (in lowercase, default is +:monday+) and it returns the date corresponding to that day in the next week: + + +d = Date.new(2010, 5, 9) # => Sun, 09 May 2010 +d.next_week # => Mon, 10 May 2010 +d.next_week(:saturday) # => Sat, 15 May 2010 + + +h6. +beginning_of_month+, +end_of_month+ + +The methods +beginning_of_month+ and +end_of_month+ return the dates for the beginning and end of the month: + + +d = Date.new(2010, 5, 9) # => Sun, 09 May 2010 +d.beginning_of_month # => Sat, 01 May 2010 +d.end_of_month # => Mon, 31 May 2010 + + ++beginning_of_month+ is aliased to +at_beginning_of_month+, and +end_of_month+ is aliased to +at_end_of_month+. + +h6. +beginning_of_quarter+, +end_of_quarter+ + +The methods +beginning_of_quarter+ and +end_of_quarter+ return the dates for the beginning and end of the quarter of the receiver's calendar year: + + +d = Date.new(2010, 5, 9) # => Sun, 09 May 2010 +d.beginning_of_quarter # => Thu, 01 Apr 2010 +d.end_of_quarter # => Wed, 30 Jun 2010 + + ++beginning_of_quarter+ is aliased to +at_beginning_of_quarter+, and +end_of_quarter+ is aliased to +at_end_of_quarter+. + +h6. +beginning_of_year+, +end_of_year+ + +The methods +beginning_of_year+ and +end_of_year+ return the dates for the beginning and end of the year: + + +d = Date.new(2010, 5, 9) # => Sun, 09 May 2010 +d.beginning_of_year # => Fri, 01 Jan 2010 +d.end_of_year # => Fri, 31 Dec 2010 + + ++beginning_of_year+ is aliased to +at_beginning_of_year+, and +end_of_year+ is aliased to +at_end_of_year+. + h4. Conversions h3. Extensions to +DateTime+