Class: Sheepsafe::Config
- Inherits:
-
Object
- Object
- Sheepsafe::Config
- Defined in:
- lib/sheepsafe/config.rb
Constant Summary collapse
- FILE =
File.('~/.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
-
#config ⇒ Object
readonly
Returns the value of attribute config.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(hash = nil) ⇒ Config
constructor
A new instance of Config.
- #ssh_args ⇒ Object
- #write ⇒ Object
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
#config ⇒ Object (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_config ⇒ Object
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_args ⇒ Object
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 |
#write ⇒ Object
32 33 34 |
# File 'lib/sheepsafe/config.rb', line 32 def write File.open(FILE, "w") {|f| f << YAML.dump(config) } end |