Class: Tumugi::AtomicFile
- Inherits:
-
Object
- Object
- Tumugi::AtomicFile
- Extended by:
- Forwardable
- Defined in:
- lib/tumugi/atomic_file.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
- #close ⇒ Object
-
#initialize(path) ⇒ AtomicFile
constructor
A new instance of AtomicFile.
- #move_to_final_destination(temp_file) ⇒ Object
- #open(&block) ⇒ Object
Constructor Details
#initialize(path) ⇒ AtomicFile
Returns a new instance of AtomicFile.
12 13 14 |
# File 'lib/tumugi/atomic_file.rb', line 12 def initialize(path) @path = path end |
Instance Attribute Details
#path ⇒ Object (readonly)
Returns the value of attribute path.
16 17 18 |
# File 'lib/tumugi/atomic_file.rb', line 16 def path @path end |
Instance Method Details
#close ⇒ Object
31 32 33 34 35 36 37 |
# File 'lib/tumugi/atomic_file.rb', line 31 def close if @temp_file move_to_final_destination(@temp_file) @temp_file.close @temp_file = nil end end |
#move_to_final_destination(temp_file) ⇒ Object
39 40 41 |
# File 'lib/tumugi/atomic_file.rb', line 39 def move_to_final_destination(temp_file) raise NotImplementedError, "You must implement #{self.class}##{__method__}" end |
#open(&block) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/tumugi/atomic_file.rb', line 18 def open(&block) if block_given? Tempfile.open(basename) do |fp| @temp_file = fp block.call(self) close end else @temp_file = Tempfile.open(basename) end self end |