Class: DeepTest::Distributed::FilenameResolver
- Inherits:
-
Object
- Object
- DeepTest::Distributed::FilenameResolver
- Defined in:
- lib/deep_test/distributed/filename_resolver.rb
Instance Method Summary collapse
- #cache_resolution(original_filename, resolved_filename) ⇒ Object
- #each_potential_filename(filename) ⇒ Object
-
#initialize(base_path) ⇒ FilenameResolver
constructor
A new instance of FilenameResolver.
- #resolve(filename) ⇒ Object
Constructor Details
#initialize(base_path) ⇒ FilenameResolver
Returns a new instance of FilenameResolver.
4 5 6 |
# File 'lib/deep_test/distributed/filename_resolver.rb', line 4 def initialize(base_path) @base_path = base_path end |
Instance Method Details
#cache_resolution(original_filename, resolved_filename) ⇒ Object
23 24 25 26 27 |
# 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) ⇒ Object
29 30 31 32 33 34 35 36 37 |
# 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) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# 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 |