Sha256: 8b38795d0d13da7260bf86abb56af038f27193b0585703e0c552e82614683425

Contents?: true

Size: 788 Bytes

Versions: 2

Compression:

Stored size: 788 Bytes

Contents

# p __FILE__


module GlobalHelpers

  def check_disallowed(name)
    raise DisallowedName(name) if disallowed?(name)
  end

  def check_file_exists(file)
    raise FileNotFound(file) unless File.exist?(file)
  end

  def grab_file(fname)
    File.read(fname)
  end

  def search_upward(file)
    value = nil
    return file if File.exist?(file)

    count = 1
    loop do
      front = "../" * count
      count += 1
      here = Pathname.new(front).expand_path.dirname.to_s
      break if here == "/"
      path = front + file
      value = path if File.exist?(path)
      break if value
    end
    ::STDERR.puts "Cannot find #{file.inspect} from #{Dir.pwd}" unless value
	  return value
  rescue
    ::STDERR.puts "Can't find #{file.inspect} from #{Dir.pwd}"
	  return nil
  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
livetext-0.9.24 lib/global_helpers.rb
livetext-0.9.23 lib/global_helpers.rb