123456789_123456789_123456789_123456789_123456789_

Class: RBS::Annotate::RDocSource

Relationships & Source Files
Inherits: Object
Defined in: lib/rbs/annotate/rdoc_source.rb

Class Method Summary

Instance Attribute Summary

Instance Method Summary

Constructor Details

.newRDocSource

[ GitHub ]

  
# File 'lib/rbs/annotate/rdoc_source.rb', line 12

def initialize
  self.with_system_dir = true
  self.with_gems_dir = false
  self.with_site_dir = false
  self.with_home_dir = false

  @extra_dirs = []
  @stores = []
end

Instance Attribute Details

#extra_dirs (readonly)

[ GitHub ]

  
# File 'lib/rbs/annotate/rdoc_source.rb', line 8

attr_reader :extra_dirs

#stores (readonly)

[ GitHub ]

  
# File 'lib/rbs/annotate/rdoc_source.rb', line 10

attr_reader :stores

#with_gems_dir (rw)

[ GitHub ]

  
# File 'lib/rbs/annotate/rdoc_source.rb', line 6

attr_accessor :with_system_dir, :with_gems_dir, :with_site_dir, :with_home_dir

#with_home_dir (rw)

[ GitHub ]

  
# File 'lib/rbs/annotate/rdoc_source.rb', line 6

attr_accessor :with_system_dir, :with_gems_dir, :with_site_dir, :with_home_dir

#with_site_dir (rw)

[ GitHub ]

  
# File 'lib/rbs/annotate/rdoc_source.rb', line 6

attr_accessor :with_system_dir, :with_gems_dir, :with_site_dir, :with_home_dir

#with_system_dir (rw)

[ GitHub ]

  
# File 'lib/rbs/annotate/rdoc_source.rb', line 6

attr_accessor :with_system_dir, :with_gems_dir, :with_site_dir, :with_home_dir

Instance Method Details

#class_docs(typename)

[ GitHub ]

  
# File 'lib/rbs/annotate/rdoc_source.rb', line 55

def class_docs(typename)
  if classes = find_class(typename)
    classes.map {|klass| klass.comment }
  end
end

#docs

[ GitHub ]

  
# File 'lib/rbs/annotate/rdoc_source.rb', line 47

def docs
  if ds = yield
    unless ds.empty?
      ds.map(&:comment)
    end
  end
end

#find_attribute(typename, name, singleton:)

[ GitHub ]

  
# File 'lib/rbs/annotate/rdoc_source.rb', line 108

def find_attribute(typename, name, singleton:)
  if klasss = find_class(typename)
    # @type var attrs: Array[RDoc::Attr]
    attrs = []

    klasss.each do |kls|
      attrs.concat(kls.attributes.select {|attr| attr.singleton == singleton && attr.name == name.to_s })
    end

    attrs unless attrs.empty?
  end
end

#find_class(typename)

[ GitHub ]

  
# File 'lib/rbs/annotate/rdoc_source.rb', line 33

def find_class(typename)
  classes = []

  @stores.each do |store|
    if klass = store.find_class_or_module(typename.relative!.to_s)
      classes << klass
    end
  end

  unless classes.empty?
    classes
  end
end

#find_const(const_name)

[ GitHub ]

  
# File 'lib/rbs/annotate/rdoc_source.rb', line 61

def find_const(const_name)
  namespace =
    if const_name.namespace.empty?
      TypeName("::Object")
    else
      const_name.namespace.to_type_name
    end

  if classes = find_class(namespace)
    # @type var consts: Array[RDoc::Constant]
    consts = []

    classes.each do |klass|
      if const = klass.constants.find {|c| c.name == const_name.name.to_s }
        consts << const
      end
    end

    unless consts.empty?
      consts
    end
  end
end

#find_method(typename, instance_method: nil, singleton_method: nil)

[ GitHub ]

  
# File 'lib/rbs/annotate/rdoc_source.rb', line 85

def find_method(typename, instance_method: nil, singleton_method: nil)
  if classes = find_class(typename)
    # @type var methods: Array[RDoc::AnyMethod]
    methods = []

    classes.each do |klass|
      klass.method_list.each do |method|
        if instance_method && !method.singleton && method.name == instance_method.to_s
          methods << method
        end

        if singleton_method && method.singleton && method.name == singleton_method.to_s
          methods << method
        end
      end
    end

    unless methods.empty?
      methods
    end
  end
end

#load

[ GitHub ]

  
# File 'lib/rbs/annotate/rdoc_source.rb', line 22

def load
  @stores.clear()

  RDoc::RI::Paths.each(with_system_dir, with_site_dir, with_home_dir, with_gems_dir ? :latest : false, *extra_dirs.map(&:to_s)) do |path, type|
    store = RDoc::Store.new(path, type)
    store.load_all

    @stores << store
  end
end