class AcademicSubject
AcademicSubject:
Public Instance Methods
parents()
click to toggle source
Returns an Array of parents from furthest to closest.
dad.parent_subject = grandpa me.parent_subject = dad me.parents # => [grandpa, dad]
# File lib/buweb/academic_subject.rb, line 74 def parents if parent_subject.present? # Recursivly call this method. If parent doesn't have a parent, # it will return [] temp_parents = parent_subject.parents # prevent against cyclic relations if temp_parents.include? parent_subject temp_parents else temp_parents + [parent_subject] end else [] end end
Private Instance Methods
generate_path()
click to toggle source
Generates the path of this object in relation to its parents. This does not update children, or save.
biology_subject.generate_path # =>
"sciences/biological-physical-sciences/biology"
# File lib/buweb/academic_subject.rb, line 98 def generate_path self.path = (parents + [self]).map(&:slug).join('/') end
regenerate_child_paths()
click to toggle source
Loops through child paths and saves them, which triggers a call to `generate_path`. Also triggers a call to `regenerate_child_paths` on each child. Note: It only runs if the path was changed.
# File lib/buweb/academic_subject.rb, line 106 def regenerate_child_paths child_subjects.each(&:save) if changed_attributes['path'] end