class ConfigFileCollection
Public Class Methods
new(dir)
click to toggle source
Collect all the config files present within the given directory and return the object @param [String] dir The full path if the directory containing the config files.
# File lib/config_file_collection.rb, line 8 def initialize(dir) failValidation if not dir.is_a?(String) or not (File.exists?(dir) and File.directory?(dir)) @files = Array.new temp = Array.new # get all the subdirectories within the given folder temp = Dir.entries(dir).select{|x| File.directory?(File.join(dir, x)) and not (x =~ /\.\.?/)} # For each one, add the config file if it contains one temp.each do |folder| config_file = File.join(dir, folder, 'config.ini') @files.push(config_file) if File.exists?(config_file) end # if no config files were found, raise an errors raise if @files.count == 0 end
Public Instance Methods
archive(time)
click to toggle source
Scrubs and uploads config files to S3
@param [Time] time the time of the sync point to archive to
# File lib/config_file_collection.rb, line 30 def archive(time) failValidation if time.nil? or not time.is_a?(Time) bucket = AWS::S3.new(:access_key_id=>$AWS_ID, :secret_access_key=>$AWS_SECRET).buckets[$SYNC_BUCKET] print "Uploading configuration synchronization data...\t\t" @files.each do |file| config = ConfigFile.new(file) subdomain = File.basename(File.dirname(file)) object = "#{time.to_i}/configs/#{subdomain}/config.ini" #data = Zlib::Deflate.deflate(config.scrub) bucket.objects[object].write(config.scrub) end puts "Done." end