Skip to content

Commit

Permalink
ensuring that documentation does not exceed 100 columns
Browse files Browse the repository at this point in the history
  • Loading branch information
Neeraj Singh committed Aug 2, 2010
1 parent 6ac9482 commit b29c23a
Show file tree
Hide file tree
Showing 3 changed files with 282 additions and 194 deletions.
13 changes: 6 additions & 7 deletions activerecord/lib/active_record/aggregations.rb
Expand Up @@ -11,11 +11,11 @@ def clear_aggregation_cache #:nodoc:


# Active Record implements aggregation through a macro-like class method called +composed_of+ # Active Record implements aggregation through a macro-like class method called +composed_of+
# for representing attributes as value objects. It expresses relationships like "Account [is] # for representing attributes as value objects. It expresses relationships like "Account [is]
# composed of Money [among other things]" or "Person [is] # composed of Money [among other things]" or "Person [is] composed of [an] address". Each call
# composed of [an] address". Each call to the macro adds a description of how the value objects # to the macro adds a description of how the value objects are created from the attributes of
# are created from the attributes of the entity object (when the entity is initialized either # the entity object (when the entity is initialized either as a new object or from finding an
# as a new object or from finding an existing object) and how it can be turned back into attributes # existing object) and how it can be turned back into attributes (when the entity is saved to
# (when the entity is saved to the database). # the database).
# #
# class Customer < ActiveRecord::Base # class Customer < ActiveRecord::Base
# composed_of :balance, :class_name => "Money", :mapping => %w(balance amount) # composed_of :balance, :class_name => "Money", :mapping => %w(balance amount)
Expand Down Expand Up @@ -83,8 +83,7 @@ def clear_aggregation_cache #:nodoc:
# customer.balance < Money.new(5) # => false # customer.balance < Money.new(5) # => false
# #
# Value objects can also be composed of multiple attributes, such as the case of Address. The order # Value objects can also be composed of multiple attributes, such as the case of Address. The order
# of the mappings will # of the mappings will determine the order of the parameters.
# determine the order of the parameters.
# #
# customer.address_street = "Hyancintvej" # customer.address_street = "Hyancintvej"
# customer.address_city = "Copenhagen" # customer.address_city = "Copenhagen"
Expand Down
16 changes: 9 additions & 7 deletions activerecord/lib/active_record/association_preload.rb
Expand Up @@ -9,8 +9,8 @@ module AssociationPreload #:nodoc:
# Implements the details of eager loading of Active Record associations. # Implements the details of eager loading of Active Record associations.
# Application developers should not use this module directly. # Application developers should not use this module directly.
# #
# ActiveRecord::Base is extended with this module. The source code in # <tt>ActiveRecord::Base</tt> is extended with this module. The source code in
# ActiveRecord::Base references methods defined in this module. # <tt>ActiveRecord::Base</tt> references methods defined in this module.
# #
# Note that 'eager loading' and 'preloading' are actually the same thing. # Note that 'eager loading' and 'preloading' are actually the same thing.
# However, there are two different eager loading strategies. # However, there are two different eager loading strategies.
Expand Down Expand Up @@ -55,7 +55,7 @@ module ClassMethods
# == Parameters # == Parameters
# +records+ is an array of ActiveRecord::Base. This array needs not be flat, # +records+ is an array of ActiveRecord::Base. This array needs not be flat,
# i.e. +records+ itself may also contain arrays of records. In any case, # i.e. +records+ itself may also contain arrays of records. In any case,
# +preload_associations+ will preload the associations all records by # +preload_associations+ will preload the all associations records by
# flattening +records+. # flattening +records+.
# #
# +associations+ specifies one or more associations that you want to # +associations+ specifies one or more associations that you want to
Expand Down Expand Up @@ -110,8 +110,8 @@ def preload_associations(records, associations, preload_options={})
def preload_one_association(records, association, preload_options={}) def preload_one_association(records, association, preload_options={})
class_to_reflection = {} class_to_reflection = {}
# Not all records have the same class, so group then preload # Not all records have the same class, so group then preload
# group on the reflection itself so that if various subclass share the same association then we do not split them # group on the reflection itself so that if various subclass share the same association then
# unnecessarily # we do not split them unnecessarily
records.group_by { |record| class_to_reflection[record.class] ||= record.class.reflections[association]}.each do |reflection, _records| records.group_by { |record| class_to_reflection[record.class] ||= record.class.reflections[association]}.each do |reflection, _records|
raise ConfigurationError, "Association named '#{ association }' was not found; perhaps you misspelled it?" unless reflection raise ConfigurationError, "Association named '#{ association }' was not found; perhaps you misspelled it?" unless reflection


Expand Down Expand Up @@ -149,7 +149,8 @@ def set_association_single_records(id_to_record_map, reflection_name, associated
seen_keys = {} seen_keys = {}
associated_records.each do |associated_record| associated_records.each do |associated_record|
#this is a has_one or belongs_to: there should only be one record. #this is a has_one or belongs_to: there should only be one record.
#Unfortunately we can't (in portable way) ask the database for 'all records where foo_id in (x,y,z), but please #Unfortunately we can't (in portable way) ask the database for
#'all records where foo_id in (x,y,z), but please
# only one row per distinct foo_id' so this where we enforce that # only one row per distinct foo_id' so this where we enforce that
next if seen_keys[associated_record[key].to_s] next if seen_keys[associated_record[key].to_s]
seen_keys[associated_record[key].to_s] = true seen_keys[associated_record[key].to_s] = true
Expand Down Expand Up @@ -304,7 +305,8 @@ def preload_belongs_to_association(records, reflection, preload_options={})
polymorph_type = options[:foreign_type] polymorph_type = options[:foreign_type]
klasses_and_ids = {} klasses_and_ids = {}


# Construct a mapping from klass to a list of ids to load and a mapping of those ids back to their parent_records # Construct a mapping from klass to a list of ids to load and a mapping of those ids back
# to their parent_records
records.each do |record| records.each do |record|
if klass = record.send(polymorph_type) if klass = record.send(polymorph_type)
klass_id = record.send(primary_key_name) klass_id = record.send(primary_key_name)
Expand Down

0 comments on commit b29c23a

Please sign in to comment.