class RBS::Annotate::Annotations

Attributes

items[R]

Public Class Methods

new(items) click to toggle source
# File rbs-2.7.0/lib/rbs/annotate/annotations.rb, line 148
def initialize(items)
  @items = items
end
parse(annotation) click to toggle source
# File rbs-2.7.0/lib/rbs/annotate/annotations.rb, line 119
def self.parse(annotation)
  string = annotation.string

  case
  when match = string.match(/\Aannotate:rdoc:skip(:all)?\Z/)
    Skip.new(
      annotation: annotation,
      skip_children: string.end_with?(":all")
    )
  when match = string.match(/\Aannotate:rdoc:source:from=(?<path>.+)\Z/)
    Source.new(
      annotation: annotation,
      include: (match[:path] or raise).strip
    )
  when match = string.match(/\Aannotate:rdoc:source:skip=(?<path>.+)\Z/)
    Source.new(
      annotation: annotation,
      skip: (match[:path] or raise).strip
    )
  when match = string.match(/\Aannotate:rdoc:copy:(?<name>.+)\Z/)
    Copy.new(
      annotation: annotation,
      source: (match[:name] or raise).strip
    )
  end
end

Public Instance Methods

copy_annotation() click to toggle source
# File rbs-2.7.0/lib/rbs/annotate/annotations.rb, line 160
def copy_annotation
  _ = items.find {|a| a.is_a?(Copy) }
end
skip?() click to toggle source
# File rbs-2.7.0/lib/rbs/annotate/annotations.rb, line 152
def skip?
  items.any? {|a| a.is_a?(Skip) }
end
skip_all?() click to toggle source
# File rbs-2.7.0/lib/rbs/annotate/annotations.rb, line 156
def skip_all?
  items.any? {|a| a.is_a?(Skip) && a.skip_children }
end
test_path(path) click to toggle source
# File rbs-2.7.0/lib/rbs/annotate/annotations.rb, line 164
def test_path(path)
  # @type var source_items: Array[Source]
  source_items = _ = items.select {|item| item.is_a?(Source) }

  return true if source_items.empty?

  result = source_items[0].include_source == nil

  items.each do |a|
    if a.is_a?(Source)
      if pat = a.include_source
        if test_path_string(pat, path)
          result = true
        end
      end

      if pat = a.skip_source
        if test_path_string(pat, path)
          result = false
        end
      end
    end
  end

  result
end
test_path_string(pattern, string) click to toggle source
# File rbs-2.7.0/lib/rbs/annotate/annotations.rb, line 191
def test_path_string(pattern, string)
  return true if pattern == string
  return true if string.start_with?(pattern + File::SEPARATOR)

  false
end