FileWriteAction

InfoGenerateCreated ByPackages

This code defines a module called `Sublayer` with a nested module `Actions`. Inside `Actions`, there's a class `WriteFileAction` which inherits from a base class (`Base`). The purpose of this class is to write contents to a file at a specified path. When an object of `WriteFileAction` is initialized, it takes two arguments: `file_contents` (the data to be written to the file) and `file_path` (the location where the file will be created or overwritten). The `call` method within this class handles the actual writing process, opening the file in binary write mode (`'wb'`) and writing the provided contents to it.

module Sublayer
  module Actions
    class WriteFileAction < Base
      def initialize(file_contents:, file_path:)
        @file_contents = file_contents
        @file_path = file_path
      end

      def call
        File.open(@file_path, 'wb') do |file|
          file.write(@file_contents)
        end
      end
    end
  end
end