123456789_123456789_123456789_123456789_123456789_

Class: RBS::Repository

Relationships & Source Files
Namespace Children
Classes:
Inherits: Object
Defined in: lib/rbs/repository.rb

Constant Summary

Class Method Summary

Instance Attribute Summary

Instance Method Summary

Constructor Details

.new(no_stdlib: false) ⇒ Repository

[ GitHub ]

  
# File 'lib/rbs/repository.rb', line 77

def initialize(no_stdlib: false)
  @dirs = []
  @gems = {}

  unless no_stdlib
    add(DEFAULT_STDLIB_ROOT)
  end
end

Class Method Details

.default

[ GitHub ]

  
# File 'lib/rbs/repository.rb', line 86

def self.default
  new().tap do |repo|
    repo.add(DEFAULT_STDLIB_ROOT)
  end
end

Instance Attribute Details

#dirs (readonly)

[ GitHub ]

  
# File 'lib/rbs/repository.rb', line 74

attr_reader :dirs

#gems (readonly)

[ GitHub ]

  
# File 'lib/rbs/repository.rb', line 75

attr_reader :gems

Instance Method Details

#add(dir)

[ GitHub ]

  
# File 'lib/rbs/repository.rb', line 92

def add(dir)
  dirs << dir

  dir.each_child(false) do |child|
    gem_name = child.to_s
    gem_rbs = (gems[gem_name] ||= GemRBS.new(name: gem_name))
    gem_rbs.paths << dir + child
  end
end

#lookup(gem, version)

[ GitHub ]

  
# File 'lib/rbs/repository.rb', line 102

def lookup(gem, version)
  _, set = lookup_path(gem, version)
  set&.path
end

#lookup_path(gem, version)

[ GitHub ]

  
# File 'lib/rbs/repository.rb', line 107

def lookup_path(gem, version)
  if gem_rbs = gems[gem]
    unless gem_rbs.empty?
      set = if v = Gem::Version.create(version)&.release
        gem_rbs.find_best_version(v)
      else
        gem_rbs.latest_version
      end

      [gem_rbs, set]
    end
  end
end