Changeset 9093
- Timestamp:
- 03/26/08 12:27:52 (2 months 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