Class: WindowsEnv

Inherits:
Object show all
Defined in:
lib/pik/windows_env.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key, subkey) ⇒ WindowsEnv

Returns a new instance of WindowsEnv.



19
20
21
22
23
# File 'lib/pik/windows_env.rb', line 19

def initialize(key, subkey)
  @key    = key
  @subkey = subkey
  @reg    = Reg.new
end

Class Method Details

.systemObject



7
8
9
10
11
# File 'lib/pik/windows_env.rb', line 7

def self.system
  key    = :HKEY_LOCAL_MACHINE
  subkey = 'SYSTEM\CurrentControlSet\Control\Session Manager\Environment'
  new(key, subkey)
end

.userObject



13
14
15
16
17
# File 'lib/pik/windows_env.rb', line 13

def self.user
  key    = :HKEY_CURRENT_USER
  subkey = 'Environment'
  new(key, subkey)
end

Instance Method Details

#[](name) ⇒ Object



29
30
31
# File 'lib/pik/windows_env.rb', line 29

def [](name)
  @reg.open(@key, @subkey, name)
end

#[]=(name, other) ⇒ Object



33
34
35
36
37
38
39
# File 'lib/pik/windows_env.rb', line 33

def []=(name, other)
  if other == nil
    @env.remove(name)
  else
    @env.setproperty('item', name, other)
  end
end

#has_key?(key) ⇒ Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/pik/windows_env.rb', line 41

def has_key?(key)
  !!self[key]
end

#set(items) ⇒ Object



25
26
27
# File 'lib/pik/windows_env.rb', line 25

def set(items)
  items.each{|k,v| self[k] = v }
end