Module: Yatte::Recovery
- Defined in:
- lib/yatte/recovery.rb
Constant Summary collapse
- EDIT_THRESHOLD =
100- TIME_THRESHOLD =
30
Class Method Summary collapse
- .exists?(filepath) ⇒ Boolean
- .load(filepath) ⇒ Object
- .remove(filepath) ⇒ Object
- .save(filepath, buffer_text) ⇒ Object
- .swap_path(filepath) ⇒ Object
Class Method Details
.exists?(filepath) ⇒ Boolean
31 32 33 34 |
# File 'lib/yatte/recovery.rb', line 31 def self.exists?(filepath) swp = swap_path(filepath) swp && File.exist?(swp) end |
.load(filepath) ⇒ Object
36 37 38 39 40 |
# File 'lib/yatte/recovery.rb', line 36 def self.load(filepath) swp = swap_path(filepath) return nil unless swp && File.exist?(swp) File.read(swp) end |
.remove(filepath) ⇒ Object
42 43 44 45 46 47 48 |
# File 'lib/yatte/recovery.rb', line 42 def self.remove(filepath) swp = swap_path(filepath) return unless swp && File.exist?(swp) File.delete(swp) rescue nil end |
.save(filepath, buffer_text) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/yatte/recovery.rb', line 17 def self.save(filepath, buffer_text) swp = swap_path(filepath) return unless swp dir = File.dirname(swp) tmp = Tempfile.new(".yatte_swap", dir) tmp.write(buffer_text) tmp.close File.rename(tmp.path, swp) rescue => e tmp&.close! Yatte.logger&.error("Swap save failed: #{e.}") end |
.swap_path(filepath) ⇒ Object
10 11 12 13 14 15 |
# File 'lib/yatte/recovery.rb', line 10 def self.swap_path(filepath) return nil unless filepath dir = File.dirname(filepath) name = File.basename(filepath) File.join(dir, ".#{name}.swp") end |