Skip to content

Commit

Permalink
Formatting, grammar and spelling fixes for the associations documenta…
Browse files Browse the repository at this point in the history
…tion. [seanhussey] Closes #8899

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@7368 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information
NZKoz committed Aug 28, 2007
1 parent c11ca0e commit 18a3333
Show file tree
Hide file tree
Showing 8 changed files with 226 additions and 226 deletions.
22 changes: 11 additions & 11 deletions activerecord/lib/active_record/aggregations.rb
Expand Up @@ -70,7 +70,7 @@ def clear_aggregation_cache #:nodoc:
# end
#
# Now it's possible to access attributes from the database through the value objects instead. If you choose to name the
# composition the same as the attributes name, it will be the only way to access that attribute. That's the case with our
# composition the same as the attribute's name, it will be the only way to access that attribute. That's the case with our
# +balance+ attribute. You interact with the value objects just like you would any other attribute, though:
#
# customer.balance = Money.new(20) # sets the Money value object and the attribute
Expand All @@ -92,19 +92,19 @@ def clear_aggregation_cache #:nodoc:
#
# == Writing value objects
#
# Value objects are immutable and interchangeable objects that represent a given value, such as a Money object representing
# $5. Two Money objects both representing $5 should be equal (through methods such as == and <=> from Comparable if ranking
# makes sense). This is unlike entity objects where equality is determined by identity. An entity class such as Customer can
# Value objects are immutable and interchangeable objects that represent a given value, such as a +Money+ object representing
# $5. Two +Money+ objects both representing $5 should be equal (through methods such as == and <=> from +Comparable+ if ranking
# makes sense). This is unlike entity objects where equality is determined by identity. An entity class such as +Customer+ can
# easily have two different objects that both have an address on Hyancintvej. Entity identity is determined by object or
# relational unique identifiers (such as primary keys). Normal ActiveRecord::Base classes are entity objects.
# relational unique identifiers (such as primary keys). Normal <tt>ActiveRecord::Base</tt> classes are entity objects.
#
# It's also important to treat the value objects as immutable. Don't allow the Money object to have its amount changed after
# creation. Create a new money object with the new value instead. This is exemplified by the Money#exchanged_to method that
# It's also important to treat the value objects as immutable. Don't allow the +Money+ object to have its amount changed after
# creation. Create a new +Money+ object with the new value instead. This is exemplified by the <tt>Money#exchanged_to</tt> method that
# returns a new value object instead of changing its own values. Active Record won't persist value objects that have been
# changed through other means than the writer method.
# changed through means other than the writer method.
#
# The immutable requirement is enforced by Active Record by freezing any object assigned as a value object. Attempting to
# change it afterwards will result in a TypeError.
# change it afterwards will result in a <tt>TypeError</tt>.
#
# Read more about value objects on http://c2.com/cgi/wiki?ValueObject and on the dangers of not keeping value objects
# immutable on http://c2.com/cgi/wiki?ValueObjectsShouldBeImmutable
Expand All @@ -119,8 +119,8 @@ module ClassMethods
# * <tt>:mapping</tt> - specifies a number of mapping arrays (attribute, parameter) that bind an attribute name
# to a constructor parameter on the value class.
# * <tt>:allow_nil</tt> - specifies that the aggregate object will not be instantiated when all mapped
# attributes are nil. Setting the aggregate class to nil has the effect of writing nil to all mapped attributes.
# This defaults to false.
# attributes are +nil+. Setting the aggregate class to +nil+ has the effect of writing +nil+ to all mapped attributes.
# This defaults to +false+.
#
# Option examples:
# composed_of :temperature, :mapping => %w(reading celsius)
Expand Down
316 changes: 158 additions & 158 deletions activerecord/lib/active_record/associations.rb

Large diffs are not rendered by default.

Expand Up @@ -65,7 +65,7 @@ def delete(*records)

# Removes all records from this association. Returns +self+ so method calls may be chained.
def clear
return self if length.zero? # forces load_target if hasn't happened already
return self if length.zero? # forces load_target if it hasn't happened already

if @reflection.options[:dependent] && @reflection.options[:dependent] == :delete_all
destroy_all
Expand Down
Expand Up @@ -139,7 +139,7 @@ def load_target
end

# Can be overwritten by associations that might have the foreign key available for an association without
# having the object itself (and still being a new record). Currently, only belongs_to present this scenario.
# having the object itself (and still being a new record). Currently, only belongs_to presents this scenario.
def foreign_key_present
false
end
Expand Down
Expand Up @@ -14,7 +14,7 @@ def build(attributes = {})
end

def create(attributes = {})
# Can't use Base.create since the foreign key may be a protected attribute.
# Can't use Base.create because the foreign key may be a protected attribute.
if attributes.is_a?(Array)
attributes.collect { |attr| create(attr) }
else
Expand Down Expand Up @@ -138,8 +138,8 @@ def construct_scope
end

# Join tables with additional columns on top of the two foreign keys must be considered ambigious unless a select
# clause has been explicitly defined. Otherwise you can get broken records back, if, say, the join column also has
# and id column, which will then overwrite the id column of the records coming back.
# clause has been explicitly defined. Otherwise you can get broken records back, if, for example, the join column also has
# an id column. This will then overwrite the id column of the records coming back.
def finding_with_ambigious_select?(select_clause)
!select_clause && @owner.connection.columns(@reflection.options[:join_table], "Join Table Columns").size != 2
end
Expand Down
Expand Up @@ -67,7 +67,7 @@ def <<(*records)

[:push, :concat].each { |method| alias_method method, :<< }

# Remove +records+ from this association. Does not destroy +records+.
# Removes +records+ from this association. Does not destroy +records+.
def delete(*records)
records = flatten_deeper(records)
records.each { |associate| raise_on_type_mismatch(associate) }
Expand Down
Expand Up @@ -76,7 +76,7 @@ def construct_scope
end

def new_record(replace_existing)
# make sure we load the target first, if we plan on replacing the existing
# Make sure we load the target first, if we plan on replacing the existing
# instance. Otherwise, if the target has not previously been loaded
# elsewhere, the instance we create will get orphaned.
load_target if replace_existing
Expand Down
100 changes: 50 additions & 50 deletions activerecord/lib/active_record/callbacks.rb
@@ -1,25 +1,25 @@
require 'observer'

module ActiveRecord
# Callbacks are hooks into the lifecycle of an Active Record object that allows you to trigger logic
# Callbacks are hooks into the lifecycle of an Active Record object that allow you to trigger logic
# before or after an alteration of the object state. This can be used to make sure that associated and
# dependent objects are deleted when destroy is called (by overwriting before_destroy) or to massage attributes
# before they're validated (by overwriting before_validation). As an example of the callbacks initiated, consider
# the Base#save call:
#
# * (-) save
# * (-) valid?
# * (1) before_validation
# * (2) before_validation_on_create
# * (-) validate
# * (-) validate_on_create
# * (3) after_validation
# * (4) after_validation_on_create
# * (5) before_save
# * (6) before_create
# * (-) create
# * (7) after_create
# * (8) after_save
# dependent objects are deleted when destroy is called (by overwriting +before_destroy+) or to massage attributes
# before they're validated (by overwriting +before_validation+). As an example of the callbacks initiated, consider
# the <tt>Base#save</tt> call:
#
# * (-) <tt>save</tt>
# * (-) <tt>valid</tt>
# * (1) <tt>before_validation</tt>
# * (2) <tt>before_validation_on_create</tt>
# * (-) <tt>validate</tt>
# * (-) <tt>validate_on_create</tt>
# * (3) <tt>after_validation</tt>
# * (4) <tt>after_validation_on_create</tt>
# * (5) <tt>before_save</tt>
# * (6) <tt>before_create</tt>
# * (-) <tt>create</tt>
# * (7) <tt>after_create</tt>
# * (8) <tt>after_save</tt>
#
# That's a total of eight callbacks, which gives you immense power to react and prepare for each state in the
# Active Record lifecycle.
Expand Down Expand Up @@ -62,8 +62,8 @@ module ActiveRecord
# before_destroy :destroy_readers
# end
#
# Now, when Topic#destroy is run only +destroy_author+ is called. When Reply#destroy is run both +destroy_author+ and
# +destroy_readers+ is called. Contrast this to the situation where we've implemented the save behavior through overwriteable
# Now, when <tt>Topic#destroy</tt> is run only +destroy_author+ is called. When <tt>Reply#destroy</tt> is run, both +destroy_author+ and
# +destroy_readers+ are called. Contrast this to the situation where we've implemented the save behavior through overwriteable
# methods:
#
# class Topic < ActiveRecord::Base
Expand All @@ -74,9 +74,9 @@ module ActiveRecord
# def before_destroy() destroy_readers end
# end
#
# In that case, Reply#destroy would only run +destroy_readers+ and _not_ +destroy_author+. So use the callback macros when
# you want to ensure that a certain callback is called for the entire hierarchy and the regular overwriteable methods when you
# want to leave it up to each descendent to decide whether they want to call +super+ and trigger the inherited callbacks.
# In that case, <tt>Reply#destroy</tt> would only run +destroy_readers+ and _not_ +destroy_author+. So, use the callback macros when
# you want to ensure that a certain callback is called for the entire hierarchy, and use the regular overwriteable methods
# when you want to leave it up to each descendent to decide whether they want to call +super+ and trigger the inherited callbacks.
#
# *IMPORTANT:* In order for inheritance to work for the callback queues, you must specify the callbacks before specifying the
# associations. Otherwise, you might trigger the loading of a child before the parent has registered the callbacks and they won't
Expand Down Expand Up @@ -143,31 +143,31 @@ module ActiveRecord
# before_destroy 'self.class.delete_all "parent_id = #{id}"'
# end
#
# Notice that single plings (') are used so the #{id} part isn't evaluated until the callback is triggered. Also note that these
# Notice that single plings (') are used so the <tt>#{id}</tt> part isn't evaluated until the callback is triggered. Also note that these
# inline callbacks can be stacked just like the regular ones:
#
# class Topic < ActiveRecord::Base
# before_destroy 'self.class.delete_all "parent_id = #{id}"',
# 'puts "Evaluated after parents are destroyed"'
# end
#
# == The after_find and after_initialize exceptions
# == The +after_find+ and +after_initialize+ exceptions
#
# Because after_find and after_initialize are called for each object found and instantiated by a finder, such as Base.find(:all), we've had
# to implement a simple performance constraint (50% more speed on a simple test case). Unlike all the other callbacks, after_find and
# after_initialize will only be run if an explicit implementation is defined (<tt>def after_find</tt>). In that case, all of the
# Because +after_find+ and +after_initialize+ are called for each object found and instantiated by a finder, such as <tt>Base.find(:all)</tt>, we've had
# to implement a simple performance constraint (50% more speed on a simple test case). Unlike all the other callbacks, +after_find+ and
# +after_initialize+ will only be run if an explicit implementation is defined (<tt>def after_find</tt>). In that case, all of the
# callback types will be called.
#
# == before_validation* returning statements
# == <tt>before_validation*</tt> returning statements
#
# If the returning value of a before_validation callback can be evaluated to false, the process will be aborted and Base#save will return false.
# If Base#save! is called it will raise a RecordNotSave error.
# If the returning value of a +before_validation+ callback can be evaluated to +false+, the process will be aborted and <tt>Base#save</tt> will return +false+.
# If <tt>Base#save!</tt> is called it will raise a +RecordNotSave+ exception.
# Nothing will be appended to the errors object.
#
# == Cancelling callbacks
#
# If a before_* callback returns false, all the later callbacks and the associated action are cancelled. If an after_* callback returns
# false, all the later callbacks are cancelled. Callbacks are generally run in the order they are defined, with the exception of callbacks
# If a <tt>before_*</tt> callback returns +false+, all the later callbacks and the associated action are cancelled. If an <tt>after_*</tt> callback returns
# +false+, all the later callbacks are cancelled. Callbacks are generally run in the order they are defined, with the exception of callbacks
# defined as methods on the model, which are called last.
module Callbacks
CALLBACKS = %w(
Expand Down Expand Up @@ -215,10 +215,10 @@ def instantiate_with_callbacks(record)
end
end

# Is called when the object was instantiated by one of the finders, like Base.find.
# Is called when the object was instantiated by one of the finders, like <tt>Base.find</tt>.
#def after_find() end

# Is called after the object has been instantiated by a call to Base.new.
# Is called after the object has been instantiated by a call to <tt>Base.new</tt>.
#def after_initialize() end

def initialize_with_callbacks(attributes = nil) #:nodoc:
Expand All @@ -229,10 +229,10 @@ def initialize_with_callbacks(attributes = nil) #:nodoc:
end
private :initialize_with_callbacks

# Is called _before_ Base.save (regardless of whether it's a create or update save).
# Is called _before_ <tt>Base.save</tt> (regardless of whether it's a +create+ or +update+ save).
def before_save() end

# Is called _after_ Base.save (regardless of whether it's a create or update save).
# Is called _after_ <tt>Base.save</tt> (regardless of whether it's a +create+ or +update+ save).
#
# class Contact < ActiveRecord::Base
# after_save { logger.info( 'New contact saved!' ) }
Expand All @@ -246,10 +246,10 @@ def create_or_update_with_callbacks #:nodoc:
end
private :create_or_update_with_callbacks

# Is called _before_ Base.save on new objects that haven't been saved yet (no record exists).
# Is called _before_ <tt>Base.save</tt> on new objects that haven't been saved yet (no record exists).
def before_create() end

# Is called _after_ Base.save on new objects that haven't been saved yet (no record exists).
# Is called _after_ <tt>Base.save</tt> on new objects that haven't been saved yet (no record exists).
def after_create() end
def create_with_callbacks #:nodoc:
return false if callback(:before_create) == false
Expand All @@ -259,10 +259,10 @@ def create_with_callbacks #:nodoc:
end
private :create_with_callbacks

# Is called _before_ Base.save on existing objects that have a record.
# Is called _before_ <tt>Base.save</tt> on existing objects that have a record.
def before_update() end

# Is called _after_ Base.save on existing objects that have a record.
# Is called _after_ <tt>Base.save</tt> on existing objects that have a record.
def after_update() end

def update_with_callbacks #:nodoc:
Expand All @@ -273,25 +273,25 @@ def update_with_callbacks #:nodoc:
end
private :update_with_callbacks

# Is called _before_ Validations.validate (which is part of the Base.save call).
# Is called _before_ <tt>Validations.validate</tt> (which is part of the <tt>Base.save</tt> call).
def before_validation() end

# Is called _after_ Validations.validate (which is part of the Base.save call).
# Is called _after_ <tt>Validations.validate</tt> (which is part of the <tt>Base.save</tt> call).
def after_validation() end

# Is called _before_ Validations.validate (which is part of the Base.save call) on new objects
# Is called _before_ <tt>Validations.validate</tt> (which is part of the <tt>Base.save</tt> call) on new objects
# that haven't been saved yet (no record exists).
def before_validation_on_create() end

# Is called _after_ Validations.validate (which is part of the Base.save call) on new objects
# Is called _after_ <tt>Validations.validate</tt> (which is part of the <tt>Base.save</tt> call) on new objects
# that haven't been saved yet (no record exists).
def after_validation_on_create() end

# Is called _before_ Validations.validate (which is part of the Base.save call) on
# Is called _before_ <tt>Validations.validate</tt> (which is part of the <tt>Base.save</tt> call) on
# existing objects that have a record.
def before_validation_on_update() end

# Is called _after_ Validations.validate (which is part of the Base.save call) on
# Is called _after_ <tt>Validations.validate</tt> (which is part of the <tt>Base.save</tt> call) on
# existing objects that have a record.
def after_validation_on_update() end

Expand All @@ -308,13 +308,13 @@ def valid_with_callbacks? #:nodoc:
return result
end

# Is called _before_ Base.destroy.
# Is called _before_ <tt>Base.destroy</tt>.
#
# Note: If you need to _destroy_ or _nullify_ associated records first,
# use the _:dependent_ option on your associations.
# use the <tt>:dependent</tt> option on your associations.
def before_destroy() end

# Is called _after_ Base.destroy (and all the attributes have been frozen).
# Is called _after_ <tt>Base.destroy</tt> (and all the attributes have been frozen).
#
# class Contact < ActiveRecord::Base
# after_destroy { |record| logger.info( "Contact #{record.id} was destroyed." ) }
Expand Down

0 comments on commit 18a3333

Please sign in to comment.