Sha256: 97d6ae723577d0467480b2bc6604759d302fbe47a73cd4cf84c87476bef20078

Contents?: true

Size: 751 Bytes

Versions: 4

Compression:

Stored size: 751 Bytes

Contents

# frozen_string_literal: true

module DevSuite
  module Utils
    module FileWriter
      module Writer
        class Text < Base
          def write(path, content, backup: false)
            create_backup(path) if backup

            AtomicWriter.new(path, content).write
          end

          # Updates a key-like pattern in a plain text file (find and replace)
          def update_key(path, key, value, backup: false)
            content = load_file_content(path)

            # Simple pattern matching and replacement (e.g., `key: value`)
            updated_content = content.gsub(/^#{Regexp.escape(key)}:.*/, "#{key}: #{value}")

            write(path, updated_content, backup: backup)
          end
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
dev_suite-0.2.11 lib/dev_suite/utils/file_writer/writer/text.rb
dev_suite-0.2.10 lib/dev_suite/utils/file_writer/writer/text.rb
dev_suite-0.2.9 lib/dev_suite/utils/file_writer/writer/text.rb
dev_suite-0.2.8 lib/dev_suite/utils/file_writer/writer/text.rb