summaryrefslogtreecommitdiff
path: root/app/models/tournament.rb
diff options
context:
space:
mode:
authorLuke Shumaker <shumakl@purdue.edu>2014-04-26 20:39:49 -0400
committerLuke Shumaker <shumakl@purdue.edu>2014-04-26 20:39:49 -0400
commited4f3dad6cd92710bf9cbafc36cf87dae8605f73 (patch)
tree40483a266f439e6fce717d38e3acd1edd4bdbf12 /app/models/tournament.rb
parentdfbbe46fdcca392b3dec703cf347d1b1d57ca94f (diff)
add convenience methods for getting scoring/sampling/scheduling/seeding
Diffstat (limited to 'app/models/tournament.rb')
-rw-r--r--app/models/tournament.rb16
1 files changed, 16 insertions, 0 deletions
diff --git a/app/models/tournament.rb b/app/models/tournament.rb
index 7460a7d..61b4700 100644
--- a/app/models/tournament.rb
+++ b/app/models/tournament.rb
@@ -6,6 +6,8 @@ class Tournament < ActiveRecord::Base
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
@@ -57,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
@@ -77,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