Class: Effective::MentorshipCycle
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Effective::MentorshipCycle
- Defined in:
- app/models/effective/mentorship_cycle.rb
Class Method Summary collapse
-
.effective_mentorships_mentorship_cycle? ⇒ Boolean
before_destroy do if (count = mentorship_groups.length) > 0 raise(“#count groups belong to this cycle”) end end.
- .latest_cycle ⇒ Object
Instance Method Summary collapse
-
#duplicate ⇒ Object
Returns a duplicated event object, or throws an exception.
- #to_s ⇒ Object
Class Method Details
.effective_mentorships_mentorship_cycle? ⇒ Boolean
before_destroy do
if (count = mentorship_groups.length) > 0
raise("#{count} groups belong to this cycle")
end
end
53 54 55 |
# File 'app/models/effective/mentorship_cycle.rb', line 53 def self.effective_mentorships_mentorship_cycle? true end |
.latest_cycle ⇒ Object
57 58 59 |
# File 'app/models/effective/mentorship_cycle.rb', line 57 def self.latest_cycle order(id: :desc).first end |
Instance Method Details
#duplicate ⇒ Object
Returns a duplicated event object, or throws an exception
66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'app/models/effective/mentorship_cycle.rb', line 66 def duplicate MentorshipCycle.new(attributes.except('id', 'updated_at', 'created_at', 'token')).tap do |mentorship| mentorship.start_at = mentorship.start_at.advance(years: 1) if mentorship.start_at.present? mentorship.end_at = mentorship.end_at.advance(years: 1) if mentorship.end_at.present? mentorship.registration_start_at = mentorship.registration_start_at.advance(years: 1) if mentorship.registration_start_at.present? mentorship.registration_end_at = mentorship.registration_end_at.advance(years: 1) if mentorship.registration_end_at.present? mentorship.title = mentorship.title + ' (Copy)' mentorship.rich_texts.each { |rt| self.send("rich_text_#{rt.name}=", rt.body) } end end |
#to_s ⇒ Object
61 62 63 |
# File 'app/models/effective/mentorship_cycle.rb', line 61 def to_s title.presence || model_name.human end |