Created
March 5, 2013 18:45
-
-
Save romulostorel/5092975 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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