Class: HmxClient::Command::Base
- Inherits:
-
Object
- Object
- HmxClient::Command::Base
show all
- Includes:
- CLIColorize, Helpers
- Defined in:
- lib/hmx/command/base.rb
Direct Known Subclasses
Bootstrap, Check, Clone, Config, Dump, Fn, Fountain, Get, GetContent, Help, Partition, Query, Session, Task, Type, User, View
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
#args ⇒ Object
Returns the value of attribute args.
14
15
16
|
# File 'lib/hmx/command/base.rb', line 14
def args
@args
end
|
#options ⇒ Object
Returns the value of attribute options.
15
16
17
|
# File 'lib/hmx/command/base.rb', line 15
def options
@options
end
|
Class Method Details
.namespace ⇒ Object
10
11
12
|
# File 'lib/hmx/command/base.rb', line 10
def self.namespace
self.to_s.split("::").last.downcase
end
|
Instance Method Details
#hmx ⇒ Object
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.login(@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!
@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)
if (keyName == :password)
keyValue = Digest::MD5.hexdigest(keyValue)
end
@config[keyName] = keyValue
removeConfig("context".to_sym); end
|
#writeConfig ⇒ Object
47
48
49
|
# File 'lib/hmx/command/base.rb', line 47
def writeConfig
File.open(FILE, 'w+') { |f| Marshal.dump(@config, f) }
end
|