Skip to content

Instantly share code, notes, and snippets.

@halfdan
Created April 4, 2010 09:14
Show Gist options
  • Save halfdan/355265 to your computer and use it in GitHub Desktop.
Save halfdan/355265 to your computer and use it in GitHub Desktop.
class VHost
attr_accessor :hostname
attr_accessor :file
attr_accessor :changed
attr_accessor :config
attr_accessor :id
@changed=false
def initialize(config,hostname,id=0)
# Initially there is no change
@changed=false
@hostname=hostname
@config=config
@id=id
@traffic=0
end
...
end
class RVLogger
def initialize(config, database=nil)
@config=config
@dbconn=database unless database.nil?
@vhosts={}
end
...
def find(hostname)
return @vhosts[hostname] if @vhosts[hostname]
# Add vhost to DB if active
if @config.params['general']['use_db']
domains = @dbconn[:vhosts].filter(:name => hostname)
unless domains.count > 0
domains.insert(:name => hostname)
end
row = domains[:name=>hostname]
id = row[:id]
@vhosts[hostname]=VHost.new(@config, hostname, id)
else
@vhosts[hostname]=VHost.new(@config, hostname)
end
end
def update_db
@vhosts.each do |vhost|
if vhost.changed
# Update DB
vhost.update_db @dbconn
vhost.changed=false
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment