Class: Klenod::Build::ResolveError
- Defined in:
- lib/klenod/build/errors.rb
Constant Summary collapse
- REASONS =
[:incorrect_case, :not_found].freeze
Instance Attribute Summary collapse
-
#dependency ⇒ Object
readonly
Returns the value of attribute dependency.
-
#importer_id ⇒ Object
readonly
Returns the value of attribute importer_id.
-
#reason ⇒ Object
readonly
Returns the value of attribute reason.
-
#requested_specifier ⇒ Object
readonly
Returns the value of attribute requested_specifier.
-
#suggestions ⇒ Object
readonly
Returns the value of attribute suggestions.
-
#unresolved_path ⇒ Object
readonly
Returns the value of attribute unresolved_path.
Instance Method Summary collapse
- #imported_by ⇒ Object
-
#initialize(message = nil, unresolved_path: nil, dependency: nil, importer_id: nil, reason: nil, requested_specifier: nil, suggestions: []) ⇒ ResolveError
constructor
A new instance of ResolveError.
- #resolution_failure? ⇒ Boolean
- #source_location ⇒ Object
- #title ⇒ Object
- #with_path_prefix(prefix) ⇒ Object
- #with_resolution_context(dependency:, importer_id:) ⇒ Object
Constructor Details
#initialize(message = nil, unresolved_path: nil, dependency: nil, importer_id: nil, reason: nil, requested_specifier: nil, suggestions: []) ⇒ ResolveError
Returns a new instance of ResolveError.
14 15 16 17 18 19 20 21 22 23 |
# File 'lib/klenod/build/errors.rb', line 14 def initialize( = nil, unresolved_path: nil, dependency: nil, importer_id: nil, reason: nil, requested_specifier: nil, suggestions: []) @unresolved_path = unresolved_path @dependency = dependency @importer_id = importer_id @reason = reason @requested_specifier = requested_specifier @suggestions = suggestions.freeze super( || ) end |
Instance Attribute Details
#dependency ⇒ Object (readonly)
Returns the value of attribute dependency.
12 13 14 |
# File 'lib/klenod/build/errors.rb', line 12 def dependency @dependency end |
#importer_id ⇒ Object (readonly)
Returns the value of attribute importer_id.
12 13 14 |
# File 'lib/klenod/build/errors.rb', line 12 def importer_id @importer_id end |
#reason ⇒ Object (readonly)
Returns the value of attribute reason.
12 13 14 |
# File 'lib/klenod/build/errors.rb', line 12 def reason @reason end |
#requested_specifier ⇒ Object (readonly)
Returns the value of attribute requested_specifier.
12 13 14 |
# File 'lib/klenod/build/errors.rb', line 12 def requested_specifier @requested_specifier end |
#suggestions ⇒ Object (readonly)
Returns the value of attribute suggestions.
12 13 14 |
# File 'lib/klenod/build/errors.rb', line 12 def suggestions @suggestions end |
#unresolved_path ⇒ Object (readonly)
Returns the value of attribute unresolved_path.
12 13 14 |
# File 'lib/klenod/build/errors.rb', line 12 def unresolved_path @unresolved_path end |
Instance Method Details
#imported_by ⇒ Object
41 42 43 44 45 46 47 |
# File 'lib/klenod/build/errors.rb', line 41 def imported_by if source_location&.line "#{display_importer(source_location.path)}:#{source_location.line}" else display_importer(dependency&.importer_id || importer_id) end end |
#resolution_failure? ⇒ Boolean
25 26 27 |
# File 'lib/klenod/build/errors.rb', line 25 def resolution_failure? REASONS.include?(reason) && requested_specifier end |
#source_location ⇒ Object
37 38 39 |
# File 'lib/klenod/build/errors.rb', line 37 def source_location dependency&.loc end |
#title ⇒ Object
29 30 31 32 33 34 35 |
# File 'lib/klenod/build/errors.rb', line 29 def title case reason when :incorrect_case then "Incorrect import path casing" when :not_found then "Module not found" else self.class.name end end |
#with_path_prefix(prefix) ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/klenod/build/errors.rb', line 73 def with_path_prefix(prefix) return self unless resolution_failure? self.class.new( nil, unresolved_path: unresolved_path, dependency: dependency, importer_id: importer_id, reason: reason, requested_specifier: prefixed_path(prefix, requested_specifier), suggestions: suggestions.map { prefixed_path(prefix, it) } ) end |
#with_resolution_context(dependency:, importer_id:) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/klenod/build/errors.rb', line 49 def with_resolution_context(dependency:, importer_id:) unless resolution_failure? return self if self.dependency return self.class.new( (dependency, importer_id), unresolved_path: unresolved_path, dependency: dependency, importer_id: importer_id ) end replacements = suggestions.map { replacement_specifier(it, dependency) } self.class.new( nil, unresolved_path: unresolved_path, dependency: dependency, importer_id: importer_id, reason: reason, requested_specifier: dependency.specifier.to_s, suggestions: replacements ) end |