123456789_123456789_123456789_123456789_123456789_

Class: RBS::Repository::GemRBS

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

Class Method Summary

Instance Attribute Summary

Instance Method Summary

Constructor Details

.new(name:) ⇒ GemRBS

[ GitHub ]

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

def initialize(name:)
  @name = name
  @paths = []
  @versions = nil
end

Instance Attribute Details

#empty?Boolean (readonly)

[ GitHub ]

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

def empty?
  versions.empty?
end

#name (readonly)

[ GitHub ]

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

attr_reader :name

#paths (readonly)

[ GitHub ]

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

attr_reader :paths

Instance Method Details

#find_best_version(version)

[ GitHub ]

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

def find_best_version(version)
  return latest_version unless version

  if v = version_names.reverse.bsearch {|v| v <= version ? true : false }
    versions[v]
  else
    oldest_version
  end
end

#latest_version

[ GitHub ]

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

def latest_version
  latest = version_names.last or raise
  versions[latest] or raise
end

#load!

[ GitHub ]

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

def load!
  @versions = {}
  versions = @versions or raise

  paths.each do |gem_path|
    gem_path.each_child(false) do |child|
      next unless Gem::Version.correct?(child.to_s)

      if version = Gem::Version.create(child.to_s)
        unless version.prerelease?
          path = gem_path + child

          if prev = versions[version]
            RBS.logger.info { "Overwriting gem RBS in repository: gem=#{name}, prev_path=#{prev.path}, new_path=#{path}" }
          end

          versions[version] = VersionPath.new(gem: self, version: version, path: path)
        end
      end
    end
  end
end

#oldest_version

[ GitHub ]

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

def oldest_version
  oldest = version_names.first or raise
  versions[oldest] or raise
end

#version_names

[ GitHub ]

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

def version_names
  versions.keys.sort_by(&:version)
end

#versions

[ GitHub ]

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

def versions
  load! unless @versions
  @versions or raise
end