Aggiunge i tornei con hub, pagina pubblica e tabellone per semifinali e finali.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
module Tournaments
|
||||
class GenerateSlug
|
||||
def self.call(tournament)
|
||||
new(tournament).call
|
||||
end
|
||||
|
||||
def initialize(tournament)
|
||||
@tournament = tournament
|
||||
end
|
||||
|
||||
def call
|
||||
base = @tournament.name.to_s.parameterize.presence || "torneo"
|
||||
slug = base
|
||||
n = 2
|
||||
while conflict?(slug)
|
||||
slug = "#{base}-#{n}"
|
||||
n += 1
|
||||
end
|
||||
slug
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def conflict?(slug)
|
||||
scope = Tournament.where(slug: slug)
|
||||
scope = scope.where.not(id: @tournament.id) if @tournament.persisted?
|
||||
scope.exists?
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user