class DeepTest::Distributed::FilenameResolver

Public Class Methods

new(base_path) click to toggle source
# File lib/deep_test/distributed/filename_resolver.rb, line 4
def initialize(base_path)
  @base_path = base_path
end

Public Instance Methods

cache_resolution(original_filename, resolved_filename) click to toggle source
# File lib/deep_test/distributed/filename_resolver.rb, line 23
def cache_resolution(original_filename, resolved_filename)
  @cached_replaced_path = original_filename.sub(
     resolved_filename.sub(@base_path, ""), ""
  )
end
each_potential_filename(filename) { |[base_path, dirs, basename].join('/')| ... } click to toggle source
# File lib/deep_test/distributed/filename_resolver.rb, line 29
def each_potential_filename(filename)
  basename = File.basename(filename)
  dirs = File.dirname(filename).split('/')

  begin
    dirs.shift
    yield [@base_path, dirs, basename].flatten.join('/')
  end until dirs.empty?
end
resolve(filename) click to toggle source
# File lib/deep_test/distributed/filename_resolver.rb, line 8
def resolve(filename)
  return resolve("/" + filename) unless filename[0] == ?/

  return filename.sub(@cached_replaced_path, @base_path) if @cached_replaced_path

  each_potential_filename(filename) do |potential_filename|
    if File.exist?(potential_filename)
      cache_resolution(filename, potential_filename)
      return potential_filename 
    end
  end

  raise "Filename resolution failed.  Cannot resolve #{filename} within #{@base_path}"
end