class VMLib::File

This is the file class for handling VMLib version files

Constants

FILE_NAME

Default file name of 'Version'

Public Class Methods

new(filename = nil) click to toggle source

Create a new file object with the specified filename. If the filename is not specified, it reverts to the default

# File lib/vmlib/file.rb, line 20
def initialize(filename = nil)
  @filename ||= FILE_NAME
  @dir = nil
end

Public Instance Methods

find_file(dir = nil) click to toggle source

Search the current and all parent folders for a version file Raises an error if it cannot find any up to the root.

# File lib/vmlib/file.rb, line 27
def find_file(dir = nil)
  dir ||= ::Dir.pwd
  raise Errors::PathError unless ::File.directory?(dir)
  path = ::File.join(dir, @filename)

  ::Dir.chdir(dir) do
    while !::File.exists?(path) do
      if (::File.dirname(path).match(/^(\w:\/|\/)$/))
        raise Errors::NoVersionError, "#{dir} is not versioned"
      end

      path = ::File.join(::File.dirname(path), '..')
      path = ::File.expand_path(path)
      #puts "vmlib: looking at path #{path}"
      path = ::File.join(path, @filename)
    end
    @dir = path
    return path
  end