summaryrefslogtreecommitdiff
path: root/app/models/tournament.rb
diff options
context:
space:
mode:
authornfoy <nfoy@purdue.edu>2014-04-26 20:57:26 -0400
committernfoy <nfoy@purdue.edu>2014-04-26 20:57:26 -0400
commit31d458e59077340f28955033735f5c433197cb75 (patch)
tree8784a35b5d50f32ce693c0427b277f7238c6d691 /app/models/tournament.rb
parent00f3d70445d7cae0976ec9794e555c52a1765b24 (diff)
parentedcca83c6c251a79afcd83760cf20ebaf00b3b32 (diff)
Merge branch 'master' of https://github.com/LukeShu/leaguer
Diffstat (limited to 'app/models/tournament.rb')
-rw-r--r--app/models/tournament.rb17
1 files changed, 17 insertions, 0 deletions
diff --git a/app/models/tournament.rb b/app/models/tournament.rb
index 861be6c..61b4700 100644
--- a/app/models/tournament.rb
+++ b/app/models/tournament.rb
@@ -1,10 +1,13 @@
class Tournament < ActiveRecord::Base
belongs_to :game
has_many :stages, class_name: "TournamentStage"
+ has_many :brackets
has_many :settings_raw, class_name: "TournamentSetting"
has_and_belongs_to_many :players, class_name: "User", association_foreign_key: "player_id", join_table: "players_tournaments"
has_and_belongs_to_many :hosts, class_name: "User", association_foreign_key: "host_id", join_table: "hosts_tournaments"
+ # Settings #################################################################
+
def settings
@settings ||= Settings.new(self)
end
@@ -56,10 +59,14 @@ class Tournament < ActiveRecord::Base
end
end
+ # Misc. ####################################################################
+
def open?
return true
end
+ # Joining/Leaving ##########################################################
+
def joinable_by?(user)
return (open? and user.can?(:join_tournament) and !players.include?(user))
end
@@ -76,4 +83,14 @@ class Tournament < ActiveRecord::Base
players.delete(user)
end
end
+
+ # Configured methods #######################################################
+
+ def scoring
+ @scoring ||= "Scoring::#{self.scoring_method.camelcase}".constantize
+ end
+
+ def sampling
+ @sampling ||= "Sampling::#{self.sampling_method.camelcase}".constantize
+ end
end