Changeset 9226
- Timestamp:
- 04/05/08 03:52:58 (8 months ago)
- Files:
-
- trunk/actionpack/CHANGELOG (modified) (1 diff)
- trunk/actionpack/lib/action_controller/routing.rb (modified) (2 diffs)
- trunk/actionpack/lib/action_view/helpers/prototype_helper.rb (modified) (3 diffs)
- trunk/actionpack/lib/action_view/helpers/url_helper.rb (modified) (1 diff)
- trunk/activerecord/CHANGELOG (modified) (1 diff)
- trunk/activerecord/lib/active_record/associations.rb (modified) (2 diffs)
- trunk/activerecord/lib/active_record/associations/association_proxy.rb (modified) (1 diff)
- trunk/activerecord/lib/active_record/base.rb (modified) (2 diffs)
- trunk/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb (modified) (1 diff)
- trunk/activerecord/lib/active_record/reflection.rb (modified) (1 diff)
- trunk/activerecord/lib/active_record/transactions.rb (modified) (1 diff)
- trunk/activerecord/lib/active_record/validations.rb (modified) (2 diffs)
- trunk/activerecord/README (modified) (1 diff)
- trunk/activeresource/CHANGELOG (modified) (1 diff)
- trunk/activesupport/lib/active_support/core_ext/array/access.rb (modified) (2 diffs)
- trunk/activesupport/lib/active_support/core_ext/array/conversions.rb (modified) (2 diffs)
- trunk/activesupport/lib/active_support/core_ext/array/extract_options.rb (modified) (1 diff)
- trunk/activesupport/lib/active_support/core_ext/array/grouping.rb (modified) (2 diffs)
- trunk/activesupport/lib/active_support/core_ext/array/random_access.rb (modified) (1 diff)
- 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_time/conversions.rb (modified) (1 diff)
- trunk/activesupport/lib/active_support/core_ext/date/calculations.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/object/instance_variables.rb (modified) (1 diff)
- trunk/activesupport/lib/active_support/core_ext/string/unicode.rb (modified) (1 diff)
- trunk/activesupport/lib/active_support/core_ext/time/conversions.rb (modified) (5 diffs)
- trunk/activesupport/lib/active_support/core_ext/time/zones.rb (modified) (1 diff)
- trunk/activesupport/lib/active_support/whiny_nil.rb (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/actionpack/CHANGELOG
r9212 r9226 1 1 *SVN* 2 3 * Improve documentation. [Xavier Noria, leethal, jerome] 2 4 3 5 * Ensure RJS redirect_to doesn't html-escapes string argument. Closes #8546 [josh, eventualbuddha, Pratik] trunk/actionpack/lib/action_controller/routing.rb
r9115 r9226 48 48 # :action maps to an action with your controllers 49 49 # 50 # Other names simply map to a parameter as in the case of +:id+.50 # Other names simply map to a parameter as in the case of <tt>:id</tt>. 51 51 # 52 52 # == Route priority … … 83 83 # This means visiting '/' would invoke the blog controller. 84 84 # 85 # More formally, you can define defaults in a route with the +:defaults+key.85 # More formally, you can define defaults in a route with the <tt>:defaults</tt> key. 86 86 # 87 87 # map.connect ':controller/:action/:id', :action => 'show', :defaults => { :page => 'Dashboard' } trunk/actionpack/lib/action_view/helpers/prototype_helper.rb
r9212 r9226 717 717 # # element with ID 'content'. 718 718 # # Generates: new Insertion.Before("content", "-- Contents of 'navigation' partial --"); 719 # insert_html :before, 'content', :partial => 'navigation'719 # page.insert_html :before, 'content', :partial => 'navigation' 720 720 # 721 721 # # Add a list item to the bottom of the <ul> with ID 'list'. 722 722 # # Generates: new Insertion.Bottom("list", "<li>Last item</li>"); 723 # insert_html :bottom, 'list', '<li>Last item</li>'723 # page.insert_html :bottom, 'list', '<li>Last item</li>' 724 724 # 725 725 def insert_html(position, id, *options_for_render) … … 736 736 # # 'person' partial for the appropriate object. 737 737 # # Generates: Element.update("person-45", "-- Contents of 'person' partial --"); 738 # replace_html 'person-45', :partial => 'person', :object => @person738 # page.replace_html 'person-45', :partial => 'person', :object => @person 739 739 # 740 740 def replace_html(id, *options_for_render) … … 750 750 # # Replace the DOM element having ID 'person-45' with the 751 751 # # 'person' partial for the appropriate object. 752 # replace 'person-45', :partial => 'person', :object => @person752 # page.replace 'person-45', :partial => 'person', :object => @person 753 753 # 754 754 # This allows the same partial that is used for the +insert_html+ to trunk/actionpack/lib/action_view/helpers/url_helper.rb
r9034 r9226 87 87 # url_for. It's also possible to pass a string instead 88 88 # of an options hash to get a link tag that uses the value of the string as the 89 # href for the link, or use +:back+to link to the referrer - a JavaScript back89 # href for the link, or use <tt>:back</tt> to link to the referrer - a JavaScript back 90 90 # link will be used in place of a referrer if none exists. If nil is passed as 91 91 # a name, the link itself will become the name. trunk/activerecord/CHANGELOG
r9202 r9226 1 1 *SVN* 2 3 * Improve documentation. [Xavier Noria, Jack Danger Canty, leethal] 2 4 3 5 * Tweak ActiveRecord::Base#to_json to include a root value in the returned hash: {"post": {"title": ...}} [rick] trunk/activerecord/lib/active_record/associations.rb
r9095 r9226 137 137 # #others.size | X | X | X 138 138 # #others.length | X | X | X 139 # #others.count | | X | X139 # #others.count | X | X | X 140 140 # #others.sum(args*,&block) | X | X | X 141 141 # #others.empty? | X | X | X … … 151 151 # == Cardinality and associations 152 152 # 153 # ActiveRecord associations can be used to describe relations with one-to-one, one-to-many154 # and many-to-many cardinality. Each model uses an association to describe its role in155 # the relation. In each case, the +belongs_to+ association is used in the model that has153 # ActiveRecord associations can be used to describe one-to-one, one-to-many and many-to-many 154 # relationships between models. Each model uses an association to describe its role in 155 # the relation. The +belongs_to+ association is always used in the model that has 156 156 # the foreign key. 157 157 # trunk/activerecord/lib/active_record/associations/association_proxy.rb
r9084 r9226 1 1 module ActiveRecord 2 2 module Associations 3 # This is the root class of all association proxies: 4 # 5 # AssociationProxy 6 # BelongsToAssociation 7 # HasOneAssociation 8 # BelongsToPolymorphicAssociation 9 # AssociationCollection 10 # HasManyAssociation 11 # HasAndBelongsToManyAssociation 12 # HasManyThroughAssociation 13 # HasOneThroughAssociation 14 # 15 # Association proxies in Active Record are middlemen between the object that 16 # holds the association, known as the <tt>@owner</tt>, and the actual associated 17 # object, known as the <tt>@target</tt>. The kind of association any proxy is 18 # about is available in <tt>@reflection</tt>. That's an instance of the class 19 # ActiveRecord::Reflection::AssociationReflection. 20 # 21 # For example, given 22 # 23 # class Blog < ActiveRecord::Base 24 # has_many :posts 25 # end 26 # 27 # blog = Blog.find(:first) 28 # 29 # the association proxy in <tt>blog.posts</tt> has the object in +blog+ as 30 # <tt>@owner</tt>, the collection of its posts as <tt>@target</tt>, and 31 # the <tt>@reflection</tt> object represents a <tt>:has_many</tt> macro. 32 # 33 # This class has most of the basic instance methods removed, and delegates 34 # unknown methods to <tt>@target</tt> via <tt>method_missing</tt>. As a 35 # corner case, it even removes the +class+ method and that's why you get 36 # 37 # blog.posts.class # => Array 38 # 39 # though the object behind <tt>blog.posts</tt> is not an Array, but an 40 # ActiveRecord::Associations::HasManyAssociation. 41 # 42 # The <tt>@target</tt> object is not loaded until needed. For example, 43 # 44 # blog.posts.count 45 # 46 # is computed directly through SQL and does not trigger by itself the 47 # instantiation of the actual post records. 3 48 class AssociationProxy #:nodoc: 4 49 alias_method :proxy_respond_to?, :respond_to? trunk/activerecord/lib/active_record/base.rb
r9157 r9226 191 191 # 192 192 # Student.find(:all, :conditions => { :grade => 9..12 }) 193 # 194 # An array may be used in the hash to use the SQL IN operator: 195 # 196 # Student.find(:all, :conditions => { :grade => [9,11,12] }) 193 197 # 194 198 # == Overwriting default accessors … … 489 493 # Person.find(:all) # returns an array of objects for all the rows fetched by SELECT * FROM people 490 494 # Person.find(:all, :conditions => [ "category IN (?)", categories], :limit => 50) 495 # Person.find(:all, :conditions => { :friends => ["Bob", "Steve", "Fred"] } 491 496 # Person.find(:all, :offset => 10, :limit => 10) 492 497 # Person.find(:all, :include => [ :account, :friends ]) trunk/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb
r9122 r9226 162 162 # 163 163 # The index will be named after the table and the first column name, 164 # unless you pass +:name+as an option.164 # unless you pass <tt>:name</tt> as an option. 165 165 # 166 166 # When creating an index on multiple columns, the first column is used as a name 167 167 # for the index. For example, when you specify an index on two columns 168 # [ +:first+, +:last+], the DBMS creates an index for both columns as well as an169 # index for the first column +:first+. Using just the first name for this index168 # [<tt>:first</tt>, <tt>:last</tt>], the DBMS creates an index for both columns as well as an 169 # index for the first column <tt>:first</tt>. Using just the first name for this index 170 170 # makes sense, because you will never have to create a singular index with this 171 171 # name. trunk/activerecord/lib/active_record/reflection.rb
r8571 r9226 77 77 end 78 78 79 # Returns the name of the macro , so it would return :balance for "composed_of :balance, :class_name => 'Money'" or80 # :clients for "has_many :clients".79 # Returns the name of the macro. For example, <tt>composed_of :balance, :class_name => 'Money'</tt> will return 80 # <tt>:balance</tt> or for <tt>has_many :clients</tt> it will return <tt>:clients</tt>. 81 81 def name 82 82 @name 83 83 end 84 84 85 # Returns the type of the macro, so it would return :composed_of for86 # "composed_of :balance, :class_name => 'Money'" or :has_many for "has_many :clients".85 # Returns the macro type. For example, <tt>composed_of :balance, :class_name => 'Money'</tt> will return <tt>:composed_of</tt> 86 # or for <tt>has_many :clients</tt> will return <tt>:has_many</tt>. 87 87 def macro 88 88 @macro 89 89 end 90 90 91 # Returns the hash of options used for the macro, so it would return { :class_name => "Money" } for 92 # "composed_of :balance, :class_name => 'Money'" or {} for "has_many :clients". 91 # Returns the hash of options used for the macro. For example, it would return <tt>{ :class_name => "Money" }</tt> for 92 # <tt>composed_of :balance, :class_name => 'Money'</tt> or +{}+ for <tt>has_many :clients</tt>. 93 93 94 def options 94 95 @options 95 96 end 96 97 97 # Returns the class for the macro , so "composed_of :balance, :class_name => 'Money'" returns the Money class and98 # "has_many :clients" returns the Clientclass.98 # Returns the class for the macro. For example, <tt>composed_of :balance, :class_name => 'Money'</tt> returns the +Money+ 99 # class and <tt>has_many :clients</tt> returns the +Client+ class. 99 100 def klass 100 101 @klass ||= class_name.constantize 101 102 end 102 103 104 # Returns the class name for the macro. For example, <tt>composed_of :balance, :class_name => 'Money'</tt> returns <tt>'Money'</tt> 105 # and <tt>has_many :clients</tt> returns <tt>'Client'</tt>. 103 106 def class_name 104 107 @class_name ||= options[:class_name] || derive_class_name 105 108 end 106 109 110 # Returns +true+ if +self+ and +other_aggregation+ have the same +name+ attribute, +active_record+ attribute, 111 # and +other_aggregation+ has an options hash assigned to it. 107 112 def ==(other_aggregation) 108 113 name == other_aggregation.name && other_aggregation.options && active_record == other_aggregation.active_record trunk/activerecord/lib/active_record/transactions.rb
r8484 r9226 29 29 # This example will only take money from David and give to Mary if neither +withdrawal+ nor +deposit+ raises an exception. 30 30 # Exceptions will force a ROLLBACK that returns the database to the state before the transaction was begun. Be aware, though, 31 # that the objects by defaultwill _not_ have their instance data returned to their pre-transactional state.31 # that the objects will _not_ have their instance data returned to their pre-transactional state. 32 32 # 33 33 # == Different ActiveRecord classes in a single transaction trunk/activerecord/lib/active_record/validations.rb
r9168 r9226 724 724 # Configuration options: 725 725 # * <tt>in</tt> - An enumerable object of available items 726 # * <tt>message</tt> - Specifies a custom ererror message (default is: "is not included in the list")726 # * <tt>message</tt> - Specifies a custom error message (default is: "is not included in the list") 727 727 # * <tt>allow_nil</tt> - If set to true, skips this validation if the attribute is null (default is: false) 728 728 # * <tt>allow_blank</tt> - If set to true, skips this validation if the attribute is blank (default is: false) … … 756 756 # Configuration options: 757 757 # * <tt>in</tt> - An enumerable object of items that the value shouldn't be part of 758 # * <tt>message</tt> - Specifies a custom ererror message (default is: "is reserved")758 # * <tt>message</tt> - Specifies a custom error message (default is: "is reserved") 759 759 # * <tt>allow_nil</tt> - If set to true, skips this validation if the attribute is null (default is: false) 760 760 # * <tt>allow_blank</tt> - If set to true, skips this validation if the attribute is blank (default is: false) trunk/activerecord/README
r8371 r9226 103 103 104 104 105 * Transaction support on both a database and object level. The latter is implemented 106 by using Transaction::Simple[http://railsmanual.com/module/Transaction::Simple] 107 108 # Just database transaction 105 * Transactions 106 107 # Database transaction 109 108 Account.transaction do 110 david.withdrawal(100)111 mary.deposit(100)112 end113 114 # Database and object transaction115 Account.transaction(david, mary) do116 109 david.withdrawal(100) 117 110 mary.deposit(100) trunk/activeresource/CHANGELOG
r9114 r9226 1 1 *SVN* 2 3 * Improve documentation. [Xavier Noria] 2 4 3 5 * Fixed that to_param should be used and honored instead of hardcoding the id #11406 [gspiers] trunk/activesupport/lib/active_support/core_ext/array/access.rb
r8224 r9226 4 4 # Makes it easier to access parts of an array. 5 5 module Access 6 # Returns the remaining of the array from the+position+.6 # Returns the tail of the array from +position+. 7 7 # 8 # Examples:9 8 # %w( a b c d ).from(0) # => %w( a b c d ) 10 9 # %w( a b c d ).from(2) # => %w( c d ) … … 14 13 end 15 14 16 # Returns the beginning of the array up to the+position+.15 # Returns the beginning of the array up to +position+. 17 16 # 18 # Examples:19 17 # %w( a b c d ).to(0) # => %w( a ) 20 18 # %w( a b c d ).to(2) # => %w( a b c ) trunk/activesupport/lib/active_support/core_ext/array/conversions.rb
r9093 r9226 31 31 end 32 32 33 # Converts an array into a string suitable for use as a URL query string, using the given <tt>key</tt> as the 34 # param name. 35 # 36 # Example: 33 # Converts an array into a string suitable for use as a URL query string, 34 # using the given +key+ as the param name. 37 35 # 38 36 # ['Rails', 'coding'].to_query('hobbies') # => "hobbies%5B%5D=Rails&hobbies%5B%5D=coding" … … 81 79 # 82 80 # Root children have as node name the one of the root singularized. 83 #84 # Example:85 81 # 86 82 # [{:foo => 1, :bar => 2}, {:baz => 3}].to_xml trunk/activesupport/lib/active_support/core_ext/array/extract_options.rb
r7217 r9226 3 3 module Array #:nodoc: 4 4 module ExtractOptions 5 # Extract options from a set of arguments. Removes and returns the last element in the array if it's a hash, otherwise returns a blank hash. 5 # Extracts options from a set of arguments. Removes and returns the last 6 # element in the array if it's a hash, otherwise returns a blank hash. 6 7 # 7 8 # def options(*args) trunk/activesupport/lib/active_support/core_ext/array/grouping.rb
r9093 r9226 5 5 module Array #:nodoc: 6 6 module Grouping 7 # Iterate over an array in groups of a certain size, padding any remaining 8 # slots with specified value (<tt>nil</tt> by default) unless it is 9 # <tt>false</tt>. 10 # 11 # Examples: 7 # Iterates over the array in groups of size +number+, padding any remaining 8 # slots with +fill_with+ unless it is +false+. 12 9 # 13 10 # %w(1 2 3 4 5 6 7).in_groups_of(3) {|g| p g} … … 43 40 end 44 41 45 # Divide the array into one or more subarrays based on a delimiting +value+42 # Divides the array into one or more subarrays based on a delimiting +value+ 46 43 # or the result of an optional block. 47 #48 # Examples:49 44 # 50 45 # [1, 2, 3, 4, 5].split(3) # => [[1, 2], [4, 5]] trunk/activesupport/lib/active_support/core_ext/array/random_access.rb
r7490 r9226 3 3 module Array #:nodoc: 4 4 module RandomAccess 5 # Return a random element from the array.5 # Returns a random element from the array. 6 6 def rand 7 7 self[Kernel.rand(length)] trunk/activesupport/lib/active_support/core_ext/blank.rb
r9093 r9226 1 1 class Object 2 2 # An object is blank if it's false, empty, or a whitespace string. 3 # For example, "", " ", nil, [], and {} are blank.3 # For example, "", " ", +nil+, [], and {} are blank. 4 4 # 5 5 # This simplifies 6 # 6 7 # if !address.nil? && !address.empty? 8 # 7 9 # to 10 # 8 11 # if !address.blank? 9 12 def blank? trunk/activesupport/lib/active_support/core_ext/class/removal.rb
r9093 r9226 1 1 class Class #:nodoc: 2 2 3 # Will unassociate the class with its subclasses as well as uninitializing the subclasses themselves.4 # >> Integer.remove_subclasses5 # => [Bignum, Fixnum]6 # >> Fixnum7 # NameError: uninitialized constant Fixnum3 # Unassociates the class with its subclasses and removes the subclasses 4 # themselves. 5 # 6 # Integer.remove_subclasses # => [Bignum, Fixnum] 7 # Fixnum # => NameError: uninitialized constant Fixnum 8 8 def remove_subclasses 9 9 Object.remove_subclasses_of(self) 10 10 end 11 11 12 # Returns a list of classes that inherit from this class in an array. 13 # Example: Integer.subclasses => ["Bignum", "Fixnum"] 12 # Returns an array with the names of the subclasses of +self+ as strings. 13 # 14 # Integer.subclasses # => ["Bignum", "Fixnum"] 14 15 def subclasses 15 16 Object.subclasses_of(self).map { |o| o.to_s } 16 17 end 17 18 18 # Allows you to remove individual subclasses or a selection of subclasses from a class without removing all of them. 19 # Removes the classes in +klasses+ from their parent module. 20 # 21 # Ordinary classes belong to some module via a constant. This method computes 22 # that constant name from the class name and removes it from the module it 23 # belongs to. 24 # 25 # Object.remove_class(Integer) # => [Integer] 26 # Integer # => NameError: uninitialized constant Integer 27 # 28 # Take into account that in general the class object could be still stored 29 # somewhere else. 30 # 31 # i = Integer # => Integer 32 # Object.remove_class(Integer) # => [Integer] 33 # Integer # => NameError: uninitialized constant Integer 34 # i.subclasses # => ["Bignum", "Fixnum"] 35 # Fixnum.superclass # => Integer 19 36 def remove_class(*klasses) 20 37 klasses.flatten.each do |klass| trunk/activesupport/lib/active_support/core_ext/date_time/conversions.rb
r9161 r9226 46 46 end 47 47 48 # Returns the utc_offsetas an +HH:MM formatted string. Examples:48 # Returns the +utc_offset+ as an +HH:MM formatted string. Examples: 49 49 # 50 50 # datetime = DateTime.civil(2000, 1, 1, 0, 0, 0, Rational(-6, 24)) trunk/activesupport/lib/active_support/core_ext/date/calculations.rb
r9093 r9226 17 17 18 18 module ClassMethods 19 # Finds yesterday's date, in the format similar to: Mon, 17 Mar 200819 # Returns a new Date representing the date 1 day ago (i.e. yesterday's date). 20 20 def yesterday 21 21 ::Date.today.yesterday 22 22 end 23 23 24 # Finds tommorrow's date, in the format similar to: Tue, 18 Mar 200824 # Returns a new Date representing the date 1 day after today (i.e. tomorrow's date). 25 25 def tomorrow 26 26 ::Date.today.tomorrow trunk/activesupport/lib/active_support/core_ext/integer/even_odd.rb
r9093 r9226 4 4 # For checking if a fixnum is even or odd. 5 5 # 6 # Examples:7 #8 6 # 1.even? # => false 9 7 # 1.odd? # => true 10 8 # 2.even? # => true 11 # 2.odd? # => false9 # 2.odd? # => false 12 10 module EvenOdd 13 11 def multiple_of?(number) trunk/activesupport/lib/active_support/core_ext/integer/inflections.rb
r9093 r9226 7 7 # Ordinalize turns a number into an ordinal string used to denote the 8 8 # position in an ordered sequence such as 1st, 2nd, 3rd, 4th. 9 #10 # Examples:11 9 # 12 10 # 1.ordinalize # => "1st" trunk/activesupport/lib/active_support/core_ext/object/instance_variables.rb
r9093 r9226 38 38 end 39 39 40 # Copies the instance variables of +object+ into self.40 # Copies the instance variables of +object+ into +self+. 41 41 # 42 42 # Instance variable names in the +exclude+ array are ignored. If +object+ trunk/activesupport/lib/active_support/core_ext/string/unicode.rb
r9093 r9226 11 11 # 12 12 # name = 'Claus MÃŒller' 13 # name.reverse #=> "rell??M sualC"14 # name.length #=> 1313 # name.reverse #=> "rell??M sualC" 14 # name.length #=> 13 15 15 # 16 # name.chars.reverse.to_s #=> "rellÃŒM sualC"17 # name.chars.length #=> 1216 # name.chars.reverse.to_s #=> "rellÃŒM sualC" 17 # name.chars.length #=> 12 18 18 # 19 19 # trunk/activesupport/lib/active_support/core_ext/time/conversions.rb
r8699 r9226 21 21 end 22 22 23 # Convert to a formatted string. See DATE_FORMATS for builtin formats.23 # Converts to a formatted string. See DATE_FORMATS for builtin formats. 24 24 # 25 25 # This method is aliased to <tt>to_s</tt>. 26 26 # 27 # ==== Examples:28 27 # time = Time.now # => Thu Jan 18 06:10:17 CST 2007 29 28 # … … 37 36 # time.to_formatted_s(:rfc822) # => "Thu, 18 Jan 2007 06:10:17 -0600" 38 37 # 39 # == Adding your own time formats to to_formatted_s38 # == Adding your own time formats to +to_formatted_s+ 40 39 # You can add your own formats to the Time::DATE_FORMATS hash. 41 40 # Use the format name as the hash key and either a strftime string … … 50 49 end 51 50 52 # Returns the utc_offset as an +HH:MM formatted string. Examples:51 # Returns the UTC offset as an +HH:MM formatted string. 53 52 # 54 53 # Time.local(2000).formatted_offset # => "-06:00" … … 58 57 end 59 58 60 # Convert a Time object to a Date, dropping hour, minute, and second precision.59 # Converts a Time object to a Date, dropping hour, minute, and second precision. 61 60 # 62 # ==== Examples 63 # my_time = Time.now 64 # # => Mon Nov 12 22:59:51 -0500 2007 61 # my_time = Time.now # => Mon Nov 12 22:59:51 -0500 2007 62 # my_time.to_date #=> Mon, 12 Nov 2007 65 63 # 66 # my_time.to_date 67 # #=> Mon, 12 Nov 2007 68 # 69 # your_time = Time.parse("1/13/2009 1:13:03 P.M.") 70 # # => Tue Jan 13 13:13:03 -0500 2009 71 # 72 # your_time.to_date 73 # # => Tue, 13 Jan 2009 64 # your_time = Time.parse("1/13/2009 1:13:03 P.M.") # => Tue Jan 13 13:13:03 -0500 2009 65 # your_time.to_date # => Tue, 13 Jan 2009 74 66 def to_date 75 67 ::Date.new(year, month, day) … … 84 76 # Converts a Time instance to a Ruby DateTime instance, preserving UTC offset. 85 77 # 86 # ==== Examples 87 # my_time = Time.now 88 # # => Mon Nov 12 23:04:21 -0500 2007 78 # my_time = Time.now # => Mon Nov 12 23:04:21 -0500 2007 79 # my_time.to_datetime # => Mon, 12 Nov 2007 23:04:21 -0500 89 80 # 90 # my_time.to_datetime 91 # # => Mon, 12 Nov 2007 23:04:21 -0500 92 # 93 # your_time = Time.parse("1/13/2009 1:13:03 P.M.") 94 # # => Tue Jan 13 13:13:03 -0500 2009 95 # 96 # your_time.to_datetime 97 # # => Tue, 13 Jan 2009 13:13:03 -0500 81 # your_time = Time.parse("1/13/2009 1:13:03 P.M.") # => Tue Jan 13 13:13:03 -0500 2009 82 # your_time.to_datetime # => Tue, 13 Jan 2009 13:13:03 -0500 98 83 def to_datetime 99 84 ::DateTime.civil(year, month, day, hour, min, sec, Rational(utc_offset, 86400)) trunk/activesupport/lib/active_support/core_ext/time/zones.rb
r9107 r9226 18 18 # Sets a global default time zone, separate from the system time zone in ENV['TZ']. 19 19 # Accepts either a Rails TimeZone object, a string that identifies a 20 # Rails TimeZone object (e.g., "Central Time (US & Canada)"), or a TZInfo::Timezone object 20 # Rails TimeZone object (e.g., "Central Time (US & Canada)"), or a TZInfo::Timezone object. 21 21 # 22 # Any Time or DateTime object can use this default time zone, via #in_time_zone. 23 # Example: 22 # Any Time or DateTime object can use this default time zone, via <tt>in_time_zone</tt>. 24 23 # 25 24 # Time.zone = 'Hawaii' # => 'Hawaii' trunk/activesupport/lib/active_support/whiny_nil.rb
r9093 r9226 1 # Extensions to nil which allow for more helpful error messages for2 # people who are new to rails.1 # Extensions to +nil+ which allow for more helpful error messages for people who 2 # are new to Rails. 3 3 # 4 # The aim is to ensure that when users pass nil to methods where that isn't 5 # appropriate, instead of NoMethodError and the name of some method used 6 # by the framework users will see a message explaining what type of object 7 # was expected. 8 4 # Ruby raises NoMethodError if you invoke a method on an object that does not 5 # respond to it: 6 # 7 # $ ruby -e nil.destroy 8 # -e:1: undefined method `destroy' for nil:NilClass (NoMethodError) 9 # 10 # With these extensions, if the method belongs to the public interface of the 11 # classes in NilClass::WHINERS the error message suggests which could be the 12 # actual intended class: 13 # 14 # $ script/runner nil.destroy 15 # ... 16 # You might have expected an instance of ActiveRecord::Base. 17 # ... 18 # 19 # NilClass#id exists in Ruby 1.8 (though it is deprecated). Since +id+ is a fundamental 20 # method of Active Record models NilClass#id is redefined as well to raise a RuntimeError 21 # and warn the user. She probably wanted a model database identifier and the 4 22 # returned by the original method could result in obscure bugs. 23 # 24 # The flag <tt>config.whiny_nils</tt> determines whether this feature is enabled. 25 # By default it is on in development and test modes, and it is off in production 26 # mode. 9 27 class NilClass 10 28 WHINERS = [::Array] … … 19 37 end 20 38 21 # Raises a RuntimeError when you attempt to call id on nil or a nil object.39 # Raises a RuntimeError when you attempt to call +id+ on +nil+. 22 40 def id 23 41 raise RuntimeError, "Called id for nil, which would mistakenly be 4 -- if you really wanted the id of nil, use object_id", caller … … 29 47 end 30 48 31 # Raises a NoMethodError when you attempt to call a method on nil, or a nil object.49 # Raises a NoMethodError when you attempt to call a method on +nil+. 32 50 def raise_nil_warning_for(class_name = nil, selector = nil, with_caller = nil) 33 51 message = "You have a nil object when you didn't expect it!"