Sha256: b195b47ef4cbdc5381031b6be79758420e76d2f9d82e274899554438f1825703

Contents?: true

Size: 687 Bytes

Versions: 1

Compression:

Stored size: 687 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 exists?
      !contents.nil?
    end

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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
stashify-3.2.0 lib/stashify/file.rb