Class: ReleaseCeremony::TransactionalWriter

Inherits:
Object
  • Object
show all
Defined in:
lib/release_ceremony/transactional_writer.rb

Overview

Replaces a set of files atomically: every replacement and a backup of every original are staged as sibling temporary files first, so a failure while installing can restore the originals.

Defined Under Namespace

Classes: Artifact

Instance Method Summary collapse

Constructor Details

#initialize(renamer: File.method(:rename)) ⇒ TransactionalWriter

Returns a new instance of TransactionalWriter.



13
14
15
# File 'lib/release_ceremony/transactional_writer.rb', line 13

def initialize(renamer: File.method(:rename))
  @renamer = renamer
end

Instance Method Details

#write(changes) ⇒ Object



17
18
19
20
21
22
23
# File 'lib/release_ceremony/transactional_writer.rb', line 17

def write(changes)
  artifacts = stage_changes(changes)
  install(artifacts)
  true
ensure
  cleanup(artifacts || [])
end