Module: Vcli

Defined in:
lib/vcli/cli/show.rb,
lib/vcli.rb,
lib/vcli/cli.rb,
lib/vcli/version.rb,
lib/vcli/cli/create.rb,
lib/vcli/cli/delete.rb,
lib/vcli/cli/modify.rb,
lib/vcli/cli/resource.rb

Overview

VCLI::CLI::Delete

Jay Fearn

Initial Delete

DATE   # Ver # Description

28072015 # 0.1 # Initial Creation

Defined Under Namespace

Modules: CLI Classes: Cli

Constant Summary collapse

CONFIG_DIR =

Set Config directory and file

"#{ENV['HOME']}/.vcli/"
CONFIG_FILE =
CONFIG_DIR + "vcli.yml"
VERSION =
"0.2.10"

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#passwordObject (readonly)

Returns the value of attribute password.



13
14
15
# File 'lib/vcli.rb', line 13

def password
  @password
end

#targetObject (readonly)

Returns the value of attribute target.



11
12
13
# File 'lib/vcli.rb', line 11

def target
  @target
end

#userObject (readonly)

Returns the value of attribute user.



12
13
14
# File 'lib/vcli.rb', line 12

def user
  @user
end

Class Method Details

.create_dirObject



43
44
45
46
# File 'lib/vcli.rb', line 43

def self.create_dir
  # create directory
  Dir::mkdir CONFIG_DIR
end

.create_fileObject



33
34
35
36
37
38
39
40
41
# File 'lib/vcli.rb', line 33

def self.create_file
  # create file
  f = File.open(CONFIG_FILE, 'w')
  f.write("")
  # set some default null values
  set_config("target","")
  set_config("user","")
  set_config("password","")
end

.readconfigObject



26
27
28
29
30
31
# File 'lib/vcli.rb', line 26

def self.readconfig
  # read in yaml file and store as instance variables
  config = YAML.load_file(CONFIG_FILE)
  config.each { |key, value|
    instance_variable_set("@#{key}", value) }
end

.set_config(key, value) ⇒ Object



15
16
17
18
19
20
21
22
23
24
# File 'lib/vcli.rb', line 15

def self.set_config(key, value)
  # Read in YAML file
  config = YAML::load(File.read(CONFIG_FILE)) || {}
  # change to new value
  config[key.to_sym] = value
  # Write it back out to the YAML file
  open(CONFIG_FILE, 'w') { |f| YAML::dump(config, f) }
  # ReRead the configuration file
  readconfig
end