Class: HmxClient::Command::Base

Inherits:
Object
  • Object
show all
Includes:
CLIColorize, Helpers
Defined in:
lib/hmx/command/base.rb

Constant Summary collapse

FILE =
File.expand_path("~/.hmxConfig")

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Helpers

#display, #display_row, #display_tab, #display_table, #error, #getFromUser, #longest

Constructor Details

#initialize(args = [], options = {}) ⇒ Base

Returns a new instance of Base.



19
20
21
22
23
# File 'lib/hmx/command/base.rb', line 19

def initialize(args=[], options={})
  @args = args
  @options = options
  loadConfig!
end

Instance Attribute Details

#argsObject (readonly)

Returns the value of attribute args.



14
15
16
# File 'lib/hmx/command/base.rb', line 14

def args
  @args
end

#optionsObject (readonly)

Returns the value of attribute options.



15
16
17
# File 'lib/hmx/command/base.rb', line 15

def options
  @options
end

Class Method Details

.namespaceObject



10
11
12
# File 'lib/hmx/command/base.rb', line 10

def self.namespace
  self.to_s.split("::").last.downcase
end

Instance Method Details

#hmxObject



50
51
52
53
54
55
56
57
# File 'lib/hmx/command/base.rb', line 50

def hmx
  if @hmx.nil?
  	@hmx = Hmx.new    
  	@hmx.(@config)
      writeConfig
  end
  @hmx
end

#loadConfig!Object



25
26
27
28
29
30
31
32
33
# File 'lib/hmx/command/base.rb', line 25

def loadConfig!
	# Load the config from the save file
      @config = if File.exist?(FILE)
           File.open(FILE) { |file| Marshal.load(file) }
  else
     {}
  end
     RestClient.proxy = @config[:proxy] if @config.has_key?(:proxy)
end

#removeConfig(keyName) ⇒ Object



43
44
45
46
# File 'lib/hmx/command/base.rb', line 43

def removeConfig(keyName)
    @config.delete keyName
    writeConfig
end

#storeConfig(keyName, keyValue) ⇒ Object



34
35
36
37
38
39
40
41
42
# File 'lib/hmx/command/base.rb', line 34

def storeConfig(keyName, keyValue)
     # Update the config hashMap and persist it
     if (keyName == :password) 
         keyValue = Digest::MD5.hexdigest(keyValue)
     end
     @config[keyName] = keyValue
     # Remove any saved session config
     removeConfig("context".to_sym); # Also saves config
end

#writeConfigObject



47
48
49
# File 'lib/hmx/command/base.rb', line 47

def writeConfig
     File.open(FILE, 'w+') { |f| Marshal.dump(@config, f) }
end