Module: Skytap::SkytapRC

Extended by:
SkytapRC
Included in:
SkytapRC
Defined in:
lib/skytap/skytaprc.rb

Constant Summary collapse

RC_FILE =
File.expand_path(File.join(ENV['HOME'], '.skytaprc'))
RECOGNIZED_OPTIONS =
[:'verify-certs', :'base-url', :'api-token', :'http-format', :ask, :'log-level', :username, :colorize]

Instance Method Summary collapse

Instance Method Details

#exists?Boolean

Returns:

  • (Boolean)


8
9
10
# File 'lib/skytap/skytaprc.rb', line 8

def exists?
  File.exist?(RC_FILE)
end

#loadObject



12
13
14
15
16
17
18
# File 'lib/skytap/skytaprc.rb', line 12

def load
  @rc_contents ||= (if File.exist?(RC_FILE)
                     YAML.load_file(RC_FILE).symbolize_keys
                   else
                     {}
                   end).subset(RECOGNIZED_OPTIONS)
end

#write(hash) ⇒ Object



20
21
22
23
24
25
26
# File 'lib/skytap/skytaprc.rb', line 20

def write(hash)
  @rc_contents = nil
  hash = (hash || {}).subset(RECOGNIZED_OPTIONS)
  File.open(RC_FILE, 'w') do |f|
    f << YAML.dump(hash)
  end
end