Class: RubyIndexer::Entry
- Inherits:
-
Object
- Object
- RubyIndexer::Entry
- Defined in:
- lib/ruby_indexer/lib/ruby_indexer/entry.rb
Direct Known Subclasses
ClassVariable, Constant, ConstantAlias, GlobalVariable, InstanceVariable, Member, MethodAlias, Namespace, UnresolvedConstantAlias, UnresolvedMethodAlias
Defined Under Namespace
Classes: Accessor, BlockParameter, Class, ClassVariable, Constant, ConstantAlias, ForwardingParameter, GlobalVariable, Include, InstanceVariable, KeywordParameter, KeywordRestParameter, Member, Method, MethodAlias, Module, ModuleOperation, Namespace, OptionalKeywordParameter, OptionalParameter, Parameter, Prepend, RequiredParameter, RestParameter, Signature, SingletonClass, UnresolvedConstantAlias, UnresolvedMethodAlias
Instance Attribute Summary collapse
-
#location ⇒ Object
(also: #name_location)
readonly
: RubyIndexer::Location.
-
#name ⇒ Object
readonly
: String.
-
#uri ⇒ Object
readonly
: URI::Generic.
-
#visibility ⇒ Object
: Symbol.
Instance Method Summary collapse
-
#comments ⇒ Object
: -> String.
-
#file_name ⇒ Object
: -> String.
-
#file_path ⇒ Object
: -> String?.
-
#initialize(name, uri, location, comments) ⇒ Entry
constructor
: (String name, URI::Generic uri, Location location, String? comments) -> void.
-
#private? ⇒ Boolean
: -> bool.
-
#protected? ⇒ Boolean
: -> bool.
-
#public? ⇒ Boolean
: -> bool.
Constructor Details
#initialize(name, uri, location, comments) ⇒ Entry
: (String name, URI::Generic uri, Location location, String? comments) -> void
21 22 23 24 25 26 27 |
# File 'lib/ruby_indexer/lib/ruby_indexer/entry.rb', line 21 def initialize(name, uri, location, comments) @name = name @uri = uri @comments = comments @visibility = :public #: Symbol @location = location end |
Instance Attribute Details
#location ⇒ Object (readonly) Also known as: name_location
: RubyIndexer::Location
13 14 15 |
# File 'lib/ruby_indexer/lib/ruby_indexer/entry.rb', line 13 def location @location end |
#name ⇒ Object (readonly)
: String
7 8 9 |
# File 'lib/ruby_indexer/lib/ruby_indexer/entry.rb', line 7 def name @name end |
#uri ⇒ Object (readonly)
: URI::Generic
10 11 12 |
# File 'lib/ruby_indexer/lib/ruby_indexer/entry.rb', line 10 def uri @uri end |
#visibility ⇒ Object
: Symbol
18 19 20 |
# File 'lib/ruby_indexer/lib/ruby_indexer/entry.rb', line 18 def visibility @visibility end |
Instance Method Details
#comments ⇒ Object
: -> String
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/ruby_indexer/lib/ruby_indexer/entry.rb', line 61 def comments @comments ||= begin # Parse only the comments based on the file path, which is much faster than parsing the entire file path = file_path parsed_comments = path ? Prism.parse_file_comments(path) : [] # Group comments based on whether they belong to a single block of comments grouped = parsed_comments.slice_when do |left, right| left.location.start_line + 1 != right.location.start_line end # Find the group that is either immediately or two lines above the current entry correct_group = grouped.find do |group| comment_end_line = group.last.location.start_line (comment_end_line..comment_end_line + 1).cover?(@location.start_line - 1) end # If we found something, we join the comments together. Otherwise, the entry has no documentation and we don't # want to accidentally re-parse it, so we set it to an empty string. If an entry is updated, the entire entry # object is dropped, so this will not prevent updates if correct_group correct_group.filter_map do |comment| content = comment.slice.chomp if content.valid_encoding? content.delete_prefix!("#") content.delete_prefix!(" ") content end end.join("\n") else "" end rescue Errno::ENOENT # If the file was deleted, but the entry hasn't been removed yet (could happen due to concurrency), then we do # not want to fail. Just set the comments to an empty string "" end end |
#file_name ⇒ Object
: -> String
45 46 47 48 49 50 51 52 53 |
# File 'lib/ruby_indexer/lib/ruby_indexer/entry.rb', line 45 def file_name if @uri.scheme == "untitled" @uri.opaque #: as !nil else File.basename( file_path, #: as !nil ) end end |
#file_path ⇒ Object
: -> String?
56 57 58 |
# File 'lib/ruby_indexer/lib/ruby_indexer/entry.rb', line 56 def file_path @uri.full_path end |
#private? ⇒ Boolean
: -> bool
40 41 42 |
# File 'lib/ruby_indexer/lib/ruby_indexer/entry.rb', line 40 def private? @visibility == :private end |
#protected? ⇒ Boolean
: -> bool
35 36 37 |
# File 'lib/ruby_indexer/lib/ruby_indexer/entry.rb', line 35 def protected? @visibility == :protected end |
#public? ⇒ Boolean
: -> bool
30 31 32 |
# File 'lib/ruby_indexer/lib/ruby_indexer/entry.rb', line 30 def public? @visibility == :public end |