Class: RubyJard::Decorators::PathDecorator
- Inherits:
-
Object
- Object
- RubyJard::Decorators::PathDecorator
- Defined in:
- lib/ruby_jard/decorators/path_decorator.rb
Overview
Simplify and generate labels to indicate the location of a path. The return value is an array of two elements. The first one is overview, the second is detailed path location.
Instance Method Summary collapse
- #decorate(path, lineno = nil) ⇒ Object
-
#initialize(path_classifier: nil) ⇒ PathDecorator
constructor
A new instance of PathDecorator.
Constructor Details
#initialize(path_classifier: nil) ⇒ PathDecorator
Returns a new instance of PathDecorator.
13 14 15 |
# File 'lib/ruby_jard/decorators/path_decorator.rb', line 13 def initialize(path_classifier: nil) @path_classifier = path_classifier || RubyJard::PathClassifier.new end |
Instance Method Details
#decorate(path, lineno = nil) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/ruby_jard/decorators/path_decorator.rb', line 17 def decorate(path, lineno = nil) return ['at ???', 'at ???'] if path.nil? type, *info = @path_classifier.classify(path) lineno = ":#{lineno}" unless lineno.nil? case type when RubyJard::PathClassifier::TYPE_SOURCE_TREE path = File.(path) decorate_source_tree(path, lineno) when RubyJard::PathClassifier::TYPE_GEM decorate_gem(path, lineno, info) when RubyJard::PathClassifier::TYPE_STDLIB decorate_stdlib(path, lineno, info) when RubyJard::PathClassifier::TYPE_INTERNAL ["in #{path}", path] when RubyJard::PathClassifier::TYPE_EVALUATION ["at #{path}#{lineno}", "#{path}#{lineno}"] when RubyJard::PathClassifier::TYPE_RUBY_SCRIPT ["at (-e ruby script)#{lineno}", "(-e ruby script)#{lineno}"] else path = compact_with_relative_path(path) ["at #{path}#{lineno}", "#{path}#{lineno}"] end end |