summaryrefslogtreecommitdiff
path: root/app/models/tournament.rb
diff options
context:
space:
mode:
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