Class: RBS::Repository::GemRBS

Inherits:
Object
  • Object
show all
Defined in:
lib/rbs/repository.rb,
sig/repository.rbs

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name:) ⇒ GemRBS

Returns a new instance of GemRBS.

Parameters:

  • name: (String)


11
12
13
14
15
# File 'lib/rbs/repository.rb', line 11

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

Instance Attribute Details

#nameString (readonly)

Returns the value of attribute name.

Returns:

  • (String)


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

def name
  @name
end

#pathsArray[Pathname] (readonly)

Array of gem dirs. Gem dir contains directories for each version.

Returns:

  • (Array[Pathname])


23
24
25
# File 'sig/repository.rbs', line 23

def paths
  @paths
end

Instance Method Details

#empty?Boolean

Returns true if versions is empty.

Returns:

  • (Boolean)


43
44
45
# File 'sig/repository.rbs', line 43

def empty?
  versions.empty?
end

#find_best_version(version) ⇒ VersionPath

Parameters:

  • (Gem::Version, nil)

Returns:



59
60
61
62
# File 'lib/rbs/repository.rb', line 59

def find_best_version(version)
  best_version = Repository.find_best_version(version, version_names)
  versions[best_version]
end

#latest_versionVersionPath

Returns:



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

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

#load!void

This method returns an undefined value.



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/rbs/repository.rb', line 22

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_versionVersionPath

Returns:



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

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

#version_namesArray[Gem::Version]

Returns:

  • (Array[Gem::Version])


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

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

#versionsObject



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

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