Class: Klenod::Build::FilesystemResolver
- Inherits:
-
Object
- Object
- Klenod::Build::FilesystemResolver
- Defined in:
- lib/klenod/build/filesystem_resolver.rb
Defined Under Namespace
Classes: PathMatch
Constant Summary collapse
- MAX_CORRECTIONS =
3
Instance Method Summary collapse
-
#initialize(root:, extensions: [], path_prefix: nil) ⇒ FilesystemResolver
constructor
A new instance of FilesystemResolver.
- #resolve(relative_path) ⇒ Object
Constructor Details
#initialize(root:, extensions: [], path_prefix: nil) ⇒ FilesystemResolver
Returns a new instance of FilesystemResolver.
14 15 16 17 18 |
# File 'lib/klenod/build/filesystem_resolver.rb', line 14 def initialize(root:, extensions: [], path_prefix: nil) @root = Pathname.new(root). @extensions = extensions.freeze @path_prefix = path_prefix.to_s end |
Instance Method Details
#resolve(relative_path) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/klenod/build/filesystem_resolver.rb', line 20 def resolve(relative_path) relative_path = normalize_relative_path(relative_path) case_corrections = [] candidate_paths(relative_path).each do |candidate_path| path_matches(candidate_path).each do |match| return match.path unless match.case_mismatch case_corrections << relative_path_for(match.path) end end unless case_corrections.empty? raise ResolveError.new( nil, unresolved_path: display_path(relative_path), reason: :incorrect_case, requested_specifier: display_path(relative_path), suggestions: case_corrections.uniq.map { display_path(it) }.first(MAX_CORRECTIONS) ) end corrections = spelling_corrections(relative_path) raise ResolveError.new( nil, unresolved_path: display_path(relative_path), reason: :not_found, requested_specifier: display_path(relative_path), suggestions: corrections.map { display_path(it) } ) end |