Module: KeyStore
- Defined in:
- lib/key_store.rb,
lib/key_store/key.rb,
lib/key_store/version.rb
Defined Under Namespace
Classes: Key
Constant Summary collapse
- VERSION =
"0.0.4"
Class Attribute Summary collapse
-
.file_path ⇒ Object
readonly
Returns the value of attribute file_path.
Class Method Summary collapse
- .delete!(name) ⇒ Object
- .exists?(name) ⇒ Boolean
- .file ⇒ Object
- .find(name) ⇒ Object
- .set_file_path(value) ⇒ Object
Class Attribute Details
.file_path ⇒ Object (readonly)
Returns the value of attribute file_path.
11 12 13 |
# File 'lib/key_store.rb', line 11 def file_path @file_path end |
Class Method Details
.delete!(name) ⇒ Object
39 40 41 |
# File 'lib/key_store.rb', line 39 def delete!(name) file.transaction { |f| f.delete(name.to_s) } end |
.exists?(name) ⇒ Boolean
31 32 33 |
# File 'lib/key_store.rb', line 31 def exists?(name) !!(file.transaction { |f| f[name.to_s] }) end |
.file ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/key_store.rb', line 17 def file if @file.nil? || modified? Mutex.new.synchronize do @file = begin raise "file_path not set" if file_path.nil? FileUtils.touch(file_path) unless File.exists?(file_path) self.mtime = File.mtime(file_path) YAML::Store.new(file_path, true) end end end @file end |
.find(name) ⇒ Object
35 36 37 |
# File 'lib/key_store.rb', line 35 def find(name) exists?(name) ? KeyStore::Key.new(name) : nil end |
.set_file_path(value) ⇒ Object
13 14 15 |
# File 'lib/key_store.rb', line 13 def set_file_path(value) @file_path = value end |