class DRbQS::ProcessList::ListDirectory

Public Class Methods

new(dir) click to toggle source
# File lib/drbqs/config/process_list.rb, line 10
def initialize(dir)
  @directory = dir
  FileUtils.mkdir_p(@directory) unless File.exist?(@directory)
end

Public Instance Methods

server_of_key_exist?(uri, key) click to toggle source
# File lib/drbqs/config/process_list.rb, line 61
def server_of_key_exist?(uri, key)
  if data = get(uri)
    return data[:key] == key
  end
  false
end

Private Instance Methods

delete_file(file) click to toggle source
# File lib/drbqs/config/process_list.rb, line 48
def delete_file(file)
  path = path_under_directory(file)
  FileUtils.remove(path) if File.exist?(path)
end
entries() click to toggle source
# File lib/drbqs/config/process_list.rb, line 54
def entries
  Dir.entries(@directory).delete_if do |dir|
    /^\.+$/ =~ dir
  end
end
load_file(file) click to toggle source

If file does not exist then this method returns nil.

# File lib/drbqs/config/process_list.rb, line 38
def load_file(file)
  path = path_under_directory(file)
  if File.exist?(path)
    YAML.load_file(path)
  else
    nil
  end
end
path_under_directory(file) click to toggle source
# File lib/drbqs/config/process_list.rb, line 15
def path_under_directory(file)
  File.join(@directory, file)
end
save_file(file, data) click to toggle source

If file exists then this method returns false. Otherwise, return true. @param [String] file Set path under the data directory. @param [Object] data Set the save data that is converted to YAML.

# File lib/drbqs/config/process_list.rb, line 24
def save_file(file, data)
  path = path_under_directory(file)
  if File.exist?(path)
    false
  else
    open(path, 'w') do |f|
      f.print data.to_yaml
    end
    true
  end
end