Sha256: 56d1d4379bd852121f80c78c796004e59043083d2d205d909a51108ca37c66dc

Contents?: true

Size: 913 Bytes

Versions: 3

Compression:

Stored size: 913 Bytes

Contents

# frozen_string_literal: true
module Steam
  # Represents a Sentry file on disk
  #
  # @todo this will overwrite any existing file, namespace
  #   to username?
  class SentryFile
    # Writes the digest to the sentry file
    #
    # @example Write the SentryFile
    #   file = SentryFile.new
    #   file.write('sha1digest')
    #
    # @param digest [String]
    def write(digest)
      File.open(path, 'wb') do |file|
        file.write(digest)
      end
    end

    # Read the digest from the sentry file. Returns
    # nil if the Sentry file does not exist.
    #
    # @example Read the SentryFile
    #   file = SentryFile.new
    #   file.read # => 'somedigest'
    #
    # @return [String,nil]
    def read
      return nil unless File.exist?(path)

      File.open(path, 'rb', &:read)
    end

    private

    # @api private
    def path
      File.expand_path('~/.steam-sentry')
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
steamrb-0.1.2 lib/steam/sentry_file.rb
steamrb-0.1.1 lib/steam/sentry_file.rb
steamrb-0.1.0 lib/steam/sentry_file.rb