Module: Vigilem::Evdev::KeyMapCache
Instance Attribute Summary collapse
- #default_filename ⇒ String
- #default_path ⇒ String
-
#key_map ⇒ Object
Returns the value of attribute key_map.
Instance Method Summary collapse
- #dump(key_map, path = default_path) ⇒ Object (also: #cache)
- #exists? ⇒ TrueClass || FalseClass
- #restore(path = default_path) ⇒ KeyMap || nil
Instance Attribute Details
#default_filename ⇒ String
17 18 19 |
# File 'lib/vigilem/evdev/key_map_cache.rb', line 17 def default_filename @default_filename ||= 'key_map_cache' end |
#default_path ⇒ 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_map ⇒ Object
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
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
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
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 |