Class Customer
In: app/models/customer.rb
Parent: TaskGroup
File:customer.rb
(C):Hipposoft 2008, 2009
Purpose:Describe the behaviour of Customer objects. See below for more details.

          24-Dec-2007 (ADH): Created.

Methods

Public Class methods

Apply a default sort to the given array of customer objects. The array is modified in place. Although this method is compatible with the default sort mechanism in the YUI tree view component, it‘s not called by that because the wider data set does not behave even remotely like acts_as_nested_set style collections, so bespoke controller and view code is used to generate arrays of objects.

[Source]

    # File app/models/customer.rb, line 58
58:   def self.apply_default_sort_order( array )
59:     array.sort! { | x, y | x.title.downcase <=> y.title.downcase }
60:   end

Public Instance methods

Assign default conditions for a brand new object, used whether or not the object ends up being saved in the database (so a before_create filter is not sufficient). For user-specific default values, pass a User object.

[Source]

    # File app/models/customer.rb, line 43
43:   def assign_defaults( user )
44:     self.active = true
45:     self.code   = "CID%04d" % Customer.count
46: 
47:     # Presently, there are no user-specific default values for
48:     # Customer objects.
49:   end

As update_with_side_effects!, but destroys things rather than updating them. Pass ‘true’ to destroy associated projects, else ‘false’. If omitted, defaults to ‘true’; pass also ‘true’ to destroy tasks associated with those projects, else ‘false’, with, again, the default being ‘true’.

[Source]

    # File app/models/customer.rb, line 90
90:   def destroy_with_side_effects( destroy_projects = true, destroy_tasks = true )
91:     if ( destroy_projects )
92:       self.projects.each do | project |
93:         project.destroy_with_side_effects( destroy_tasks )
94:       end
95:     end
96: 
97:     self.destroy()
98:   end

Update an object with the given attributes. This is done by a special model method because changes of the ‘active’ flag have side effects for other associated objects. THE CALLER *MUST* USE A TRANSACTION around a call to this method. There is no need to call here unless the ‘active’ flag state is changing. Pass in ‘true’ to update associated projects, else ‘false’ and ‘true’ to update associated tasks via those projects, else ‘false’. Booleans default to ‘true’ if omitted.

[Source]

    # File app/models/customer.rb, line 71
71:   def update_with_side_effects!( attrs, update_projects = true, update_tasks = true )
72:     active = self.active
73:     self.update_attributes!( attrs )
74: 
75:     # If the active flag has changed, deal with repercussions.
76: 
77:     if ( update_projects and attrs[ :active ] != active )
78:       self.projects.each do | project |
79:         project.update_with_side_effects!( { :active => attrs[ :active ] }, update_tasks )
80:       end
81:     end
82:   end

[Validate]