Module: StateMate::Adapters::NVRAM
Constant Summary
API_METHOD_NAMES, DEFAULT_KEY_SEP
Class Method Summary
collapse
get, included, register
Class Method Details
.read(key, options = {}) ⇒ Object
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
# File 'lib/state_mate/adapters/nvram.rb', line 12
def self.read key, options = {}
result = Cmds "nvram %{key}", key: key
if result.error?
if result.err.start_with? "nvram: Error getting variable"
return nil
end
result.assert
end
if m = /^#{ key }\t(.*)\n$/.match(result.out)
m[1]
else
raise binding.erb <<-BLOCK
can't parse output for key <%= key.inspect %>:
cmd: <%= result.cmd %>
output: <%= result.out.inspect %>
BLOCK
end
end
|
.write(key, value, options = {}) ⇒ Object
35
36
37
38
39
40
41
|
# File 'lib/state_mate/adapters/nvram.rb', line 35
def self.write key, value, options = {}
unless value.is_a? String
raise "value must be a String, not #{ value.inspect }"
end
Cmds! "sudo nvram #{ key }='#{ value }'"
end
|