Module: Vigilem::Evdev::KeyMapCache

Extended by:
KeyMapCache
Included in:
KeyMapCache
Defined in:
lib/vigilem/evdev/key_map_cache.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#default_filenameString

Returns:

  • (String)


17
18
19
# File 'lib/vigilem/evdev/key_map_cache.rb', line 17

def default_filename
  @default_filename ||= 'key_map_cache'
end

#default_pathString

Returns:

  • (String)


23
24
25
26
27
28
29
# File 'lib/vigilem/evdev/key_map_cache.rb', line 23

def default_path
  @default_path ||= begin
    path = Vigilem::Evdev.data_dir
    Dir.mkdir(path) unless test ?d, path
    File.join(path, default_filename)
  end
end

#key_mapObject

Returns the value of attribute key_map.



11
12
13
# File 'lib/vigilem/evdev/key_map_cache.rb', line 11

def key_map
  @key_map
end

Instance Method Details

#dump(key_map, path = default_path) ⇒ Object Also known as: cache

Parameters:

  • path (String) (defaults to: default_path)

Returns:



40
41
42
# File 'lib/vigilem/evdev/key_map_cache.rb', line 40

def dump(key_map, path=default_path)
  File.open(path, 'w') {|f| f.write(Marshal.dump(key_map)) }
end

#exists?TrueClass || FalseClass

Returns:

  • (TrueClass || FalseClass)


33
34
35
# File 'lib/vigilem/evdev/key_map_cache.rb', line 33

def exists?
  File.exists? default_path
end

#restore(path = default_path) ⇒ KeyMap || nil

Parameters:

  • path (String) (defaults to: default_path)

Returns:

  • (KeyMap || nil)


47
48
49
# File 'lib/vigilem/evdev/key_map_cache.rb', line 47

def restore(path=default_path)
  key_map = Marshal.restore(File.binread(path))
end