Module: StateMate::Adapters::NVRAM

Includes:
StateMate::Adapters
Defined in:
lib/state_mate/adapters/nvram.rb

Constant Summary

Constants included from StateMate::Adapters

API_METHOD_NAMES

Class Method Summary collapse

Methods included from StateMate::Adapters

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 "      can't parse output for key <%= key.inspect %>:\n\n        cmd: <%= result.cmd %>\n\n        output: <%= result.out.inspect %>\n    BLOCK\n  end\nend\n"

.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