Class: RBI::NodeWithComments
- Extended by:
- T::Helpers, T::Sig
- Defined in:
- lib/rbi/model.rb,
lib/rbi/rewriters/merge_trees.rb,
lib/rbi/rewriters/filter_versions.rb
Direct Known Subclasses
Attr, Const, Helper, Method, Mixin, Param, RequiresAncestor, Send, Sig, SigParam, TStructField, Tree, TypeMember, Visibility
Instance Attribute Summary collapse
-
#comments ⇒ Object
Returns the value of attribute comments.
Attributes inherited from Node
Instance Method Summary collapse
- #annotations ⇒ Object
-
#initialize(loc: nil, comments: []) ⇒ NodeWithComments
constructor
A new instance of NodeWithComments.
- #merge_with(other) ⇒ Object
- #version_requirements ⇒ Object
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
Returns a new instance of NodeWithComments.
95 96 97 98 |
# File 'lib/rbi/model.rb', line 95 def initialize(loc: nil, comments: []) super(loc: loc) @comments = comments end |
Instance Attribute Details
#comments ⇒ Object
Returns the value of attribute comments.
92 93 94 |
# File 'lib/rbi/model.rb', line 92 def comments @comments end |
Instance Method Details
#annotations ⇒ Object
101 102 103 104 105 |
# File 'lib/rbi/model.rb', line 101 def annotations comments .select { |comment| comment.text.start_with?("@") } .map { |comment| T.must(comment.text[1..]) } end |
#merge_with(other) ⇒ Object
311 312 313 314 315 316 317 |
# File 'lib/rbi/rewriters/merge_trees.rb', line 311 def merge_with(other) return unless other.is_a?(NodeWithComments) other.comments.each do |comment| comments << comment unless comments.include?(comment) end end |
#version_requirements ⇒ Object
104 105 106 107 108 109 110 111 |
# File 'lib/rbi/rewriters/filter_versions.rb', line 104 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 |