Class: Whisper::AuthorTracker
- Inherits:
-
Object
- Object
- Whisper::AuthorTracker
- Includes:
- Loggy
- Defined in:
- lib/whisper/author_tracker.rb
Instance Method Summary collapse
- #[](name) ⇒ Object
- #[]=(name, info) ⇒ Object
-
#initialize(dir) ⇒ AuthorTracker
constructor
A new instance of AuthorTracker.
Constructor Details
#initialize(dir) ⇒ AuthorTracker
Returns a new instance of AuthorTracker.
8 9 10 11 |
# File 'lib/whisper/author_tracker.rb', line 8 def initialize dir @dir = dir @mutex = Mutex.new end |
Instance Method Details
#[](name) ⇒ Object
13 14 15 16 17 18 19 20 21 22 |
# File 'lib/whisper/author_tracker.rb', line 13 def [] name @mutex.synchronize do fn = fn_for name begin YAML.load_file fn rescue SystemCallError => e {} end end end |
#[]=(name, info) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/whisper/author_tracker.rb', line 24 def []= name, info unless info.empty? @mutex.synchronize do fn = fn_for name old_info = YAML.load_file(fn) rescue {} info = old_info.merge info debug "writing #{info.inspect} to #{fn}..." begin File.open(fn, "w") { |f| f.print info.to_yaml } rescue SystemCallError => e warn "can't write #{fn}: #{e.}" end end end info end |