Sha256: fa3e8ef044249c7f2e62d6a796e3ebdde3d70c5a3d585e6ca33a803d3214ccbc

Contents?: true

Size: 898 Bytes

Versions: 3

Compression:

Stored size: 898 Bytes

Contents

# frozen_string_literal: true

module Gemirro
  ##
  # Similar to {Gemirro::MirrorDirectory} the MirrorFile class is used to
  # make it easier to read and write data in a directory that mirrors data from
  # an external source.
  #
  # @!attribute [r] path
  #  @return [String]
  #
  class MirrorFile
    attr_reader :path

    ##
    # @param [String] path
    #
    def initialize(path)
      @path = path
    end

    ##
    # Writes the specified content to the current file. Existing files are
    # overwritten.
    #
    # @param [String] content
    #
    def write(content)
      handle = File.open(@path, 'w')

      handle.write(content)
      handle.close
    end

    ##
    # Reads the content of the current file.
    #
    # @return [String]
    #
    def read
      handle  = File.open(@path, 'r')
      content = handle.read

      handle.close

      content
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
gemirro-1.5.0 lib/gemirro/mirror_file.rb
gemirro-1.4.0 lib/gemirro/mirror_file.rb
gemirro-1.3.0 lib/gemirro/mirror_file.rb