Changeset 9093
- Timestamp:
- 03/26/08 12:27:52 (1 year ago)
- Files:
-
- trunk/actionpack/CHANGELOG (modified) (1 diff)
- trunk/actionpack/lib/action_controller/resources.rb (modified) (1 diff)
- trunk/actionpack/lib/action_view/helpers/atom_feed_helper.rb (modified) (1 diff)
- trunk/actionpack/lib/action_view/helpers/form_helper.rb (modified) (5 diffs)
- trunk/activerecord/CHANGELOG (modified) (1 diff)
- trunk/activerecord/lib/active_record/fixtures.rb (modified) (1 diff)
- trunk/activerecord/lib/active_record/migration.rb (modified) (1 diff)
- trunk/activerecord/lib/active_record/serializers/json_serializer.rb (modified) (3 diffs)
- trunk/activerecord/lib/active_record/serializers/xml_serializer.rb (modified) (8 diffs)
- trunk/activerecord/lib/active_record/timestamp.rb (modified) (1 diff)
- trunk/activeresource/CHANGELOG (modified) (1 diff)
- trunk/activesupport/CHANGELOG (modified) (1 diff)
- trunk/activesupport/lib/active_support/basic_object.rb (modified) (1 diff)
- trunk/activesupport/lib/active_support/core_ext/array/conversions.rb (modified) (4 diffs)
- trunk/activesupport/lib/active_support/core_ext/array/grouping.rb (modified) (2 diffs)
- trunk/activesupport/lib/active_support/core_ext/blank.rb (modified) (1 diff)
- trunk/activesupport/lib/active_support/core_ext/class/removal.rb (modified) (1 diff)
- trunk/activesupport/lib/active_support/core_ext/date/calculations.rb (modified) (1 diff)
- trunk/activesupport/lib/active_support/core_ext/enumerable.rb (modified) (3 diffs)
- trunk/activesupport/lib/active_support/core_ext/file.rb (modified) (1 diff)
- trunk/activesupport/lib/active_support/core_ext/hash/indifferent_access.rb (modified) (4 diffs)
- trunk/activesupport/lib/active_support/core_ext/hash/reverse_merge.rb (modified) (1 diff)
- trunk/activesupport/lib/active_support/core_ext/integer/even_odd.rb (modified) (1 diff)
- trunk/activesupport/lib/active_support/core_ext/integer/inflections.rb (modified) (1 diff)
- trunk/activesupport/lib/active_support/core_ext/kernel/reporting.rb (modified) (1 diff)
- trunk/activesupport/lib/active_support/core_ext/module/attr_internal.rb (modified) (1 diff)
- trunk/activesupport/lib/active_support/core_ext/module/inclusion.rb (modified) (1 diff)
- trunk/activesupport/lib/active_support/core_ext/module/introspection.rb (modified) (3 diffs)
- trunk/activesupport/lib/active_support/core_ext/module/loading.rb (modified) (1 diff)
- trunk/activesupport/lib/active_support/core_ext/object/instance_variables.rb (modified) (2 diffs)
- trunk/activesupport/lib/active_support/core_ext/range/conversions.rb (modified) (1 diff)
- trunk/activesupport/lib/active_support/core_ext/string/inflections.rb (modified) (6 diffs)
- trunk/activesupport/lib/active_support/core_ext/string/unicode.rb (modified) (1 diff)
- trunk/activesupport/lib/active_support/core_ext/time/zones.rb (modified) (2 diffs)
- trunk/activesupport/lib/active_support/gzip.rb (modified) (2 diffs)
- trunk/activesupport/lib/active_support/inflector.rb (modified) (1 diff)
- trunk/activesupport/lib/active_support/json/encoders/date_time.rb (modified) (1 diff)
- trunk/activesupport/lib/active_support/json/encoders/date.rb (modified) (1 diff)
- trunk/activesupport/lib/active_support/json/encoders/enumerable.rb (modified) (1 diff)
- trunk/activesupport/lib/active_support/json/encoders/hash.rb (modified) (2 diffs)
- trunk/activesupport/lib/active_support/json/encoders/object.rb (modified) (1 diff)
- trunk/activesupport/lib/active_support/json/encoders/time.rb (modified) (1 diff)
- trunk/activesupport/lib/active_support/whiny_nil.rb (modified) (2 diffs)
- trunk/railties/CHANGELOG (modified) (1 diff)
- trunk/railties/configs/routes.rb (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/actionpack/CHANGELOG
r9088 r9093 1 1 *SVN* 2 3 * Improve documentation. [Radar, Jan De Poorter, chuyeow, xaviershay, danger, miloops, Xavier Noria, Sunny Ripert] 2 4 3 5 * Fixed that FormHelper#radio_button would produce invalid ids #11298 [harlancrystal] trunk/actionpack/lib/action_controller/resources.rb
r8982 r9093 227 227 # 228 228 # <% 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. 229 236 # 230 237 # The #resources method accepts the following options to customize the resulting routes: trunk/actionpack/lib/action_view/helpers/atom_feed_helper.rb
r9044 r9093 50 50 # * <tt>:schema_date</tt>: The date at which the tag scheme for the feed was first used. A good default is the year you 51 51 # 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). 53 53 # 54 54 # Other namespaces can be added to the root element: trunk/actionpack/lib/action_view/helpers/form_helper.rb
r9088 r9093 77 77 # 78 78 # <% form_for :person, @person, :url => { :action => "update" } do |f| %> 79 # <%= f.error_messages %> 79 80 # First name: <%= f.text_field :first_name %> 80 81 # Last name : <%= f.text_field :last_name %> … … 86 87 # 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 87 88 # 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. 89 91 # 90 92 # Even further, the form_for method allows you to more easily escape the instance variable convention. So while the stand-alone … … 406 408 # # Let's say that @post.validated? is 1: 407 409 # 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" /> 409 411 # # <input name="post[validated]" type="hidden" value="0" /> 410 412 # … … 414 416 # # <input name="puppy[gooddog]" type="hidden" value="no" /> 415 417 # 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" /> 418 420 # # <input name="eula[accepted]" type="hidden" value="no" /> 419 421 # … … 431 433 # radio_button("post", "category", "rails") 432 434 # 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" /> 435 437 # 436 438 # radio_button("user", "receive_newsletter", "yes") 437 439 # 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" /> 440 442 def radio_button(object_name, method, tag_value, options = {}) 441 443 InstanceTag.new(object_name, method, self, nil, options.delete(:object)).to_radio_button_tag(tag_value, options) trunk/activerecord/CHANGELOG
r9090 r9093 1 1 *SVN* 2 3 * Improve documentation. [Radar, Jan De Poorter, chuyeow, xaviershay, danger, miloops, Xavier Noria, Sunny Ripert] 2 4 3 5 * 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 177 177 # mix ERb in with your YAML or CSV fixtures to create a bunch of fixtures for load testing, like: 178 178 # 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 %> 184 184 # 185 185 # This will create 1000 very simple YAML fixtures. trunk/activerecord/lib/active_record/migration.rb
r8481 r9093 92 92 # The Rails package has several tools to help create and apply migrations. 93 93 # 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 # 95 97 # 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> 97 99 # directory where <tt>nnn</tt> is the next largest migration number. 100 # 98 101 # You may then edit the <tt>self.up</tt> and <tt>self.down</tt> methods of 99 102 # MyNewMigration. 100 103 # 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 # 101 118 # To run migrations against the currently configured database, use 102 119 # <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 9 9 # konata = User.find(1) 10 10 # 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} 14 13 # 15 14 # The :only and :except options can be used to limit the attributes … … 17 16 # 18 17 # konata.to_json(:only => [ :id, :name ]) 19 # 20 # {"id": 1, "name": "Konata Izumi"} 18 # # => {"id": 1, "name": "Konata Izumi"} 21 19 # 22 20 # konata.to_json(:except => [ :id, :created_at, :age ]) 23 # 24 # {"name": "Konata Izumi", "awesome": true} 21 # # => {"name": "Konata Izumi", "awesome": true} 25 22 # 26 23 # To include any methods on the model, use :methods. 27 24 # 28 25 # 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"} 33 29 # 34 30 # To include associations, use :include. 35 31 # 36 32 # 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"}]} 42 37 # 43 38 # 2nd level and higher order associations work as well: … … 47 42 # :only => :body } }, 48 43 # :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"}]} 56 50 def to_json(options = {}) 57 51 JsonSerializer.new(self, options).to_s trunk/activerecord/lib/active_record/serializers/xml_serializer.rb
r8258 r9093 1 1 module ActiveRecord #:nodoc: 2 2 module Serialization 3 # Builds an XML document to represent the model. Some configuration is4 # available through +options+ , however more complicated cases should5 # 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. 6 6 # 7 7 # 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: 9 9 # 10 10 # <?xml version="1.0" encoding="UTF-8"?> … … 24 24 # 25 25 # This behavior can be controlled with :only, :except, 26 # :skip_instruct, :skip_types and :dasherize. The :only and26 # :skip_instruct, :skip_types and :dasherize. The :only and 27 27 # :except options are the same as for the #attributes method. 28 28 # The default is to dasherize all column names, to disable this, 29 # set :dasherize to false. To not have the column type included29 # set :dasherize to false. To not have the column type included 30 30 # in the XML output, set :skip_types to true. 31 31 # … … 69 69 # </firm> 70 70 # 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 # 71 101 # To include any methods on the object(s) being called use :methods 72 102 # … … 79 109 # </firm> 80 110 # 81 # To call any Proc 's on the object(s) use :procs. The Proc's111 # To call any Procs on the object(s) use :procs. The Procs 82 112 # are passed a modified version of the options hash that was 83 113 # given to #to_xml. … … 91 121 # </firm> 92 122 # 93 # Alternatively, you can also justyield 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: 94 124 # 95 125 # firm.to_xml do |xml| … … 109 139 # 110 140 # You can override the to_xml method in your ActiveRecord::Base 111 # subclasses if you need to. The general form of doing this is141 # subclasses if you need to. The general form of doing this is: 112 142 # 113 143 # class IHaveMyOwnXML < ActiveRecord::Base … … 156 186 end 157 187 158 159 # To replicate the behavior in ActiveRecord#attributes,160 # :except takes precedence over :only. If :only is not set161 # 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 second163 # level model can have both :except and :only set. So if164 # :only is set, always delete :except.165 188 def serializable_attributes 166 189 serializable_attribute_names.collect { |name| Attribute.new(name, @record) } … … 252 275 # There is a significant speed improvement if the value 253 276 # does not need to be escaped, as #tag! escapes all values 254 # to ensure that valid XML is generated. For known binary277 # to ensure that valid XML is generated. For known binary 255 278 # values, it is at least an order of magnitude faster to 256 279 # Base64 encode binary values and directly put them in the trunk/activerecord/lib/active_record/timestamp.rb
r8217 r9093 6 6 # <tt>ActiveRecord::Base.record_timestamps = false</tt> 7 7 # 8 # Timestamps are in the local timezone by default but can use UTC by setting8 # Timestamps are in the local timezone by default but you can use UTC by setting 9 9 # <tt>ActiveRecord::Base.default_timezone = :utc</tt> 10 10 module Timestamp trunk/activeresource/CHANGELOG
r8827 r9093 1 1 *SVN* 2 3 * Improve documentation. [Radar, Jan De Poorter, chuyeow, xaviershay, danger, miloops, Xavier Noria, Sunny Ripert] 2 4 3 5 * Use HEAD instead of GET in exists? [bscofield] trunk/activesupport/CHANGELOG
r9081 r9093 1 1 *SVN* 2 3 * Improve documentation. [Radar, Jan De Poorter, chuyeow, xaviershay, danger, miloops, Xavier Noria, Sunny Ripert] 2 4 3 5 * 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. 4 9 module ActiveSupport 5 10 if RUBY_VERSION >= '1.9' trunk/activesupport/lib/active_support/core_ext/array/conversions.rb
r8384 r9093 25 25 end 26 26 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. 28 29 def to_param 29 30 map(&:to_param).join '/' … … 33 34 # param name. 34 35 # 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" 37 39 def to_query(key) 38 40 collect { |value| value.to_query("#{key}[]") } * '&' … … 46 48 end 47 49 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" 48 59 def to_formatted_s(format = :default) 49 60 case format … … 59 70 end 60 71 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 # 61 114 def to_xml(options = {}) 62 115 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 9 9 # <tt>false</tt>. 10 10 # 11 # E .g.11 # Examples: 12 12 # 13 13 # %w(1 2 3 4 5 6 7).in_groups_of(3) {|g| p g} … … 46 46 # or the result of an optional block. 47 47 # 48 # ex.48 # Examples: 49 49 # 50 50 # [1, 2, 3, 4, 5].split(3) # => [[1, 2], [4, 5]] trunk/activesupport/lib/active_support/core_ext/blank.rb
r8137 r9093 1 1 class 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. 3 3 # For example, "", " ", nil, [], and {} are blank. 4 4 # trunk/activesupport/lib/active_support/core_ext/class/removal.rb
r7474 r9093 1 1 class 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 2 8 def remove_subclasses 3 9 Object.remove_subclasses_of(self) 4 10 end 5 11 12 # Returns a list of classes that inherit from this class in an array. 13 # Example: Integer.subclasses => ["Bignum", "Fixnum"] 6 14 def subclasses 7 15 Object.subclasses_of(self).map { |o| o.to_s } 8 16 end 9 17 18 # Allows you to remove individual subclasses or a selection of subclasses from a class without removing all of them. 10 19 def remove_class(*klasses) 11 20 klasses.flatten.each do |klass| trunk/activesupport/lib/active_support/core_ext/date/calculations.rb
r8934 r9093 17 17 18 18 module ClassMethods 19 # Finds yesterday's date, in the format similar to: Mon, 17 Mar 2008 19 20 def yesterday 20 21 ::Date.today.yesterday 21 22 end 22 23 24 # Finds tommorrow's date, in the format similar to: Tue, 18 Mar 2008 23 25 def tomorrow 24 26 ::Date.today.tomorrow trunk/activesupport/lib/active_support/core_ext/enumerable.rb
r8700 r9093 3 3 # for example, for grouping records by date. 4 4 # 5 # e.g.5 # Example: 6 6 # 7 7 # latest_transcripts.group_by(&:day).each do |day, transcripts| … … 24 24 # Calculates a sum from the elements. Examples: 25 25 # 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) 28 28 # 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 } 30 32 # 31 33 # Also calculates sums without the use of a block: 34 # 32 35 # [5, 15, 10].sum # => 30 33 36 # … … 35 38 # However, you can override this default: 36 39 # 37 # [].sum(Payment.new(0)) { |i| i.amount } # => Payment.new(0)40 # [].sum(Payment.new(0)) { |i| i.amount } # => Payment.new(0) 38 41 # 39 42 def sum(identity = 0, &block) trunk/activesupport/lib/active_support/core_ext/file.rb
r6262 r9093 4 4 # want other processes or threads to see half-written files. 5 5 # 6 # File.atomic_write("important.file") do |file|7 # file.write("hello")8 # end6 # File.atomic_write("important.file") do |file| 7 # file.write("hello") 8 # end 9 9 # 10 10 # If your temp directory is not on the same filesystem as the file you're 11 11 # trying to write, you can provide a different temporary directory. 12 12 # 13 # File.atomic_write("/data/something.imporant", "/data/tmp") do |f|14 # file.write("hello")15 # end13 # File.atomic_write("/data/something.important", "/data/tmp") do |f| 14 # file.write("hello") 15 # end 16 16 def File.atomic_write(file_name, temp_dir = Dir.tmpdir) 17 17 temp_file = Tempfile.new(File.basename(file_name), temp_dir) trunk/activesupport/lib/active_support/core_ext/hash/indifferent_access.rb
r8332 r9093 1 1 # This class has dubious semantics and we only have it so that 2 2 # people can write params[:key] instead of params['key'] 3 # and they get the same value for both keys. 3 4 4 5 class HashWithIndifferentAccess < Hash … … 23 24 alias_method :regular_update, :update unless method_defined?(:regular_update) 24 25 26 # 27 # Assigns a new value to the hash. 28 # 29 # Example: 30 # 31 # hash = HashWithIndifferentAccess.new 32 # hash[:key] = "value" 33 # 25 34 def []=(key, value) 26 35 regular_writer(convert_key(key), convert_value(value)) 27 36 end 28 37 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 # 29 58 def update(other_hash) 30 59 other_hash.each_pair { |key, value| regular_writer(convert_key(key), convert_value(value)) } … … 34 63 alias_method :merge!, :update 35 64 65 # Checks the hash for a key matching the argument passed in 36 66 def key?(key) 37 67 super(convert_key(key)) … … 42 72 alias_method :member?, :key? 43 73 74 # Fetches the value for the specified key, same as doing hash[key] 44 75 def fetch(key, *extras) 45 76 super(convert_key(key), *extras) 46 77 end 47 78 79 # Returns an array of the values at the specified indicies. 48 80 def values_at(*indices) 49 81 indices.collect {|key| self[convert_key(key)]} 50 82 end 51 83 84 # Returns an exact copy of the hash. 52 85 def dup 53 86 HashWithIndifferentAccess.new(self) 54 87 end 55 88 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. 56 91 def merge(hash) 57 92 self.dup.update(hash) 58 93 end 59 94 95 # Removes a specified key from the hash. 60 96 def delete(key) 61 97 super(convert_key(key)) trunk/activesupport/lib/active_support/core_ext/hash/reverse_merge.rb
r5725 r9093 11 11 # The default :size and :velocity is only set if the +options+ passed in doesn't already have those keys set. 12 12 module ReverseMerge 13 # Performs the opposite of merge, with the keys and values from the first hash taking precedence over the second. 13 14 def reverse_merge(other_hash) 14 15 other_hash.merge(self) 15 16 end 16 17 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. 17 20 def reverse_merge!(other_hash) 18 21 replace(reverse_merge(other_hash)) trunk/activesupport/lib/active_support/core_ext/integer/even_odd.rb
r8397 r9093 2 2 module CoreExtensions #:nodoc: 3 3 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 9 12 module EvenOdd 10 13 def multiple_of?(number) trunk/activesupport/lib/active_support/core_ext/integer/inflections.rb
r5924 r9093 8 8 # position in an ordered sequence such as 1st, 2nd, 3rd, 4th. 9 9 # 10 # Examples 10 # Examples: 11 # 11 12 # 1.ordinalize # => "1st" 12 13 # 2.ordinalize # => "2nd" trunk/activesupport/lib/active_support/core_ext/kernel/reporting.rb
r3761 r9093 43 43 end 44 44 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" 45 53 def suppress(*exception_classes) 46 54 begin yield trunk/activesupport/lib/active_support/core_ext/module/attr_internal.rb
r4839 r9093 14 14 end 15 15 16 # Declare attributes backed by 'internal' instance variables names. 16 # Declare an attribute reader and writer backed by an internally-named instance 17 # variable. 17 18 def attr_internal_accessor(*attrs) 18 19 attr_internal_reader(*attrs) trunk/activesupport/lib/active_support/core_ext/module/inclusion.rb
r3519 r9093 1 1 class 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 # 2 21 def included_in_classes 3 22 classes = [] trunk/activesupport/lib/active_support/core_ext/module/introspection.rb
r8555 r9093 1 1 class 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 # 4 18 def parent 5 19 parent_name = name.split('::')[0..-2] * '::' … … 7 21 end 8 22 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 # 11 36 def parents 12 37 parents = [] … … 21 46 22 47 if RUBY_VERSION < '1.9' 23 # Return the constants that have been defined locally by this object and48 # Returns the constants that have been defined locally by this object and 24 49 # not in an ancestor. This method is exact if running under Ruby 1.9. In 25 50 # previous versions it may miss some constants if their definition in some trunk/activesupport/lib/active_support/core_ext/module/loading.rb
r4060 r9093 1 1 class 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" 2 12 def as_load_path 3 13 if self == Object || self == Kernel trunk/activesupport/lib/active_support/core_ext/object/instance_variables.rb
r8499 r9093 7 7 end 8 8 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} 9 19 def instance_values #:nodoc: 10 20 instance_variables.inject({}) do |values, name| … … 14 24 end 15 25 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"] 16 36 def instance_variable_names 17 37 instance_variables.map(&:to_s) 18 38 end 19 39 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 20 64 def copy_instance_variables_from(object, exclude = []) #:nodoc: 21 65 exclude += object.protected_instance_variables if object.respond_to? :protected_instance_variables trunk/activesupport/lib/active_support/core_ext/range/conversions.rb
r8397 r9093 14 14 end 15 15 end 16 16 # Gives a human readable format of the range. 17 # 18 # Example: 19 # 20 # >> [1..100].to_formatted_s 21 # => "1..100" 17 22 def to_formatted_s(format = :default) 18 23 RANGE_FORMATS[format] ? RANGE_FORMATS[format].call(first, last) : to_default_s trunk/activesupport/lib/active_support/core_ext/string/inflections.rb
r8596 r9093 6 6 # String inflections define new methods on the String class to transform names for different purposes. 7 7 # 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" 9 10 module Inflections 10 11 # Returns the plural form of the word in the string. 11 12 # 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" 19 19 def pluralize 20 20 Inflector.pluralize(self) 21 21 end 22 22 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. 24 24 # 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" 32 31 def singularize 33 32 Inflector.singularize(self) 34 33 end 35 34 36 # By default, camelizeconverts strings to UpperCamelCase. If the argument to camelize37 # 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. 38 37 # 39 # camelize will also convert '/' to '::' which is useful for converting paths to namespaces38 # +camelize+ will also convert '/' to '::' which is useful for converting paths to namespaces. 40 39 # 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" 46 44 def camelize(first_letter = :upper) 47 45 case first_letter … … 53 51 54 52 # Capitalizes all the words and replaces some characters in the string to create 55 # a nicer looking title. Titleizeis meant for creating pretty output. It is not53 # a nicer looking title. +titleize+ is meant for creating pretty output. It is not 56 54 # used in the Rails internals. 57 55 # 58 # titleize is also aliased as as titlecase56 # +titleize+ is also aliased as +titlecase+. 59 57 # 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" 63 60 def titleize 64 61 Inflector.titleize(self) … … 66 63 alias_method :titlecase, :titleize 67 64 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. 69 66 # 70 # Changes'::' to '/' to convert namespaces to paths.67 # +underscore+ will also change '::' to '/' to convert namespaces to paths. 71 68 # 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 75 71 def underscore 76 72 Inflector.underscore(self) … … 79 75 # Replaces underscores with dashes in the string. 80 76 # 81 # Example 82 # "puni_puni" #=> "puni-puni" 77 # "puni_puni" # => "puni-puni" 83 78 def dasherize 84 79 Inflector.dasherize(self) 85 80 end 86 81 87 # Removes the module part from the expression in the string82 # Removes the module part from the constant expression in the string. 88 83 # 89 # Examples 90 # "ActiveRecord::CoreExtensions::String::Inflections".demodulize #=> "Inflections" 91 # "Inflections".demodulize #=> "Inflections" 84 # "ActiveRecord::CoreExtensions::String::Inflections".demodulize # => "Inflections" 85 # "Inflections".demodulize # => "Inflections" 92 86 def demodulize 93 87 Inflector.demodulize(self) 94 88 end 95 89 96 # Create the name of a table like Rails does for models to table names. This method97 # uses the pluralizemethod 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. 98 92 # 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" 103 96 def tableize 104 97 Inflector.tableize(self) … … 106 99 107 100 # 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 class109 # 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+.) 110 103 # 111 # Examples 112 # "egg_and_hams".classify #=> "EggAndHam" 113 # "posts".classify #=> "Post" 104 # "egg_and_hams".classify # => "EggAndHam" 105 # "posts".classify # => "Post" 114 106 # 115 # Singular names are not handled correctly 116 # "business".classify #=> "Busines" 107 # Singular names are not handled correctly. 108 # 109 # "business".classify # => "Busines" 117 110 def classify 118 111 Inflector.classify(self) 119 112 end 120 113 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. 123 116 # 124 # Examples 125 # "employee_salary" #=> "Employee salary" 126 # "author_id" #=> "Author" 117 # "employee_salary" # => "Employee salary" 118 # "author_id" # => "Author" 127 119 def humanize 128 120 Inflector.humanize(self) … … 134 126 # 135 127 # 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" 139 131 def foreign_key(separate_class_name_and_id_with_underscore = true) 140 132 Inflector.foreign_key(self, separate_class_name_and_id_with_underscore) 141 133 end 142 134 143 # Constantizetries to find a declared constant with the name specified135 # +constantize+ tries to find a declared constant with the name specified 144 136 # in the string. It raises a NameError when the name is not in CamelCase 145 137 # or is not initialized. 146 138 # 147 139 # Examples 148 # "Module".constantize # => Module149 # "Class".constantize #=> Class140 # "Module".constantize # => Module 141 # "Class".constantize # => Class 150 142 def constantize 151 143 Inflector.constantize(self) trunk/activesupport/lib/active_support/core_ext/string/unicode.rb
r8460 r9093 28 28 # 29 29 # 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. 31 31 def chars 32 32 ActiveSupport::Multibyte::Chars.new(self) trunk/activesupport/lib/active_support/core_ext/time/zones.rb
r9047 r9093 44 44 end 45 45 46 # Returns the simultaneous time in Time.zone. Example:46 # Returns the simultaneous time in Time.zone. 47 47 # 48 # Time.zone = 'Hawaii' # => 'Hawaii'49 # Time.utc(2000).in_time_zone # => Fri, 31 Dec 1999 14:00:00 HST -10:0048 # Time.zone = 'Hawaii' # => 'Hawaii' 49 # Time.utc(2000).in_time_zone # => Fri, 31 Dec 1999 14:00:00 HST -10:00 50 50 # 51 51 # This method is similar to Time#localtime, except that it uses Time.zone as the local zone … … 53 53 # 54 54 # 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. 56 56 # 57 # Time.utc(2000).in_time_zone('Alaska') # => Fri, 31 Dec 1999 15:00:00 AKST -09:0057 # Time.utc(2000).in_time_zone('Alaska') # => Fri, 31 Dec 1999 15:00:00 AKST -09:00 58 58 def in_time_zone(zone = ::Time.zone) 59 59 ActiveSupport::TimeWithZone.new(utc? ? self : getutc, ::Time.send!(:get_zone, zone)) trunk/activesupport/lib/active_support/gzip.rb
r8546 r9093 3 3 4 4 module ActiveSupport 5 # A convenient wrapper for the zlib standard library that allows compression/decompression of strings with gzip. 5 6 module Gzip 6 7 class Stream < StringIO … … 8 9 end 9 10 11 # Decompresses a gzipped string. 10 12 def self.decompress(source) 11 13 Zlib::GzipReader.new(StringIO.new(source)).read 12 14 end 13 15 16 # Compresses a string using gzip. 14 17 def self.compress(source) 15 18 output = Stream.new trunk/activesupport/lib/active_support/inflector.rb
r8788 r9093 166 166 end 167 167 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. 169 169 # 170 170 # Changes '::' to '/' to convert namespaces to paths. trunk/activesupport/lib/active_support/json/encoders/date_time.rb
r7746 r9093 1 1 class 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) 3 8 %("#{strftime("%Y/%m/%d %H:%M:%S %z")}") 4 9 end trunk/activesupport/lib/active_support/json/encoders/date.rb
r7746 r9093 1 1 class 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) 3 8 %("#{strftime("%Y/%m/%d")}") 4 9 end trunk/activesupport/lib/active_support/json/encoders/enumerable.rb
r8010 r9093 3 3 # given will be passed on to its elements. For example: 4 4 # 5 # users = User.find(:all)6 # users.to_json(:only => :name)5 # users = User.find(:all) 6 # # => users.to_json(:only => :name) 7 7 # 8 8 # will pass the <tt>:only => :name</tt> option to each user. trunk/activesupport/lib/active_support/json/encoders/hash.rb
r8010 r9093 6 6 # 7 7 # { :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} 10 9 # 11 10 # The keys in the JSON string are unordered due to the nature of hashes. … … 15 14 # 16 15 # { :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} 19 17 # 20 18 # { :name => "Konata Izumi", 'age' => 16, 1 => 2 }.to_json(:except => 1) 21 # 22 # {"name": "Konata Izumi", "age": 16} 19 # # => {"name": "Konata Izumi", "age": 16} 23 20 # 24 21 # The +options+ also filter down to any hash values. This is particularly trunk/activesupport/lib/active_support/json/encoders/object.rb
r7736 r9093 1 1 class 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. 3 3 def to_json(options = {}) 4 4 ActiveSupport::JSON.encode(instance_values, options) trunk/activesupport/lib/active_support/json/encoders/time.rb
r8698 r9093 1 1 class 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) 3 8 %("#{strftime("%Y/%m/%d %H:%M:%S")} #{formatted_offset(false)}") 4 9 end trunk/activesupport/lib/active_support/whiny_nil.rb
r6818 r9093 19 19 end 20 20 21 # Raises a RuntimeError when you attempt to call id on nil or a nil object. 21 22 def id 22 23 raise RuntimeError, "Called id for nil, which would mistakenly be 4 -- if you really wanted the id of nil, use object_id", caller … … 28 29 end 29 30 31 # Raises a NoMethodError when you attempt to call a method on nil, or a nil object. 30 32 def raise_nil_warning_for(class_name = nil, selector = nil, with_caller = nil) 31 33 message = "You have a nil object when you didn't expect it!" trunk/railties/CHANGELOG
r9076 r9093 1 1 *SVN* 2 3 * Improve documentation. [Radar, Jan De Poorter, chuyeow, xaviershay, danger, miloops, Xavier Noria, Sunny Ripert] 2 4 3 5 * Added config.time_zone = 'UTC' as a commented-out option in the default environment.rb [Geoff Buesing] trunk/railties/configs/routes.rb
r7517 r9093 18 18 # Sample resource route with sub-resources: 19 19 # 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 20 26 21 27 # Sample resource route within a namespace: