Class: Ace::Demo::Molecules::TapeWriter
- Inherits:
-
Object
- Object
- Ace::Demo::Molecules::TapeWriter
- Defined in:
- lib/ace/demo/molecules/tape_writer.rb
Instance Method Summary collapse
-
#initialize(cwd: Dir.pwd) ⇒ TapeWriter
constructor
A new instance of TapeWriter.
- #write(name:, content:, force: false, extension: ".tape") ⇒ Object
Constructor Details
#initialize(cwd: Dir.pwd) ⇒ TapeWriter
Returns a new instance of TapeWriter.
9 10 11 |
# File 'lib/ace/demo/molecules/tape_writer.rb', line 9 def initialize(cwd: Dir.pwd) @cwd = cwd end |
Instance Method Details
#write(name:, content:, force: false, extension: ".tape") ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/ace/demo/molecules/tape_writer.rb', line 13 def write(name:, content:, force: false, extension: ".tape") path = tape_path(name, extension: extension) if File.exist?(path) && !force raise TapeAlreadyExistsError, "Tape already exists: #{path}\nUse --force to overwrite." end FileUtils.mkdir_p(File.dirname(path)) File.write(path, content) path end |