class Pennyworth::HostConfig
Attributes
config_file[R]
lock_server_address[R]
Public Class Methods
for_directory(config_dir)
click to toggle source
# File lib/pennyworth/host_config.rb, line 22 def self.for_directory(config_dir) HostConfig.new(File.join(config_dir, "hosts.yaml")) end
new(config_file)
click to toggle source
# File lib/pennyworth/host_config.rb, line 26 def initialize(config_file) @config_file = File.expand_path(config_file) end
Public Instance Methods
host(host_name)
click to toggle source
# File lib/pennyworth/host_config.rb, line 69 def host(host_name) @hosts[host_name] end
hosts()
click to toggle source
# File lib/pennyworth/host_config.rb, line 65 def hosts @hosts.keys end
parse(yaml_string)
click to toggle source
# File lib/pennyworth/host_config.rb, line 30 def parse(yaml_string) yaml = YAML.load(yaml_string) if !yaml raise HostFileError.new("Could not parse YAML in file '#{config_file}'") end if yaml["include"] begin open(yaml["include"], "rb") do |u| parse(u.read) end rescue OpenURI::HTTPError, Errno::ENOENT raise HostFileError.new("Unable to include '#{yaml["include"]}'") end end if yaml["hosts"] if !@hosts @hosts = yaml["hosts"] else yaml["hosts"].each do |key, value| @hosts[key] = value end end end if yaml["lock_server_address"] @lock_server_address = yaml["lock_server_address"] end end
read()
click to toggle source
# File lib/pennyworth/host_config.rb, line 61 def read parse(File.read(config_file)) end
setup(url)
click to toggle source
# File lib/pennyworth/host_config.rb, line 73 def setup(url) if File.exist?(config_file) raise HostFileError.new("Config file '#{config_file}' already exists." + " Canceling setup.") end FileUtils.mkdir_p(File.dirname(config_file)) File.open(config_file, "w") do |f| f.puts("---") f.puts("include: #{url}") end end