module JSONable def jdumpXml (ovb, nm, ident=1, output=$stdout) serialized = Hash.new ovb.myattr_accessor.each do |attribute| #serialized[attribute] = ovb[attribute] puts "attribute = #{attribute}" #serialized[attribute] = self.public_send attribute end hash = serialized tb = "\t" tbs = tb * ident tbse = tb * (ident-1) output.puts "#{tbse}<#{nm}>" hash.each do |key, val| #puts "attrib: key=#{key} val=#{val}" el = key if key.present? el = key.gsub(/_/, '-') end sv = val if val.to_s.empty? #skip ??? else if val.instance_of? String #encode the string to be xml safe sv = CGI.escapeHTML(val) end end output.puts "#{tbs}<#{el}>#{sv}" end puts "#{tbse}" end end module JamRuby class IcecastAdminAuthentication < ActiveRecord::Base include JSONable attr_accessible :source_password, :relay_user, :relay_password, :admin_user, :admin_password #myattr_accessor = [:source_password, :relay_user, :relay_password, :admin_user, :admin_password ] after_initialize :init protected def init #set only if nil self.source_password ||= "UndefinedSourcePassword" self.admin_password ||= "JKAminPw" end public self.primary_key = 'id' validates :source_password, presence: true, length: {minimum: 5} validates :admin_password, presence: true, length: {minimum: 5} def dumpXml (ident=1, output=$stdout) self.jdumpXml(self,"authentication", ident,output) end end end