Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Changeset 9093

Show
Ignore:
Timestamp:
03/26/08 12:27:52 (1 year ago)
Author:
pratik
Message:

Improve documentation.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/actionpack/CHANGELOG

    r9088 r9093  
    11*SVN* 
     2 
     3* Improve documentation. [Radar, Jan De Poorter, chuyeow, xaviershay, danger, miloops, Xavier Noria,  Sunny Ripert] 
    24 
    35* Fixed that FormHelper#radio_button would produce invalid ids #11298 [harlancrystal] 
  • trunk/actionpack/lib/action_controller/resources.rb

    r8982 r9093  
    227227    # 
    228228    #   <% form_for :message, @message, :url => message_path(@message), :html => {:method => :put} do |f| %> 
     229    # 
     230    # or 
     231    # 
     232    #   <% form_for @message do |f| %> 
     233    # 
     234    # which takes into account whether <tt>@message</tt> is a new record or not and generates the 
     235    # path and method accordingly. 
    229236    # 
    230237    # The #resources method accepts the following options to customize the resulting routes: 
  • trunk/actionpack/lib/action_view/helpers/atom_feed_helper.rb

    r9044 r9093  
    5050      # * <tt>:schema_date</tt>: The date at which the tag scheme for the feed was first used. A good default is the year you  
    5151      #   created the feed. See http://feedvalidator.org/docs/error/InvalidTAG.html for more information. If not specified,  
    52       #   2005 is used (as a "I don't care"-value). 
     52      #   2005 is used (as an "I don't care" value). 
    5353      # 
    5454      # Other namespaces can be added to the root element: 
  • trunk/actionpack/lib/action_view/helpers/form_helper.rb

    r9088 r9093  
    7777      # 
    7878      #   <% form_for :person, @person, :url => { :action => "update" } do |f| %> 
     79      #     <%= f.error_messages %> 
    7980      #     First name: <%= f.text_field :first_name %> 
    8081      #     Last name : <%= f.text_field :last_name %> 
     
    8687      # not <tt><%= %></tt>. Also worth noting is that form_for yields a <tt>form_builder</tt> object, in this example as <tt>f</tt>, which emulates 
    8788      # the API for the stand-alone FormHelper methods, but without the object name. So instead of <tt>text_field :person, :name</tt>, 
    88       # you get away with <tt>f.text_field :name</tt>. 
     89      # you get away with <tt>f.text_field :name</tt>. Notice that you can even do <tt><%= f.error_messages %></tt> to display the 
     90      # error messsages of the model object in question. 
    8991      # 
    9092      # Even further, the form_for method allows you to more easily escape the instance variable convention. So while the stand-alone 
     
    406408      #   # Let's say that @post.validated? is 1: 
    407409      #   check_box("post", "validated") 
    408       #   # => <input type="checkbox" id="post_validate" name="post[validated]" value="1" checked="checked" /> 
     410      #   # => <input type="checkbox" id="post_validated" name="post[validated]" value="1" /> 
    409411      #   #    <input name="post[validated]" type="hidden" value="0" /> 
    410412      # 
     
    414416      #   #    <input name="puppy[gooddog]" type="hidden" value="no" /> 
    415417      # 
    416       #   check_box("eula", "accepted", {}, "yes", "no", :class => 'eula_check'
    417       #   # => <input type="checkbox" id="eula_accepted" name="eula[accepted]" value="no" /> 
     418      #   check_box("eula", "accepted", { :class => 'eula_check' }, "yes", "no"
     419      #   # => <input type="checkbox" class="eula_check" id="eula_accepted" name="eula[accepted]" value="yes" /> 
    418420      #   #    <input name="eula[accepted]" type="hidden" value="no" /> 
    419421      # 
     
    431433      #   radio_button("post", "category", "rails") 
    432434      #   radio_button("post", "category", "java") 
    433       #   # => <input type="radio" id="post_category" name="post[category]" value="rails" checked="checked" /> 
    434       #   #    <input type="radio" id="post_category" name="post[category]" value="java" /> 
     435      #   # => <input type="radio" id="post_category_rails" name="post[category]" value="rails" checked="checked" /> 
     436      #   #    <input type="radio" id="post_category_java" name="post[category]" value="java" /> 
    435437      # 
    436438      #   radio_button("user", "receive_newsletter", "yes") 
    437439      #   radio_button("user", "receive_newsletter", "no") 
    438       #   # => <input type="radio" id="user_receive_newsletter" name="user[receive_newsletter]" value="yes" /> 
    439       #   #    <input type="radio" id="user_receive_newsletter" name="user[receive_newsletter]" value="no" checked="checked" /> 
     440      #   # => <input type="radio" id="user_receive_newsletter_yes" name="user[receive_newsletter]" value="yes" /> 
     441      #   #    <input type="radio" id="user_receive_newsletter_no" name="user[receive_newsletter]" value="no" checked="checked" /> 
    440442      def radio_button(object_name, method, tag_value, options = {}) 
    441443        InstanceTag.new(object_name, method, self, nil, options.delete(:object)).to_radio_button_tag(tag_value, options) 
  • trunk/activerecord/CHANGELOG

    r9090 r9093  
    11*SVN* 
     2 
     3* Improve documentation. [Radar, Jan De Poorter, chuyeow, xaviershay, danger, miloops, Xavier Noria,  Sunny Ripert] 
    24 
    35* Fixed that ActiveRecord#Base.find_or_create/initialize would not honor attr_protected/accessible when used with a hash #11422 [miloops] 
  • trunk/activerecord/lib/active_record/fixtures.rb

    r9051 r9093  
    177177# mix ERb in with your YAML or CSV fixtures to create a bunch of fixtures for load testing, like: 
    178178# 
    179 # <% for i in 1..1000 %> 
    180 # fix_<%= i %>: 
    181 #   id: <%= i %> 
    182 #   name: guy_<%= 1 %> 
    183 # <% end %> 
     179#   <% for i in 1..1000 %> 
     180#   fix_<%= i %>: 
     181#     id: <%= i %> 
     182#     name: guy_<%= 1 %> 
     183#   <% end %> 
    184184# 
    185185# This will create 1000 very simple YAML fixtures. 
  • trunk/activerecord/lib/active_record/migration.rb

    r8481 r9093  
    9292  # The Rails package has several tools to help create and apply migrations. 
    9393  # 
    94   # To generate a new migration, use <tt>script/generate migration MyNewMigration</tt> 
     94  # To generate a new migration, you can use  
     95  #   script/generate migration MyNewMigration 
     96  # 
    9597  # where MyNewMigration is the name of your migration. The generator will 
    96   # create a file <tt>nnn_my_new_migration.rb</tt> in the <tt>db/migrate/</tt> 
     98  # create an empty migration file <tt>nnn_my_new_migration.rb</tt> in the <tt>db/migrate/</tt> 
    9799  # directory where <tt>nnn</tt> is the next largest migration number. 
     100  # 
    98101  # You may then edit the <tt>self.up</tt> and <tt>self.down</tt> methods of 
    99102  # MyNewMigration. 
    100103  # 
     104  # There is a special syntactic shortcut to generate migrations that add fields to a table. 
     105  #   script/generate migration add_fieldname_to_tablename fieldname:string 
     106  # 
     107  # This will generate the file <tt>nnn_add_fieldname_to_tablename</tt>, which will look like this: 
     108  #   class AddFieldnameToTablename < ActiveRecord::Migration 
     109  #     def self.up 
     110  #       add_column :tablenames, :fieldname, :string 
     111  #     end 
     112  #  
     113  #     def self.down 
     114  #       remove_column :tablenames, :fieldname 
     115  #     end 
     116  #   end 
     117  #  
    101118  # To run migrations against the currently configured database, use 
    102119  # <tt>rake db:migrate</tt>. This will update the database by running all of the 
  • trunk/activerecord/lib/active_record/serializers/json_serializer.rb

    r7905 r9093  
    99    #   konata = User.find(1) 
    1010    #   konata.to_json 
    11     # 
    12     #   {"id": 1, "name": "Konata Izumi", "age": 16, 
    13     #    "created_at": "2006/08/01", "awesome": true} 
     11    #   # => {"id": 1, "name": "Konata Izumi", "age": 16, 
     12    #         "created_at": "2006/08/01", "awesome": true} 
    1413    # 
    1514    # The :only and :except options can be used to limit the attributes 
     
    1716    # 
    1817    #   konata.to_json(:only => [ :id, :name ]) 
    19     # 
    20     #   {"id": 1, "name": "Konata Izumi"} 
     18    #   # => {"id": 1, "name": "Konata Izumi"} 
    2119    # 
    2220    #   konata.to_json(:except => [ :id, :created_at, :age ]) 
    23     # 
    24     #   {"name": "Konata Izumi", "awesome": true} 
     21    #   # => {"name": "Konata Izumi", "awesome": true} 
    2522    # 
    2623    # To include any methods on the model, use :methods. 
    2724    # 
    2825    #   konata.to_json(:methods => :permalink) 
    29     # 
    30     #   {"id": 1, "name": "Konata Izumi", "age": 16, 
    31     #    "created_at": "2006/08/01", "awesome": true, 
    32     #    "permalink": "1-konata-izumi"} 
     26    #   # => {"id": 1, "name": "Konata Izumi", "age": 16, 
     27    #         "created_at": "2006/08/01", "awesome": true, 
     28    #         "permalink": "1-konata-izumi"} 
    3329    # 
    3430    # To include associations, use :include. 
    3531    # 
    3632    #   konata.to_json(:include => :posts) 
    37     # 
    38     #   {"id": 1, "name": "Konata Izumi", "age": 16, 
    39     #    "created_at": "2006/08/01", "awesome": true, 
    40     #    "posts": [{"id": 1, "author_id": 1, "title": "Welcome to the weblog"}, 
    41     #              {"id": 2, author_id: 1, "title": "So I was thinking"}]} 
     33    #   # => {"id": 1, "name": "Konata Izumi", "age": 16, 
     34    #         "created_at": "2006/08/01", "awesome": true, 
     35    #         "posts": [{"id": 1, "author_id": 1, "title": "Welcome to the weblog"}, 
     36    #                   {"id": 2, author_id: 1, "title": "So I was thinking"}]} 
    4237    # 
    4338    # 2nd level and higher order associations work as well: 
     
    4742    #                                                :only => :body } }, 
    4843    #                                  :only => :title } }) 
    49     # 
    50     #   {"id": 1, "name": "Konata Izumi", "age": 16, 
    51     #    "created_at": "2006/08/01", "awesome": true, 
    52     #    "posts": [{"comments": [{"body": "1st post!"}, {"body": "Second!"}], 
    53     #               "title": "Welcome to the weblog"}, 
    54     #              {"comments": [{"body": "Don't think too hard"}], 
    55     #               "title": "So I was thinking"}]} 
     44    #   # => {"id": 1, "name": "Konata Izumi", "age": 16, 
     45    #         "created_at": "2006/08/01", "awesome": true, 
     46    #         "posts": [{"comments": [{"body": "1st post!"}, {"body": "Second!"}], 
     47    #                    "title": "Welcome to the weblog"}, 
     48    #                   {"comments": [{"body": "Don't think too hard"}], 
     49    #                    "title": "So I was thinking"}]} 
    5650    def to_json(options = {}) 
    5751      JsonSerializer.new(self, options).to_s 
  • trunk/activerecord/lib/active_record/serializers/xml_serializer.rb

    r8258 r9093  
    11module ActiveRecord #:nodoc: 
    22  module Serialization 
    3     # Builds an XML document to represent the model.   Some configuration is 
    4     # available through +options+, however more complicated cases should 
    5     # override ActiveRecord's to_xml
     3    # Builds an XML document to represent the model. Some configuration is 
     4    # available through +options+. However more complicated cases should 
     5    # override ActiveRecord's to_xml method
    66    # 
    77    # By default the generated XML document will include the processing 
    8     # instruction and all object's attributes. For example: 
     8    # instruction and all the object's attributes. For example: 
    99    # 
    1010    #   <?xml version="1.0" encoding="UTF-8"?> 
     
    2424    # 
    2525    # This behavior can be controlled with :only, :except, 
    26     # :skip_instruct, :skip_types and :dasherize. The :only and 
     26    # :skip_instruct, :skip_types and :dasherize. The :only and 
    2727    # :except options are the same as for the #attributes method. 
    2828    # The default is to dasherize all column names, to disable this, 
    29     # set :dasherize to false. To not have the column type included 
     29    # set :dasherize to false. To not have the column type included 
    3030    # in the XML output, set :skip_types to true. 
    3131    # 
     
    6969    #   </firm> 
    7070    # 
     71    # To include deeper levels of associations pass a hash like this: 
     72    # 
     73    #   firm.to_xml :include => {:account => {}, :clients => {:include => :address}} 
     74    #   <?xml version="1.0" encoding="UTF-8"?> 
     75    #   <firm> 
     76    #     <id type="integer">1</id> 
     77    #     <rating type="integer">1</rating> 
     78    #     <name>37signals</name> 
     79    #     <clients type="array"> 
     80    #       <client> 
     81    #         <rating type="integer">1</rating> 
     82    #         <name>Summit</name> 
     83    #         <address> 
     84    #           ... 
     85    #         </address> 
     86    #       </client> 
     87    #       <client> 
     88    #         <rating type="integer">1</rating> 
     89    #         <name>Microsoft</name> 
     90    #         <address> 
     91    #           ... 
     92    #         </address> 
     93    #       </client> 
     94    #     </clients> 
     95    #     <account> 
     96    #       <id type="integer">1</id> 
     97    #       <credit-limit type="integer">50</credit-limit> 
     98    #     </account> 
     99    #   </firm> 
     100    # 
    71101    # To include any methods on the object(s) being called use :methods 
    72102    # 
     
    79109    #   </firm> 
    80110    # 
    81     # To call any Proc's on the object(s) use :procs.  The Proc'
     111    # To call any Procs on the object(s) use :procs. The Proc
    82112    # are passed a modified version of the options hash that was 
    83113    # given to #to_xml. 
     
    91121    #   </firm> 
    92122    # 
    93     # Alternatively, you can also just yield the builder object as part of the to_xml call: 
     123    # Alternatively, you can yield the builder object as part of the to_xml call: 
    94124    # 
    95125    #   firm.to_xml do |xml| 
     
    109139    # 
    110140    # You can override the to_xml method in your ActiveRecord::Base 
    111     # subclasses if you need to. The general form of doing this is 
     141    # subclasses if you need to. The general form of doing this is: 
    112142    # 
    113143    #   class IHaveMyOwnXML < ActiveRecord::Base 
     
    156186    end 
    157187 
    158  
    159     # To replicate the behavior in ActiveRecord#attributes, 
    160     # :except takes precedence over :only.  If :only is not set 
    161     # for a N level model but is set for the N+1 level models, 
    162     # then because :except is set to a default value, the second 
    163     # level model can have both :except and :only set.  So if 
    164     # :only is set, always delete :except. 
    165188    def serializable_attributes 
    166189      serializable_attribute_names.collect { |name| Attribute.new(name, @record) } 
     
    252275      # There is a significant speed improvement if the value 
    253276      # does not need to be escaped, as #tag! escapes all values 
    254       # to ensure that valid XML is generated. For known binary 
     277      # to ensure that valid XML is generated. For known binary 
    255278      # values, it is at least an order of magnitude faster to 
    256279      # Base64 encode binary values and directly put them in the 
  • trunk/activerecord/lib/active_record/timestamp.rb

    r8217 r9093  
    66  #   <tt>ActiveRecord::Base.record_timestamps = false</tt> 
    77  # 
    8   # Timestamps are in the local timezone by default but can use UTC by setting 
     8  # Timestamps are in the local timezone by default but you can use UTC by setting 
    99  #   <tt>ActiveRecord::Base.default_timezone = :utc</tt> 
    1010  module Timestamp 
  • trunk/activeresource/CHANGELOG

    r8827 r9093  
    11*SVN* 
     2 
     3* Improve documentation. [Radar, Jan De Poorter, chuyeow, xaviershay, danger, miloops, Xavier Noria,  Sunny Ripert] 
    24 
    35* Use HEAD instead of GET in exists? [bscofield] 
  • trunk/activesupport/CHANGELOG

    r9081 r9093  
    11*SVN* 
     2 
     3* Improve documentation. [Radar, Jan De Poorter, chuyeow, xaviershay, danger, miloops, Xavier Noria,  Sunny Ripert] 
    24 
    35* Ensure that TimeWithZone#to_yaml works when passed a YAML::Emitter.  [rick] 
  • trunk/activesupport/lib/active_support/basic_object.rb

    r8523 r9093  
    1 # Ruby 1.9 introduces BasicObject which differs slighly from Builder's BlankSlate 
    2 # that had been used so far ActiveSupport::BasicObject provides a barebones object with 
    3 # the same method on both versions. 
     1# A base class with no predefined methods that tries to behave like Builder's 
     2# BlankSlate in Ruby 1.9. In Ruby pre-1.9, this is actually the 
     3# Builder::BlankSlate class. 
     4
     5# Ruby 1.9 introduces BasicObject which differs slightly from Builder's 
     6# BlankSlate that has been used so far. ActiveSupport::BasicObject provides a 
     7# barebones base class that emulates Builder::BlankSlate while still relying on 
     8# Ruby 1.9's BasicObject in Ruby 1.9. 
    49module ActiveSupport 
    510  if RUBY_VERSION >= '1.9' 
  • trunk/activesupport/lib/active_support/core_ext/array/conversions.rb

    r8384 r9093  
    2525        end 
    2626 
    27         # Calls to_param on all its elements and joins the result with slashes. This is used by url_for in Action Pack.  
     27        # Calls <tt>to_param</tt> on all its elements and joins the result with 
     28        # slashes. This is used by <tt>url_for</tt> in Action Pack.  
    2829        def to_param 
    2930          map(&:to_param).join '/' 
     
    3334        # param name. 
    3435        # 
    35         # ==== Example: 
    36         #   ['Rails', 'coding'].to_query('hobbies') => "hobbies%5B%5D=Rails&hobbies%5B%5D=coding" 
     36        # Example: 
     37        # 
     38        #   ['Rails', 'coding'].to_query('hobbies') # => "hobbies%5B%5D=Rails&hobbies%5B%5D=coding" 
    3739        def to_query(key) 
    3840          collect { |value| value.to_query("#{key}[]") } * '&' 
     
    4648        end 
    4749 
     50        # Converts a collection of elements into a formatted string by calling 
     51        # <tt>to_s</tt> on all elements and joining them: 
     52        # 
     53        #   Blog.find(:all).to_formatted_s # => "First PostSecond PostThird Post" 
     54        # 
     55        # Adding in the <tt>:db</tt> argument as the format yields a prettier 
     56        # output: 
     57        # 
     58        #   Blog.find(:all).to_formatted_s(:db) # => "First Post,Second Post,Third Post" 
    4859        def to_formatted_s(format = :default) 
    4960          case format 
     
    5970        end 
    6071 
     72        # Returns a string that represents this array in XML by sending 
     73        # <tt>to_xml</tt> to each element. 
     74        # 
     75        # All elements are expected to respond to <tt>to_xml</tt>, if any of 
     76        # them does not an exception is raised. 
     77        # 
     78        # The root node reflects the class name of the first element in plural 
     79        # if all elements belong to the same type and that's not <tt>Hash</tt>. 
     80        # Otherwise the root element is "records". 
     81        # 
     82        # Root children have as node name the one of the root singularized. 
     83        # 
     84        # Example: 
     85        # 
     86        #   [{:foo => 1, :bar => 2}, {:baz => 3}].to_xml 
     87        # 
     88        #   <?xml version="1.0" encoding="UTF-8"?> 
     89        #   <records type="array"> 
     90        #     <record> 
     91        #       <bar type="integer">2</bar> 
     92        #       <foo type="integer">1</foo> 
     93        #     </record> 
     94        #     <record> 
     95        #       <baz type="integer">3</baz> 
     96        #     </record> 
     97        #   </records> 
     98        # 
     99        # The +options+ hash is passed downwards: 
     100        # 
     101        #   [Message.find(:first)].to_xml(:skip_types => true) 
     102        # 
     103        #   <?xml version="1.0" encoding="UTF-8"?> 
     104        #   <messages> 
     105        #     <message> 
     106        #       <created-at>2008-03-07T09:58:18+01:00</created-at> 
     107        #       <id>1</id> 
     108        #       <name>1</name> 
     109        #       <updated-at>2008-03-07T09:58:18+01:00</updated-at> 
     110        #       <user-id>1</user-id> 
     111        #     </message> 
     112        #   </messages> 
     113        # 
    61114        def to_xml(options = {}) 
    62115          raise "Not all elements respond to to_xml" unless all? { |e| e.respond_to? :to_xml } 
  • trunk/activesupport/lib/active_support/core_ext/array/grouping.rb

    r8161 r9093  
    99        # <tt>false</tt>. 
    1010        #  
    11         # E.g. 
     11        # Examples: 
    1212        #  
    1313        #   %w(1 2 3 4 5 6 7).in_groups_of(3) {|g| p g} 
     
    4646        # or the result of an optional block. 
    4747        # 
    48         # ex. 
     48        # Examples: 
    4949        # 
    5050        #   [1, 2, 3, 4, 5].split(3)                # => [[1, 2], [4, 5]] 
  • trunk/activesupport/lib/active_support/core_ext/blank.rb

    r8137 r9093  
    11class Object 
    2   # An object is blank if it's nil, empty, or a whitespace string. 
     2  # An object is blank if it's false, empty, or a whitespace string. 
    33  # For example, "", "   ", nil, [], and {} are blank. 
    44  # 
  • trunk/activesupport/lib/active_support/core_ext/class/removal.rb

    r7474 r9093  
    11class Class #:nodoc: 
     2   
     3  # Will unassociate the class with its subclasses as well as uninitializing the subclasses themselves. 
     4  # >> Integer.remove_subclasses 
     5  # => [Bignum, Fixnum] 
     6  # >> Fixnum 
     7  # NameError: uninitialized constant Fixnum 
    28  def remove_subclasses 
    39    Object.remove_subclasses_of(self) 
    410  end 
    511 
     12  # Returns a list of classes that inherit from this class in an array. 
     13  # Example: Integer.subclasses => ["Bignum", "Fixnum"] 
    614  def subclasses 
    715    Object.subclasses_of(self).map { |o| o.to_s } 
    816  end 
    917 
     18  # Allows you to remove individual subclasses or a selection of subclasses from a class without removing all of them. 
    1019  def remove_class(*klasses) 
    1120    klasses.flatten.each do |klass| 
  • trunk/activesupport/lib/active_support/core_ext/date/calculations.rb

    r8934 r9093  
    1717 
    1818        module ClassMethods 
     19          # Finds yesterday's date, in the format similar to: Mon, 17 Mar 2008 
    1920          def yesterday 
    2021            ::Date.today.yesterday 
    2122          end 
    2223           
     24          # Finds tommorrow's date, in the format similar to: Tue, 18 Mar 2008 
    2325          def tomorrow 
    2426            ::Date.today.tomorrow 
  • trunk/activesupport/lib/active_support/core_ext/enumerable.rb

    r8700 r9093  
    33  # for example, for grouping records by date. 
    44  # 
    5   # e.g.  
     5  # Example: 
    66  # 
    77  #   latest_transcripts.group_by(&:day).each do |day, transcripts|  
     
    2424  # Calculates a sum from the elements. Examples: 
    2525  # 
    26   #  payments.sum { |p| p.price * p.tax_rate } 
    27   #  payments.sum(&:price) 
     26  #  payments.sum { |p| p.price * p.tax_rate } 
     27  #  payments.sum(&:price) 
    2828  # 
    29   # This is instead of payments.inject { |sum, p| sum + p.price } 
     29  # This is instead of 
     30  # 
     31  #   payments.inject { |sum, p| sum + p.price } 
    3032  # 
    3133  # Also calculates sums without the use of a block: 
     34  # 
    3235  #   [5, 15, 10].sum # => 30 
    3336  # 
     
    3538  # However, you can override this default: 
    3639  # 
    37   # [].sum(Payment.new(0)) { |i| i.amount } # => Payment.new(0) 
     40  #   [].sum(Payment.new(0)) { |i| i.amount } # => Payment.new(0) 
    3841  # 
    3942  def sum(identity = 0, &block) 
  • trunk/activesupport/lib/active_support/core_ext/file.rb

    r6262 r9093  
    44# want other processes or threads to see half-written files. 
    55# 
    6 File.atomic_write("important.file") do |file| 
    7 #    file.write("hello") 
    8 end 
     6 File.atomic_write("important.file") do |file| 
     7#    file.write("hello") 
     8 end 
    99# 
    1010# If your temp directory is not on the same filesystem as the file you're  
    1111# trying to write, you can provide a different temporary directory. 
    1212#  
    13 # File.atomic_write("/data/something.imporant", "/data/tmp") do |f| 
    14 #   file.write("hello") 
    15 # end 
     13#   File.atomic_write("/data/something.important", "/data/tmp") do |f| 
     14#     file.write("hello") 
     15#   end 
    1616def File.atomic_write(file_name, temp_dir = Dir.tmpdir) 
    1717  temp_file = Tempfile.new(File.basename(file_name), temp_dir) 
  • trunk/activesupport/lib/active_support/core_ext/hash/indifferent_access.rb

    r8332 r9093  
    11# This class has dubious semantics and we only have it so that 
    22# people can write params[:key] instead of params['key'] 
     3# and they get the same value for both keys. 
    34 
    45class HashWithIndifferentAccess < Hash 
     
    2324  alias_method :regular_update, :update unless method_defined?(:regular_update) 
    2425 
     26  # 
     27  # Assigns a new value to the hash. 
     28  # 
     29  # Example: 
     30  # 
     31  #   hash = HashWithIndifferentAccess.new 
     32  #   hash[:key] = "value" 
     33  # 
    2534  def []=(key, value) 
    2635    regular_writer(convert_key(key), convert_value(value)) 
    2736  end 
    2837 
     38  #  
     39  # Updates the instantized hash with values from the second. 
     40  #  
     41  # Example: 
     42  #  
     43  #   >> hash_1 = HashWithIndifferentAccess.new 
     44  #   => {} 
     45  #  
     46  #   >> hash_1[:key] = "value" 
     47  #   => "value" 
     48  #  
     49  #   >> hash_2 = HashWithIndifferentAccess.new 
     50  #   => {} 
     51  #  
     52  #   >> hash_2[:key] = "New Value!" 
     53  #   => "New Value!" 
     54  #  
     55  #   >> hash_1.update(hash_2) 
     56  #   => {"key"=>"New Value!"} 
     57  #  
    2958  def update(other_hash) 
    3059    other_hash.each_pair { |key, value| regular_writer(convert_key(key), convert_value(value)) } 
     
    3463  alias_method :merge!, :update 
    3564 
     65  # Checks the hash for a key matching the argument passed in 
    3666  def key?(key) 
    3767    super(convert_key(key)) 
     
    4272  alias_method :member?, :key? 
    4373 
     74  # Fetches the value for the specified key, same as doing hash[key] 
    4475  def fetch(key, *extras) 
    4576    super(convert_key(key), *extras) 
    4677  end 
    4778 
     79  # Returns an array of the values at the specified indicies.  
    4880  def values_at(*indices) 
    4981    indices.collect {|key| self[convert_key(key)]} 
    5082  end 
    5183 
     84  # Returns an exact copy of the hash. 
    5285  def dup 
    5386    HashWithIndifferentAccess.new(self) 
    5487  end 
    5588 
     89  # Merges the instantized and the specified hashes together, giving precedence to the values from the second hash 
     90  # Does not overwrite the existing hash. 
    5691  def merge(hash) 
    5792    self.dup.update(hash) 
    5893  end 
    5994 
     95  # Removes a specified key from the hash. 
    6096  def delete(key) 
    6197    super(convert_key(key)) 
  • trunk/activesupport/lib/active_support/core_ext/hash/reverse_merge.rb

    r5725 r9093  
    1111      # The default :size and :velocity is only set if the +options+ passed in doesn't already have those keys set. 
    1212      module ReverseMerge 
     13        # Performs the opposite of merge, with the keys and values from the first hash taking precedence over the second. 
    1314        def reverse_merge(other_hash) 
    1415          other_hash.merge(self) 
    1516        end 
    1617 
     18        # Performs the opposite of merge, with the keys and values from the first hash taking precedence over the second. 
     19        # Modifies the receiver in place. 
    1720        def reverse_merge!(other_hash) 
    1821          replace(reverse_merge(other_hash)) 
  • trunk/activesupport/lib/active_support/core_ext/integer/even_odd.rb

    r8397 r9093  
    22  module CoreExtensions #:nodoc: 
    33    module Integer #:nodoc: 
    4       # For checking if a fixnum is even or odd.  
    5       # * 1.even? # => false 
    6       # * 1.odd?  # => true 
    7       # * 2.even? # => true 
    8       # * 2.odd? # => false 
     4      # For checking if a fixnum is even or odd. 
     5      # 
     6      # Examples: 
     7      # 
     8      #   1.even? # => false 
     9      #   1.odd?  # => true 
     10      #   2.even? # => true 
     11      #   2.odd? # => false 
    912      module EvenOdd 
    1013        def multiple_of?(number) 
  • trunk/activesupport/lib/active_support/core_ext/integer/inflections.rb

    r5924 r9093  
    88        # position in an ordered sequence such as 1st, 2nd, 3rd, 4th. 
    99        # 
    10         # Examples 
     10        # Examples: 
     11        # 
    1112        #   1.ordinalize    # => "1st" 
    1213        #   2.ordinalize    # => "2nd" 
  • trunk/activesupport/lib/active_support/core_ext/kernel/reporting.rb

    r3761 r9093  
    4343  end 
    4444 
     45  # Blocks and ignores any exception passed as argument if raised within the block. 
     46  # 
     47  #   suppress(ZeroDivisionError) do 
     48  #     1/0 
     49  #     puts "This code is NOT reached" 
     50  #   end 
     51  # 
     52  #   puts "This code gets executed and nothing related to ZeroDivisionError was seen" 
    4553  def suppress(*exception_classes) 
    4654    begin yield 
  • trunk/activesupport/lib/active_support/core_ext/module/attr_internal.rb

    r4839 r9093  
    1414  end 
    1515 
    16   # Declare attributes backed by 'internal' instance variables names. 
     16  # Declare an attribute reader and writer backed by an internally-named instance 
     17  # variable. 
    1718  def attr_internal_accessor(*attrs) 
    1819    attr_internal_reader(*attrs) 
  • trunk/activesupport/lib/active_support/core_ext/module/inclusion.rb

    r3519 r9093  
    11class Module 
     2  # Returns the classes in the current ObjectSpace where this module has been 
     3  # mixed in according to Module#included_modules. 
     4  # 
     5  #   module M 
     6  #   end 
     7  #    
     8  #   module N 
     9  #     include M 
     10  #   end 
     11  #    
     12  #   class C 
     13  #     include M 
     14  #   end 
     15  #    
     16  #   class D < C 
     17  #   end 
     18  # 
     19  #   p M.included_in_classes # => [C, D] 
     20  # 
    221  def included_in_classes 
    322    classes = [] 
  • trunk/activesupport/lib/active_support/core_ext/module/introspection.rb

    r8555 r9093  
    11class Module 
    2   # Return the module which contains this one; if this is a root module, such as 
    3   # +::MyModule+, then Object is returned. 
     2  # Returns the module which contains this one according to its name. 
     3  # 
     4  #   module M 
     5  #     module N 
     6  #     end 
     7  #   end 
     8  #   X = M::N 
     9  #    
     10  #   p M::N.parent # => M 
     11  #   p X.parent    # => M 
     12  # 
     13  # The parent of top-level and anonymous modules is Object. 
     14  # 
     15  #   p M.parent          # => Object 
     16  #   p Module.new.parent # => Object 
     17  # 
    418  def parent 
    519    parent_name = name.split('::')[0..-2] * '::' 
     
    721  end 
    822 
    9   # Return all the parents of this module, ordered from nested outwards. The 
    10   # receiver is not contained within the result. 
     23  # Returns all the parents of this module according to its name, ordered from 
     24  # nested outwards. The receiver is not contained within the result. 
     25  # 
     26  #   module M 
     27  #     module N 
     28  #     end 
     29  #   end 
     30  #   X = M::N 
     31  #    
     32  #   p M.parents    # => [Object] 
     33  #   p M::N.parents # => [M, Object] 
     34  #   p X.parents    # => [M, Object] 
     35  # 
    1136  def parents 
    1237    parents = [] 
     
    2146 
    2247  if RUBY_VERSION < '1.9' 
    23     # Return the constants that have been defined locally by this object and 
     48    # Returns the constants that have been defined locally by this object and 
    2449    # not in an ancestor. This method is exact if running under Ruby 1.9. In 
    2550    # previous versions it may miss some constants if their definition in some 
  • trunk/activesupport/lib/active_support/core_ext/module/loading.rb

    r4060 r9093  
    11class Module 
     2  # Returns String#underscore applied to the module name minus trailing classes. 
     3  # 
     4  #   ActiveRecord.as_load_path               # => "active_record" 
     5  #   ActiveRecord::Associations.as_load_path # => "active_record/associations" 
     6  #   ActiveRecord::Base.as_load_path         # => "active_record" (Base is a class) 
     7  # 
     8  # The Kernel module gives an empty string by definition. 
     9  # 
     10  #   Kernel.as_load_path # => "" 
     11  #   Math.as_load_path   # => "math" 
    212  def as_load_path 
    313    if self == Object || self == Kernel 
  • trunk/activesupport/lib/active_support/core_ext/object/instance_variables.rb

    r8499 r9093  
    77  end 
    88 
     9  # Returns a hash that maps instance variable names without "@" to their 
     10  # corresponding values. Keys are strings both in Ruby 1.8 and 1.9. 
     11  # 
     12  #   class C 
     13  #     def initialize(x, y) 
     14  #       @x, @y = x, y 
     15  #     end 
     16  #   end 
     17  #    
     18  #   C.new(0, 1).instance_values # => {"x" => 0, "y" => 1} 
    919  def instance_values #:nodoc: 
    1020    instance_variables.inject({}) do |values, name| 
     
    1424  end 
    1525 
     26  # Returns an array of instance variable names including "@". They are strings 
     27  # both in Ruby 1.8 and 1.9. 
     28  # 
     29  #   class C 
     30  #     def initialize(x, y) 
     31  #       @x, @y = x, y 
     32  #     end 
     33  #   end 
     34  #    
     35  #   C.new(0, 1).instance_variable_names # => ["@y", "@x"] 
    1636  def instance_variable_names 
    1737    instance_variables.map(&:to_s) 
    1838  end 
    1939 
     40  # Copies the instance variables of +object+ into self. 
     41  # 
     42  # Instance variable names in the +exclude+ array are ignored. If +object+ 
     43  # responds to <tt>protected_instance_variables</tt> the ones returned are 
     44  # also ignored. For example, Rails controllers implement that method. 
     45  # 
     46  # In both cases strings and symbols are understood, and they have to include 
     47  # the at sign. 
     48  # 
     49  #   class C 
     50  #     def initialize(x, y, z) 
     51  #       @x, @y, @z = x, y, z 
     52  #     end 
     53  #    
     54  #     def protected_instance_variables 
     55  #       %w(@z) 
     56  #     end 
     57  #   end 
     58  #    
     59  #   a = C.new(0, 1, 2) 
     60  #   b = C.new(3, 4, 5) 
     61  #    
     62  #   a.copy_instance_variables_from(b, [:@y]) 
     63  #   # a is now: @x = 3, @y = 1, @z = 2 
    2064  def copy_instance_variables_from(object, exclude = []) #:nodoc: 
    2165    exclude += object.protected_instance_variables if object.respond_to? :protected_instance_variables 
  • trunk/activesupport/lib/active_support/core_ext/range/conversions.rb

    r8397 r9093  
    1414          end 
    1515        end 
    16  
     16        # Gives a human readable format of the range. 
     17        # 
     18        # Example:  
     19        #  
     20        # >> [1..100].to_formatted_s 
     21        # => "1..100" 
    1722        def to_formatted_s(format = :default) 
    1823          RANGE_FORMATS[format] ? RANGE_FORMATS[format].call(first, last) : to_default_s 
  • trunk/activesupport/lib/active_support/core_ext/string/inflections.rb

    r8596 r9093  
    66      # String inflections define new methods on the String class to transform names for different purposes. 
    77      # For instance, you can figure out the name of a database from the name of a class. 
    8       #   "ScaleScore".tableize => "scale_scores" 
     8      # 
     9      #   "ScaleScore".tableize # => "scale_scores" 
    910      module Inflections 
    1011        # Returns the plural form of the word in the string. 
    1112        # 
    12         # Examples 
    13         #   "post".pluralize #=> "posts" 
    14         #   "octopus".pluralize #=> "octopi" 
    15         #   "sheep".pluralize #=> "sheep" 
    16         #   "words".pluralize #=> "words" 
    17         #   "the blue mailman".pluralize #=> "the blue mailmen" 
    18         #   "CamelOctopus".pluralize #=> "CamelOctopi" 
     13        #   "post".pluralize             # => "posts" 
     14        #   "octopus".pluralize          # => "octopi" 
     15        #   "sheep".pluralize            # => "sheep" 
     16        #   "words".pluralize            # => "words" 
     17        #   "the blue mailman".pluralize # => "the blue mailmen" 
     18        #   "CamelOctopus".pluralize     # => "CamelOctopi" 
    1919        def pluralize 
    2020          Inflector.pluralize(self) 
    2121        end 
    2222 
    23         # The reverse of pluralize, returns the singular form of a word in a string. 
     23        # The reverse of +pluralize+, returns the singular form of a word in a string. 
    2424        # 
    25         # Examples 
    26         #   "posts".singularize #=> "post" 
    27         #   "octopi".singularize #=> "octopus" 
    28         #   "sheep".singluarize #=> "sheep" 
    29         #   "word".singluarize #=> "word" 
    30         #   "the blue mailmen".singularize #=> "the blue mailman" 
    31         #   "CamelOctopi".singularize #=> "CamelOctopus" 
     25        #   "posts".singularize            # => "post" 
     26        #   "octopi".singularize           # => "octopus" 
     27        #   "sheep".singluarize            # => "sheep" 
     28        #   "word".singluarize             # => "word" 
     29        #   "the blue mailmen".singularize # => "the blue mailman" 
     30        #   "CamelOctopi".singularize      # => "CamelOctopus" 
    3231        def singularize 
    3332          Inflector.singularize(self) 
    3433        end 
    3534 
    36         # By default, camelize converts strings to UpperCamelCase. If the argument to camelize 
    37         # is set to ":lower" then camelize produces lowerCamelCase. 
     35        # By default, +camelize+ converts strings to UpperCamelCase. If the argument to camelize 
     36        # is set to <tt>:lower</tt> then camelize produces lowerCamelCase. 
    3837        # 
    39         # camelize will also convert '/' to '::' which is useful for converting paths to namespaces  
     38        # +camelize+ will also convert '/' to '::' which is useful for converting paths to namespaces. 
    4039        # 
    41         # Examples 
    42         #   "active_record".camelize #=> "ActiveRecord" 
    43         #   "active_record".camelize(:lower) #=> "activeRecord" 
    44         #   "active_record/errors".camelize #=> "ActiveRecord::Errors" 
    45         #   "active_record/errors".camelize(:lower) #=> "activeRecord::Errors" 
     40        #   "active_record".camelize                # => "ActiveRecord" 
     41        #   "active_record".camelize(:lower)        # => "activeRecord" 
     42        #   "active_record/errors".camelize         # => "ActiveRecord::Errors" 
     43        #   "active_record/errors".camelize(:lower) # => "activeRecord::Errors" 
    4644        def camelize(first_letter = :upper) 
    4745          case first_letter 
     
    5351 
    5452        # Capitalizes all the words and replaces some characters in the string to create 
    55         # a nicer looking title. Titleize is meant for creating pretty output. It is not 
     53        # a nicer looking title. +titleize+ is meant for creating pretty output. It is not 
    5654        # used in the Rails internals. 
    5755        # 
    58         # titleize is also aliased as as titlecase 
     56        # +titleize+ is also aliased as +titlecase+. 
    5957        # 
    60         # Examples 
    61         #   "man from the boondocks".titleize #=> "Man From The Boondocks" 
    62         #   "x-men: the last stand".titleize #=> "X Men: The Last Stand" 
     58        #   "man from the boondocks".titleize # => "Man From The Boondocks" 
     59        #   "x-men: the last stand".titleize  # => "X Men: The Last Stand" 
    6360        def titleize 
    6461          Inflector.titleize(self) 
     
    6663        alias_method :titlecase, :titleize 
    6764 
    68         # The reverse of +camelize+. Makes an underscored form from the expression in the string. 
     65        # The reverse of +camelize+. Makes an underscored, lowercase form from the expression in the string. 
    6966        #  
    70         # Changes '::' to '/' to convert namespaces to paths. 
     67        # +underscore+ will also change '::' to '/' to convert namespaces to paths. 
    7168        # 
    72         # Examples 
    73         #   "ActiveRecord".underscore #=> "active_record" 
    74         #   "ActiveRecord::Errors".underscore #=> active_record/errors 
     69        #   "ActiveRecord".underscore         # => "active_record" 
     70        #   "ActiveRecord::Errors".underscore # => active_record/errors 
    7571        def underscore 
    7672          Inflector.underscore(self) 
     
    7975        # Replaces underscores with dashes in the string. 
    8076        # 
    81         # Example 
    82         #   "puni_puni" #=> "puni-puni" 
     77        #   "puni_puni" # => "puni-puni" 
    8378        def dasherize 
    8479          Inflector.dasherize(self) 
    8580        end 
    8681 
    87         # Removes the module part from the expression in the string 
     82        # Removes the module part from the constant expression in the string. 
    8883        # 
    89         # Examples 
    90         #   "ActiveRecord::CoreExtensions::String::Inflections".demodulize #=> "Inflections" 
    91         #   "Inflections".demodulize #=> "Inflections" 
     84        #   "ActiveRecord::CoreExtensions::String::Inflections".demodulize # => "Inflections" 
     85        #   "Inflections".demodulize                                       # => "Inflections" 
    9286        def demodulize 
    9387          Inflector.demodulize(self) 
    9488        end 
    9589 
    96         # Create the name of a table like Rails does for models to table names. This method 
    97         # uses the pluralize method on the last word in the string. 
     90        # Creates the name of a table like Rails does for models to table names. This method 
     91        # uses the +pluralize+ method on the last word in the string. 
    9892        # 
    99         # Examples 
    100         #   "RawScaledScorer".tableize #=> "raw_scaled_scorers" 
    101         #   "egg_and_ham".tableize #=> "egg_and_hams" 
    102         #   "fancyCategory".tableize #=> "fancy_categories" 
     93        #   "RawScaledScorer".tableize # => "raw_scaled_scorers" 
     94        #   "egg_and_ham".tableize     # => "egg_and_hams" 
     95        #   "fancyCategory".tableize   # => "fancy_categories" 
    10396        def tableize 
    10497          Inflector.tableize(self) 
     
    10699 
    107100        # Create a class name from a plural table name like Rails does for table names to models. 
    108         # Note that this returns a string and not a Class. (To convert to an actual class 
    109         # follow classify with constantize.) 
     101        # Note that this returns a string and not a class. (To convert to an actual class 
     102        # follow +classify+ with +constantize+.) 
    110103        # 
    111         # Examples 
    112         #   "egg_and_hams".classify #=> "EggAndHam" 
    113         #   "posts".classify #=> "Post" 
     104        #   "egg_and_hams".classify # => "EggAndHam" 
     105        #   "posts".classify        # => "Post" 
    114106        # 
    115         # Singular names are not handled correctly 
    116         #   "business".classify #=> "Busines" 
     107        # Singular names are not handled correctly. 
     108        # 
     109        #   "business".classify # => "Busines" 
    117110        def classify 
    118111          Inflector.classify(self) 
    119112        end 
    120113         
    121         # Capitalizes the first word and turns underscores into spaces and strips _id
    122         # Like titleize, this is meant for creating pretty output. 
     114        # Capitalizes the first word, turns underscores into spaces, and strips '_id'
     115        # Like +titleize+, this is meant for creating pretty output. 
    123116        # 
    124         # Examples 
    125         #   "employee_salary" #=> "Employee salary"  
    126         #   "author_id" #=> "Author" 
     117        #   "employee_salary" # => "Employee salary"  
     118        #   "author_id"       # => "Author" 
    127119        def humanize 
    128120          Inflector.humanize(self) 
     
    134126        # 
    135127        # Examples 
    136         #   "Message".foreign_key #=> "message_id" 
    137         #   "Message".foreign_key(false) #=> "messageid" 
    138         #   "Admin::Post".foreign_key #=> "post_id" 
     128        #   "Message".foreign_key        # => "message_id" 
     129        #   "Message".foreign_key(false) # => "messageid" 
     130        #   "Admin::Post".foreign_key    # => "post_id" 
    139131        def foreign_key(separate_class_name_and_id_with_underscore = true) 
    140132          Inflector.foreign_key(self, separate_class_name_and_id_with_underscore) 
    141133        end 
    142134 
    143         # Constantize tries to find a declared constant with the name specified 
     135        # +constantize+ tries to find a declared constant with the name specified 
    144136        # in the string. It raises a NameError when the name is not in CamelCase 
    145137        # or is not initialized. 
    146138        # 
    147139        # Examples 
    148         #   "Module".constantize #=> Module 
    149         #   "Class".constantize #=> Class 
     140        #   "Module".constantize # => Module 
     141        #   "Class".constantize # => Class 
    150142        def constantize 
    151143          Inflector.constantize(self) 
  • trunk/activesupport/lib/active_support/core_ext/string/unicode.rb

    r8460 r9093  
    2828          # 
    2929          # For more information about the methods defined on the Chars proxy see ActiveSupport::Multibyte::Chars and 
    30           # ActiveSupport::Multibyte::Handlers::UTF8Handler 
     30          # ActiveSupport::Multibyte::Handlers::UTF8Handler. 
    3131          def chars 
    3232            ActiveSupport::Multibyte::Chars.new(self) 
  • trunk/activesupport/lib/active_support/core_ext/time/zones.rb

    r9047 r9093  
    4444        end 
    4545         
    46         # Returns the simultaneous time in Time.zone. Example: 
     46        # Returns the simultaneous time in Time.zone. 
    4747        # 
    48         #   Time.zone = 'Hawaii'                    # => 'Hawaii' 
    49         #   Time.utc(2000).in_time_zone             # => Fri, 31 Dec 1999 14:00:00 HST -10:00 
     48        #   Time.zone = 'Hawaii'         # => 'Hawaii' 
     49        #   Time.utc(2000).in_time_zone  # => Fri, 31 Dec 1999 14:00:00 HST -10:00 
    5050        # 
    5151        # This method is similar to Time#localtime, except that it uses Time.zone as the local zone 
     
    5353        # 
    5454        # You can also pass in a TimeZone instance or string that identifies a TimeZone as an argument,  
    55         # and the conversion will be based on that zone instead of Time.zone. Example: 
     55        # and the conversion will be based on that zone instead of Time.zone. 
    5656        # 
    57         #   Time.utc(2000).in_time_zone('Alaska')  # => Fri, 31 Dec 1999 15:00:00 AKST -09:00 
     57        #   Time.utc(2000).in_time_zone('Alaska')  # => Fri, 31 Dec 1999 15:00:00 AKST -09:00 
    5858        def in_time_zone(zone = ::Time.zone) 
    5959          ActiveSupport::TimeWithZone.new(utc? ? self : getutc, ::Time.send!(:get_zone, zone)) 
  • trunk/activesupport/lib/active_support/gzip.rb

    r8546 r9093  
    33 
    44module ActiveSupport 
     5  # A convenient wrapper for the zlib standard library that allows compression/decompression of strings with gzip. 
    56  module Gzip 
    67    class Stream < StringIO 
     
    89    end 
    910 
     11    # Decompresses a gzipped string. 
    1012    def self.decompress(source) 
    1113      Zlib::GzipReader.new(StringIO.new(source)).read 
    1214    end 
    1315 
     16    # Compresses a string using gzip. 
    1417    def self.compress(source) 
    1518      output = Stream.new 
  • trunk/activesupport/lib/active_support/inflector.rb

    r8788 r9093  
    166166  end 
    167167 
    168   # The reverse of +camelize+. Makes an underscored form from the expression in the string. 
     168  # The reverse of +camelize+. Makes an underscored, lowercase form from the expression in the string. 
    169169  # 
    170170  # Changes '::' to '/' to convert namespaces to paths. 
  • trunk/activesupport/lib/active_support/json/encoders/date_time.rb

    r7746 r9093  
    11class DateTime 
    2   def to_json(options = nil) #:nodoc: 
     2  # Returns a JSON string representing the datetime. 
     3  # 
     4  # ==== Example: 
     5  #   DateTime.civil(2005,2,1,15,15,10).to_json 
     6  #   # => "2005/02/01 15:15:10 +0000" 
     7  def to_json(options = nil) 
    38    %("#{strftime("%Y/%m/%d %H:%M:%S %z")}") 
    49  end 
  • trunk/activesupport/lib/active_support/json/encoders/date.rb

    r7746 r9093  
    11class Date 
    2   def to_json(options = nil) #:nodoc: 
     2  # Returns a JSON string representing the date. 
     3  # 
     4  # ==== Example: 
     5  #   Date.new(2005,2,1).to_json 
     6  #   # => "2005/02/01" 
     7  def to_json(options = nil) 
    38    %("#{strftime("%Y/%m/%d")}") 
    49  end 
  • trunk/activesupport/lib/active_support/json/encoders/enumerable.rb

    r8010 r9093  
    33  # given will be passed on to its elements. For example: 
    44  # 
    5   # users = User.find(:all) 
    6   # users.to_json(:only => :name) 
     5  #   users = User.find(:all) 
     6  #   # => users.to_json(:only => :name) 
    77  # 
    88  # will pass the <tt>:only => :name</tt> option to each user. 
  • trunk/activesupport/lib/active_support/json/encoders/hash.rb

    r8010 r9093  
    66  # 
    77  #   { :name => "Konata Izumi", 'age' => 16, 1 => 2 }.to_json 
    8   # 
    9   #   {"name": "Konata Izumi", 1: 2, "age": 16} 
     8  #   # => {"name": "Konata Izumi", 1: 2, "age": 16} 
    109  # 
    1110  # The keys in the JSON string are unordered due to the nature of hashes. 
     
    1514  # 
    1615  #   { :name => "Konata Izumi", 'age' => 16, 1 => 2 }.to_json(:only => [:name, 'age']) 
    17   # 
    18   #   {"name": "Konata Izumi", "age": 16} 
     16  #   # => {"name": "Konata Izumi", "age": 16} 
    1917  # 
    2018  #   { :name => "Konata Izumi", 'age' => 16, 1 => 2 }.to_json(:except => 1) 
    21   # 
    22   #   {"name": "Konata Izumi", "age": 16} 
     19  #   # => {"name": "Konata Izumi", "age": 16} 
    2320  # 
    2421  # The +options+ also filter down to any hash values. This is particularly 
  • trunk/activesupport/lib/active_support/json/encoders/object.rb

    r7736 r9093  
    11class Object 
    2   # Dumps object in JSON (JavaScript Object Notation). See www.json.org for more info. 
     2  # Dumps object in JSON (JavaScript Object Notation). See www.json.org for more info. 
    33  def to_json(options = {}) 
    44    ActiveSupport::JSON.encode(instance_values, options) 
  • trunk/activesupport/lib/active_support/json/encoders/time.rb

    r8698 r9093  
    11class Time 
    2   def to_json(options = nil) #:nodoc: 
     2  # Returns a JSON string representing the time. 
     3  # 
     4  # ==== Example: 
     5  #   Time.utc(2005,2,1,15,15,10).to_json 
     6  #   # => 2005/02/01 15:15:10 +0000" 
     7  def to_json(options = nil) 
    38    %("#{strftime("%Y/%m/%d %H:%M:%S")} #{formatted_offset(false)}") 
    49  end 
  • trunk/activesupport/lib/active_support/whiny_nil.rb

    r6818 r9093  
    1919  end 
    2020 
     21  # Raises a RuntimeError when you attempt to call id on nil or a nil object. 
    2122  def id 
    2223    raise RuntimeError, "Called id for nil, which would mistakenly be 4 -- if you really wanted the id of nil, use object_id", caller 
     
    2829    end 
    2930 
     31    # Raises a NoMethodError when you attempt to call a method on nil, or a nil object. 
    3032    def raise_nil_warning_for(class_name = nil, selector = nil, with_caller = nil) 
    3133      message = "You have a nil object when you didn't expect it!" 
  • trunk/railties/CHANGELOG

    r9076 r9093  
    11*SVN* 
     2 
     3* Improve documentation. [Radar, Jan De Poorter, chuyeow, xaviershay, danger, miloops, Xavier Noria,  Sunny Ripert] 
    24 
    35* Added config.time_zone = 'UTC' as a commented-out option in the default environment.rb [Geoff Buesing] 
  • trunk/railties/configs/routes.rb

    r7517 r9093  
    1818  # Sample resource route with sub-resources: 
    1919  #   map.resources :products, :has_many => [ :comments, :sales ], :has_one => :seller 
     20   
     21  # Sample resource route with more complex sub-resources 
     22  #   map.resources :products do |products| 
     23  #     products.resources :comments 
     24  #     products.resources :sales, :collection => { :recent => :get } 
     25  #   end 
    2026 
    2127  # Sample resource route within a namespace: