Sha256: 78f4b82d24bd3b0ba04b3b50741fd5bb8c222ca3cc734be618980f2722040fec

Contents?: true

Size: 1.06 KB

Versions: 1

Compression:

Stored size: 1.06 KB

Contents

#!ruby

require_relative "../invfs"

module InVFS
  class UnionFS
    attr_reader :dirs

    def initialize(*dirs)
      @dirs = dirs
    end

    def file?(lib)
      dirs.each do |dir|
        path = File.join(dir, lib)
        return true if File.file?(path)
      end

      false
    end

    def size(lib)
      dirs.each do |dir|
        path = File.join(dir, lib)
        return File.size(path) if File.file?(path)
      end

      raise Errno::ENOENT, lib
    end

    def read(lib)
      dirs.each do |dir|
        path = File.join(dir, lib)
        return File.binread(path) if File.file?(path)
      end

      raise Errno::ENOENT, lib
    end

    def to_path
      %(#<#{self.class} #{dirs.map { |d| "<#{d}>" }.join(", ")}>)
    end

    def to_s
      to_path
    end

    def inspect
      to_s
    end

    def pretty_print(q)
      q.group(2, "#<#{self.class}", ">") do
        dirs.each_with_index do |d, i|
          q.text "," if i > 0
          q.breakable " "
          d.pretty_print q
        end
      end
    end
  end

  MultipleDirectory = UnionFS
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
invfs-0.3.1 lib/invfs/unionfs.rb