Module: MuckUsers::Models::MuckAccessCode
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/muck-users/models/access_code.rb
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary collapse
- #bulk_valid? ⇒ Boolean
- #expired? ⇒ Boolean
- #invalid? ⇒ Boolean
- #overused? ⇒ Boolean
- #send_requests ⇒ Object
- #send_requests=(sr) ⇒ Object
- #use_code ⇒ Object
Instance Method Details
#bulk_valid? ⇒ Boolean
50 51 52 53 54 55 |
# File 'lib/muck-users/models/access_code.rb', line 50 def bulk_valid? errors.add(:emails, I18n.translate('muck.users.validation_are_required')) if self.emails.blank? && !self.send_requests errors.add(:subject, I18n.translate('muck.users.validation_is_required')) if self.subject.blank? errors.add(:message, I18n.translate('muck.users.validation_is_required')) if self..blank? raise ActiveRecord::RecordInvalid.new(self) if !errors.empty? end |
#expired? ⇒ Boolean
69 70 71 |
# File 'lib/muck-users/models/access_code.rb', line 69 def expired? self.expires_at? && self.expires_at < Time.now end |
#invalid? ⇒ Boolean
61 62 63 |
# File 'lib/muck-users/models/access_code.rb', line 61 def invalid? expired? || overused? end |
#overused? ⇒ Boolean
65 66 67 |
# File 'lib/muck-users/models/access_code.rb', line 65 def overused? (self.uses >= self.use_limit) && !self.unlimited end |
#send_requests ⇒ Object
77 78 79 80 81 |
# File 'lib/muck-users/models/access_code.rb', line 77 def send_requests return false if @send_request == '0' return false if @send_request == 'false' return @send_request end |
#send_requests=(sr) ⇒ Object
73 74 75 |
# File 'lib/muck-users/models/access_code.rb', line 73 def send_requests=(sr) @send_request = sr end |
#use_code ⇒ Object
57 58 59 |
# File 'lib/muck-users/models/access_code.rb', line 57 def use_code self.update_attribute(:uses, self.uses + 1) end |