l4d.tools/app/models/server.rb
2026-01-18 17:42:32 +01:00

23 lines
593 B
Ruby

class Server < ApplicationRecord
belongs_to :user
belongs_to :server_template
enum :status, { stopped: 0, starting: 1, running: 2, failed: 3 }
validates :name, :port, presence: true
validates :name, uniqueness: { scope: :user_id }
validates :port, uniqueness: true
validates :status, presence: true
scope :for_user, ->(user) { where(user_id: user.id) }
scope :active, -> { where(status: [ :starting, :running ]) }
after_destroy :cleanup_server
private
def cleanup_server
L4dServer::SystemdManager.cleanup(self)
L4dServer::Launcher.cleanup(self)
end
end