Class | Project |
In: |
app/models/project.rb
|
Parent: | TaskGroup |
File: | project.rb |
(C): | Hipposoft 2008, 2009 |
Purpose: | Describe the behaviour of Project objects. See below for more details. |
24-Dec-2007 (ADH): Created.
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.
# File app/models/project.rb, line 50 50: def assign_defaults( user ) 51: self.active = true 52: self.code = "PID%04d" % Project.count 53: 54: # User-specific defaults - pick up the default customer 55: # from the user's control panel, if defined. 56: 57: if ( user and user.control_panel ) 58: cp = user.control_panel 59: self.customer = cp.customer if ( cp.customer and cp.customer.active ) 60: end 61: end
As update_with_side_effects!, but destroys things rather than updating them. Pass ‘true’ to destroy associated tasks, else ‘false’. If omitted, defaults to ‘true’.
# File app/models/project.rb, line 88 88: def destroy_with_side_effects( destroy_tasks = true ) 89: if ( destroy_tasks ) 90: self.tasks.each do | task | 91: task.destroy() 92: end 93: end 94: 95: self.destroy() 96: 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 tasks, else ‘false’. If omitted, defaults to ‘true’.
# File app/models/project.rb, line 71 71: def update_with_side_effects!( attrs, 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_tasks and attrs[ :active ] != active ) 78: self.tasks.each do | task | 79: task.update_with_side_effects!( { :active => attrs[ :active ] } ) 80: end 81: end 82: end