Class: Sheepsafe::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/sheepsafe/config.rb

Constant Summary collapse

FILE =
File.expand_path('~/.sheepsafe.yml')
DEFAULT_CONFIG =
{"untrusted_location" => "Untrusted", "socks_port" => "9999", "trust_encrypted?" => "false"}
ATTRS =
%w(trusted_location untrusted_location last_network ssh_host ssh_port socks_port trust_encrypted?)
ARRAY_ATTRS =
%w(trusted_names untrusted_names)

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hash = nil) ⇒ Config

Returns a new instance of Config.



18
19
20
# File 'lib/sheepsafe/config.rb', line 18

def initialize(hash = nil)
  @config = DEFAULT_CONFIG.merge(hash || self.class.load_config)
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



16
17
18
# File 'lib/sheepsafe/config.rb', line 16

def config
  @config
end

Class Method Details

.load_configObject



10
11
12
13
14
# File 'lib/sheepsafe/config.rb', line 10

def self.load_config
  YAML.load_file(FILE)
rescue Errno::ENOENT
  raise "Unable to read ~/.sheepsafe.yml; please run sheepsafe-install"
end

Instance Method Details

#ssh_argsObject



36
37
38
39
40
41
# File 'lib/sheepsafe/config.rb', line 36

def ssh_args
  args = ""
  args << "-p #{ssh_port} " if ssh_port
  args << "-ND #{socks_port} #{ssh_host}"
  args
end

#writeObject



32
33
34
# File 'lib/sheepsafe/config.rb', line 32

def write
  File.open(FILE, "w") {|f| f << YAML.dump(config) }
end