Sha256: d80e88063d34974210cd8fcde740cd7d1dc7f49f341799f6aa8015cd96a9ca1c

Contents?: true

Size: 641 Bytes

Versions: 2

Compression:

Stored size: 641 Bytes

Contents

# frozen_string_literal: true

require "stashify"

module Stashify
  class File
    attr_reader :name, :path, :contents

    def initialize(name: nil, path: nil, contents: "")
      raise StandardError, "name or path must be defined" unless name || path
      raise Stashify::InvalidFile, "Name '#{name}' contains a /" if name && name =~ %r{/}

      @path = path
      @name = name || ::File.basename(path)
      @contents = contents
    end

    def write(contents)
      @contents = contents
    end

    def delete
      @contents = nil
    end

    def ==(other)
      name == other.name && contents == other.contents
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
stashify-3.1.0 lib/stashify/file.rb
stashify-3.0.0 lib/stashify/file.rb