Sha256: 62b81d038baa0c4055b1b830fe7bd61c8692be892f4330c47d0cfe69330b0e7f
Contents?: true
Size: 1.77 KB
Versions: 13
Compression:
Stored size: 1.77 KB
Contents
module ThinkFeelDoDashboard module Concerns # addes necessary membership # associations and validations module Membership extend ActiveSupport::Concern # This is perfect for including functionality # provided by 3rd party gems, etc. included do attr_accessor :display_name before_validation :ensure_display_name_for_social_arms before_validation :only_one_active_group, on: :create validate :excludes_moderators end # methods added to Class itself... module ClassMethods end def active? (start_date.nil? || start_date <= Time.zone.today) && (end_date.nil? || end_date >= Time.zone.today) end private def ensure_display_name_for_social_arms if invalid_display_name? errors.add(:display_name, "is required because the arm of this intervention " \ "utilizes social features.") else name = display_name || participant.display_name participant.update_attributes(display_name: name) end end def excludes_moderators if active_group.try(:arm) && !active_group.arm.social? && participant.is_admin errors.add(:base, "moderators can't be part of this group.") end end def only_one_active_group if participant.active_membership && active? errors.add(:participant, "can't be assigned to this group because they are " \ "already active.") end end def invalid_display_name? participant.active_membership && active_group.try(:arm).try(:social?) && participant.display_name.blank? end end end end
Version data entries
13 entries across 13 versions & 1 rubygems