Class: Smartdc::CliConfigure
- Inherits:
-
Object
- Object
- Smartdc::CliConfigure
- Defined in:
- lib/smartdc/cli_configure.rb
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
- #init ⇒ Object
-
#initialize(path = nil) ⇒ CliConfigure
constructor
A new instance of CliConfigure.
- #read ⇒ Object
- #write(options) ⇒ Object
Constructor Details
#initialize(path = nil) ⇒ CliConfigure
Returns a new instance of CliConfigure.
5 6 7 8 9 10 11 12 13 14 |
# File 'lib/smartdc/cli_configure.rb', line 5 def initialize(path=nil) if path @path =path else [Smartdc.root, ENV['HOME']].each do |path| @path = File.join(path, '.sdccfg') break if File.exist?(@path) end end end |
Instance Attribute Details
#path ⇒ Object (readonly)
Returns the value of attribute path.
3 4 5 |
# File 'lib/smartdc/cli_configure.rb', line 3 def path @path end |
Instance Method Details
#init ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/smartdc/cli_configure.rb', line 41 def init output = <<__EOS__ . | .-. .--. .-.| .-. : + : `--.( | ( `-' `--' `-'`- `-' Smart Data Center Command Line Interface https://apidocs.joyent.com/sdcapidoc/cloudapi/ __EOS__ puts output puts = self.read = option(, :Hostname, :hostname, 'api.example.com') = option(, :Version, :version, '~7.0') = option(, :Username, :username, ENV['USER']) = option(, :Fingerprint, :use_key, 'none') = option(, :SSLVerify, :ssl_verify, true) puts puts "New settings!" puts "Hostname: #{[:hostname]}" puts "Version: #{[:version]}" puts "Username: #{[:username]}" puts "Fingerprint: #{[:use_key]}" puts "SSLVerify: #{[:ssl_verify]}" puts self.write end |
#read ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/smartdc/cli_configure.rb', line 16 def read begin = {} File.open(path, 'r') do |file| file.each do |row| row.chomp! cols = row.split(/\s+=\s+/) [cols[0].to_sym] = cols[1] end end rescue {} end end |
#write(options) ⇒ Object
32 33 34 35 36 37 38 39 |
# File 'lib/smartdc/cli_configure.rb', line 32 def write() File.open(path, 'w') do |file| .each do |key, value| file.puts "#{key} = #{value}" end end end |