jam-cloud/ruby/lib/jam_ruby/models/icecast_server.rb

69 lines
3.7 KiB
Ruby

module JamRuby
class IcecastServer < ActiveRecord::Base
belongs_to :template, :class_name => "JamRuby::IcecastTemplate", foreign_key: 'template_id', :inverse_of => :servers
# all are overrides, because the template defines all of these as well. When building the XML, we will prefer these if set
belongs_to :limit, :class_name => "JamRuby::IcecastLimit", foreign_key: 'limit_id', :inverse_of => :servers
belongs_to :admin_auth, :class_name => "JamRuby::IcecastAdminAuthentication", foreign_key: 'admin_auth_id', :inverse_of => :servers
belongs_to :directory, :class_name => "JamRuby::IcecastDirectory", foreign_key: 'directory_id', :inverse_of => :servers
belongs_to :master_relay, :class_name => "JamRuby::IcecastMasterServerRelay", foreign_key: 'master_relay_id', :inverse_of => :servers
belongs_to :path, :class_name => "JamRuby::IcecastPath", foreign_key: 'path_id', :inverse_of => :servers
belongs_to :logging, :class_name => "JamRuby::IcecastLogging", foreign_key: 'logging_id', :inverse_of => :servers
belongs_to :security, :class_name => "JamRuby::IcecastSecurity", foreign_key: 'security_id', :inverse_of => :servers
has_and_belongs_to_many :listen_sockets, :class_name => "JamRuby::IcecastListenSocket", :join_table => "icecast_server_sockets"
# mounts and relays are naturally server-specific, though
has_and_belongs_to_many :mounts, :class_name => "JamRuby::IcecastMount", :join_table => "icecast_server_mounts"
has_and_belongs_to_many :relays, :class_name => "JamRuby::IcecastRelay", :join_table => "icecast_server_relays"
validates :config_changed, :inclusion => {:in => [true, false]}
validates :hostname, presence: true
validates :fileserve, :inclusion => {:in => [true, false]}, :if => lambda {|s| s.fileserve.present? }
validates :server_id, presence: true
validates :template, presence: true
def dumpXml (output=$stdout, indent=1)
builder = ::Builder::XmlMarkup.new(:target => output, :indent => indent)
builder.tag! 'icecast' do |icecast|
icecast.tag! 'hostname', hostname
icecast.tag! 'location', location.nil? ? template.location : location
icecast.tag! 'server-id', server_id
icecast.tag! 'admin', admin_email ? admin_email : template.admin_email
icecast.tag! 'fileserve', fileserve.nil? ? (template.fileserve ? 1 : 0) : (fileserve ? 1 : 0)
# do we have an override specified? or do we go with the template
current_limit = limit ? limit : template.limit
current_admin_auth = admin_auth ? admin_auth : template.admin_auth
current_directory = directory ? directory : template.directory
current_master_relay = master_relay ? master_relay : template.master_relay
current_path = path ? path : template.path
current_logging = logging ? logging : template.logging
current_security = security ? security : template.security
current_listen_sockets = listen_sockets.length > 0 ? listen_sockets : template.listen_sockets
current_limit.dumpXml(builder) unless current_limit.nil?
current_admin_auth.dumpXml(builder) unless current_admin_auth.nil?
current_directory.dumpXml(builder) unless current_directory.nil?
current_master_relay.dumpXml(builder) unless current_master_relay.nil?
current_path.dumpXml(builder) unless current_path.nil?
current_logging.dumpXml(builder) unless current_logging.nil?
current_security.dumpXml(builder) unless current_security.nil?
current_listen_sockets.each do |listen_socket|
listen_socket.dumpXml(builder)
end
relays.each do |relay|
relay.dumpXml(builder)
end
mounts.each do |mount|
mount.dumpXml(builder)
end
end
end
end
end