summaryrefslogtreecommitdiff
path: root/app/models/invite_code_validator.rb
blob: 978d3f5ef2f04002325173b97cdcd49b5c4affd1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
class InviteCodeValidator < ActiveModel::Validator
  def validate(user)
    if not_existent?(user.invite_code)
      add_error_to_user("This is not a valid code", user)
    end
  end

  private
  def not_existent?(code)
    InviteCode.find_by_invite_code(code) == nil
  end

  def add_error_to_user(error, user)
    user.errors[:invite_code] << error
  end
end