Skip to content

Instantly share code, notes, and snippets.

@romulostorel
Created March 5, 2013 18:45
Show Gist options
  • Save romulostorel/5092975 to your computer and use it in GitHub Desktop.
Save romulostorel/5092975 to your computer and use it in GitHub Desktop.
class SchoolStatusManager
def initialize(school)
@school = school
end
def set_status!
@school.update_attribute :status, school_status
end
private
def school_status
if @school.enrollment_begins_state?
SchoolState::ENROLLMENT_BEGINS
elsif @school.pre_enrollment_state?
SchoolState::PRE_ENROLLMENT
elsif @school.authorized_course_state?
SchoolState::AUTHORIZED_COURSE
end
end
end
def authorized_course_state?(school = self)
School.joins{ demands }.where{ demands.school_id.eq school.id }.any? && School.joins{ pre_enrollments }.where{ pre_enrollments.school_id.eq school.id }.empty?
end
def pre_enrollment_state?(school = self)
School.joins{ pre_enrollments }.where{ pre_enrollments.school_id.eq school.id }.any? && School.joins{ pre_enrollments.enrollment }.where{ pre_enrollments.school_id.eq school.id }.empty?
end
def enrollment_begins_state?(school = self)
School.joins{ pre_enrollments.enrollment }.where{ pre_enrollments.school_id.eq school.id }.any?
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment