Sha256: 9252a35c83cb5d8d010c9b5a81fa5aebb813026764489e0c702e82cf77f5dc7a

Contents?: true

Size: 843 Bytes

Versions: 9

Compression:

Stored size: 843 Bytes

Contents

require 'cmds'
require 'nrser'

require 'state_mate'

using NRSER

module StateMate::Adapters::NVRAM
  include StateMate::Adapters
  register 'nvram'
  
  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

  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
end # NVRAM

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
state_mate-0.1.4 lib/state_mate/adapters/nvram.rb
state_mate-0.1.3 lib/state_mate/adapters/nvram.rb
state_mate-0.1.2 lib/state_mate/adapters/nvram.rb
state_mate-0.1.1 lib/state_mate/adapters/nvram.rb
state_mate-0.1.0 lib/state_mate/adapters/nvram.rb
state_mate-0.0.9 lib/state_mate/adapters/nvram.rb
state_mate-0.0.8 lib/state_mate/adapters/nvram.rb
state_mate-0.0.7 lib/state_mate/adapters/nvram.rb
state_mate-0.0.6 lib/state_mate/adapters/nvram.rb