Sha256: bfad63bc71be813c48e6a2ab30b2146e823769b853509c43107e3b2e6816ef98

Contents?: true

Size: 1.12 KB

Versions: 28

Compression:

Stored size: 1.12 KB

Contents

module DeepTest
  module Distributed
    class FilenameResolver
      def initialize(base_path)
        @base_path = base_path
      end

      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

      def cache_resolution(original_filename, resolved_filename)
        @cached_replaced_path = original_filename.sub(
           resolved_filename.sub(@base_path, ""), ""
        )
      end

      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
    end
  end
end

Version data entries

28 entries across 28 versions & 5 rubygems

Version Path
jason-o-matic-deep_test-1.2.2.1 lib/deep_test/distributed/filename_resolver.rb
jason-o-matic-deep_test-1.2.2.10 lib/deep_test/distributed/filename_resolver.rb
jason-o-matic-deep_test-1.2.2.11 lib/deep_test/distributed/filename_resolver.rb
jason-o-matic-deep_test-1.2.2.12 lib/deep_test/distributed/filename_resolver.rb
jason-o-matic-deep_test-1.2.2.13 lib/deep_test/distributed/filename_resolver.rb
jason-o-matic-deep_test-1.2.2.14 lib/deep_test/distributed/filename_resolver.rb
jason-o-matic-deep_test-1.2.2.2 lib/deep_test/distributed/filename_resolver.rb
jason-o-matic-deep_test-1.2.2.3 lib/deep_test/distributed/filename_resolver.rb
jason-o-matic-deep_test-1.2.2.4 lib/deep_test/distributed/filename_resolver.rb
jason-o-matic-deep_test-1.2.2.5 lib/deep_test/distributed/filename_resolver.rb
jason-o-matic-deep_test-1.2.2.6 lib/deep_test/distributed/filename_resolver.rb
jason-o-matic-deep_test-1.2.2.7 lib/deep_test/distributed/filename_resolver.rb
jason-o-matic-deep_test-1.2.2.8 lib/deep_test/distributed/filename_resolver.rb
jason-o-matic-deep_test-1.2.2.9 lib/deep_test/distributed/filename_resolver.rb
jperkins-deep_test-1.2.2 lib/deep_test/distributed/filename_resolver.rb
deep_test_pre-2.0 lib/deep_test/distributed/filename_resolver.rb
jason-o-matic-deep_test-1.2.2.15 lib/deep_test/distributed/filename_resolver.rb
jstorimer-deep-test-2.0.0 lib/deep_test/distributed/filename_resolver.rb
jstorimer-deep-test-1.4.0 lib/deep_test/distributed/filename_resolver.rb
jstorimer-deep-test-1.3.0 lib/deep_test/distributed/filename_resolver.rb