Sha256: 84a86b757d19e38652d0acfea538b0efd474e51b914e2ced45fbf941af23141f

Contents?: true

Size: 867 Bytes

Versions: 7

Compression:

Stored size: 867 Bytes

Contents

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

7 entries across 7 versions & 1 rubygems

Version Path
gemirro-1.2.0 lib/gemirro/mirror_file.rb
gemirro-1.1.1 lib/gemirro/mirror_file.rb
gemirro-1.1.0 lib/gemirro/mirror_file.rb
gemirro-1.0.0 lib/gemirro/mirror_file.rb
gemirro-0.16.0 lib/gemirro/mirror_file.rb
gemirro-0.15.0 lib/gemirro/mirror_file.rb
gemirro-0.14.0 lib/gemirro/mirror_file.rb