Class: RBI::NodeWithComments Abstract

Inherits:
Node
  • Object
show all
Defined in:
lib/rbi/model.rb,
lib/rbi/rewriters/merge_trees.rb,
lib/rbi/rewriters/filter_versions.rb

Overview

This class is abstract.

Instance Attribute Summary collapse

Attributes inherited from Node

#loc, #parent_tree

Instance Method Summary collapse

Methods inherited from Node

#compatible_with?, #detach, #parent_conflict_tree, #parent_scope, #print, #rbs_print, #rbs_string, #replace, #satisfies_version?, #string

Constructor Details

#initialize(loc: nil, comments: []) ⇒ NodeWithComments

: (?loc: Loc?, ?comments: Array) -> void



93
94
95
96
# File 'lib/rbi/model.rb', line 93

def initialize(loc: nil, comments: [])
  super(loc: loc)
  @comments = comments
end

Instance Attribute Details

#commentsObject

: Array



90
91
92
# File 'lib/rbi/model.rb', line 90

def comments
  @comments
end

Instance Method Details

#annotationsObject

: -> Array



99
100
101
102
103
104
105
# File 'lib/rbi/model.rb', line 99

def annotations
  comments
    .select { |comment| comment.text.start_with?("@") }
    .map do |comment|
      comment.text[1..] #: as !nil
    end
end

#merge_with(other) ⇒ Object

: (Node other) -> void



312
313
314
315
316
317
318
# File 'lib/rbi/rewriters/merge_trees.rb', line 312

def merge_with(other)
  return unless other.is_a?(NodeWithComments)

  other.comments.each do |comment|
    comments << comment unless comments.include?(comment)
  end
end

#version_requirementsObject

: -> Array



101
102
103
104
105
106
107
108
# File 'lib/rbi/rewriters/filter_versions.rb', line 101

def version_requirements
  annotations.select do |annotation|
    annotation.start_with?(Rewriters::FilterVersions::VERSION_PREFIX)
  end.map do |annotation|
    versions = annotation.delete_prefix(Rewriters::FilterVersions::VERSION_PREFIX).split(/, */)
    Gem::Requirement.new(versions)
  end
end