diff options
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/tournament.rb | 21 | ||||
-rw-r--r-- | app/models/user.rb | 1 |
2 files changed, 20 insertions, 2 deletions
diff --git a/app/models/tournament.rb b/app/models/tournament.rb index 5e8ddfe..ca7fade 100644 --- a/app/models/tournament.rb +++ b/app/models/tournament.rb @@ -1,4 +1,21 @@ class Tournament < ActiveRecord::Base - belongs_to :game - has_many :matches + belongs_to :game + has_many :matches + 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 diff --git a/app/models/user.rb b/app/models/user.rb index 9288ef6..6405c8e 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1,4 +1,5 @@ class User < ActiveRecord::Base + has_many :tournaments, :through => :user_tournament_pair before_save { self.email = email.downcase } before_save { self.user_name = user_name } |