diff options
Diffstat (limited to 'app/models/tournament.rb')
-rw-r--r-- | app/models/tournament.rb | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/app/models/tournament.rb b/app/models/tournament.rb index cc915a0..afdd27e 100644 --- a/app/models/tournament.rb +++ b/app/models/tournament.rb @@ -1,3 +1,20 @@ class Tournament < ActiveRecord::Base - belongs_to :game + belongs_to :game + has_many :users, :through => :user_tournament_pair + + def open? + return true + end + + def joinable_by?(user) + return ((not user.nil?) and user.in_group?(:player) and open?) + end + + def join(user) + unless joinable?(user) + return false + end + pair = new_user_tournament_pair(user: user) + return pair.save + end end |